1
1

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 3 years have passed since last update.

GoをAWS Lambdaで動かす一番小さいサンプルメモ

Posted at

前提

  • Go 1.x
  • ローカル環境でGoが動く
  • デプロイは lambroll
  • IAMロール作成済み
  • 手元にAWSの認証情報がある

メモ

必要なパッケージのインストール

% go get -u github.com/aws/aws-lambda-go/lambda

コードの準備
hogehoge をログ出力するだけ。引数も戻り値も考慮しない。

hello.go
package main

// 一番最小限のLambda
import (
  "fmt"
  "github.com/aws/aws-lambda-go/lambda"
)

func hello() {
	fmt.Println("hogehoge")
}

func main() {
  lambda.Start(hello)
}

ビルド

# hello バイナリが出来る
% go build -o hello

デプロイ準備

% lambroll init --function-name hello-go --region "ap-northeast-1

function.json 更新

function.json
{
  "FunctionName": "[Function Name]",
  "Handler": "hello",
  "MemorySize": [MemorySize],
  "Role": "[Role ARN]",
  "Runtime": "go1.x",
  "Timeout": [Timeout Second]
}

デプロイ

% lambroll deploy --region "ap-northeast-1"

あとはマネコン等で適当に実行

参考

AWS Lambda で Go が使えるようになったので試してみた | Developers.IO https://dev.classmethod.jp/cloud/aws/aws-lambda-supports-go/

Go の AWS Lambda 関数ハンドラー - AWS Lambda https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/go-programming-model-handler-types.html

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?