Coder Social home page Coder Social logo

local-lambda-and-s3's Introduction

S3+Lambda発火のサンプル

手順

# localstack起動
TMPDIR=/private$TMPDIR docker-compose up -d

# ビルド
GOOS=linux GOARCH=amd64 go build -o main main.go
zip main.zip main
rm main

# Lambda作成
aws lambda create-function \
  --endpoint-url=http://localhost:4574 \
  --function-name s3-trigger-test \
  --runtime go1.x \
  --handler main \
  --zip-file fileb://main.zip \
  --role r1

# バケット作成
aws --endpoint-url=http://localhost:4572 s3 mb s3://test-bucket

# Lambdaに権限付与
aws lambda add-permission \
  --endpoint-url=http://localhost:4574 \
  --region us-east-1 \
  --function-name s3-trigger-test \
  --statement-id s3-put-event \
  --principal s3.amazonaws.com \
  --action "lambda:InvokeFunction" \
  --source-arn arn:aws:s3:::test-bucket

# バケットのイベント通知設定
aws s3api put-bucket-notification-configuration \
  --endpoint-url=http://localhost:4572 \
  --bucket test-bucket \
  --notification-configuration file://s3test-event.json

# S3アップロード
aws s3 cp main.go s3://test-bucket \
  --endpoint-url=http://localhost:4572

ログ確認

aws logs describe-log-groups \
  --endpoint-url=http://localhost:4586 \
  --log-group-name-prefix "/aws/lambda" \
  --region us-east-1

aws logs tail --follow /aws/lambda/s3-trigger-test --endpoint-url http://localhost:4586 --region=us-east-1

バケット確認

aws s3 ls s3://test-bucket \
  --endpoint-url=http://localhost:4572

aws lambda list-functions \
  --endpoint-url=http://localhost:4574

Lambda発火

aws lambda invoke \
  --endpoint-url=http://localhost:4574 \
  --function-name s3-trigger-test \
  out --log-type Tail; rm out

参考文献

local-lambda-and-s3's People

Contributors

skanehira avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

shunte88

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.