Help us understand the problem. What is going on with this article?

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

前提

  • 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

kure
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした