0
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 1 year has passed since last update.

Lambdaでgoを取り扱う

Posted at

Functionを作る

handler.go
package main

import (
	"context"
	"fmt"

	"github.com/aws/aws-lambda-go/lambda"
)

type MyEvent struct {
	Name string `json:"name"`
}

func tes(ctx context.Context, name MyEvent) (string, error) {
	return fmt.Sprintf("Hello %s!", name.Name), nil
}
func main() {
	lambda.Start(tes)
}

Zipを作る

  • LambdaでGoを扱う場合、go buildしたバイナリファイルをzipにしてLambdaFunctionへアップロードする必要がある
go mod init go-lambda
go get github.com/aws/aws-lambda-go/lambda
go mod tidy
GOOS=linux go build -o handler handler.go
zip function.zip handler 

Lambda設定

zipファイルをアップロードし、ハンドラーをhandlerにする。
Lambda設定のハンドラーはZipにした際のバイナリファイル名になるので注意
image.png

テスト

テストするといけるはず。
今回のコードではインプとされるJSONデータはなんでもよいので何も考えずにテストボタンを押せば良い
image.png

参考

0
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
0
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?