Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@kure

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

More than 1 year has passed since last update.

前提

  • 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
Help us understand the problem. What is going on with this article?
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
kure

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
1
Help us understand the problem. What is going on with this article?