4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Golangでlambdaローカルの動かし方(2019/04版)

Last updated at Posted at 2019-04-06

Golangでlambdaローカルを動かす際に古い記事しかなかったので、自分用のメモ

前提

  • OSは、Mac(Mojave 10.14.3)
  • Pythonをインストール済み
  • 筆者の環境は、pyenvで3.7.3をインストール済み
  • dockerをインストール済み

準備

  • aws-sam-cliをインストール
pip install aws-sam-cli
  • 初期化する
  • 下記のパスは、筆者の環境なので、便宜変えてください
cd $GOPATH/src/github.com
sam init --runtime go
  • 依存モジュールを取得
go get github.com/aws/aws-lambda-go/events
go get github.com/aws/aws-lambda-go/lambda
  • lambdaイベントの作成
cd sam-app/
# Lambdaに渡す用のイベントファイルの作成
sam local generate-event apigateway aws-proxy > event_file.json

# Lambdaの実行
sam local invoke HelloWorldFunction --event event_file.json
  • 動作実行
# APIの起動
sam local start-api

# 呼べるか確認
curl http://127.0.0.1:3000/hello

参考URL

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?