- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2018-08-23T22:41:20+00:00","","")
#author("2018-08-23T23:20:40+00:00","","")
[[AWSメモ]] >
* Go言語でLambdaを書いてみる [#e980248f]
#setlinebreak(on);
https://golang.org/
AWS SDK for Go Developer Guide
https://docs.aws.amazon.com/ja_jp/sdk-for-go/v1/developer-guide/welcome.html
Getting Started with the AWS SDK for Go
https://docs.aws.amazon.com/ja_jp/sdk-for-go/v1/developer-guide/setting-up.html
AWS SDK for Go Code Examples
https://docs.aws.amazon.com/ja_jp/sdk-for-go/v1/developer-guide/common-examples.html
APIリファレンス
https://docs.aws.amazon.com/sdk-for-go/api/
Go で Lambda 関数を作成するためのプログラミングモデル
https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/go-programming-model.html
#contents
** Goのインストール [#qac8ab5e]
#html(<div style="padding-left:10px">)
https://golang.org/doc/install
#html(</div>)
** Goの動作確認 [#g11f60a4]
#html(<div style="padding-left:10px">)
src/hello/hello.go
#mycode(){{
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
}}
ビルド、実行
#mycode(){{
cd src/hello
go build && hello, world
hello, world
}}
** AWS SDK for Go のインストール [#m40eb97a]
#html(<div style="padding-left:10px">)
#myterm2(){{
go get -u github.com/aws/aws-sdk-go/...
}}
#html(</div>)
** AWS SDK for Go の動作確認 [#qc96fc4d]
#html(<div style="padding-left:10px">)
https://docs.aws.amazon.com/ja_jp/sdk-for-go/v1/developer-guide/dynamo-example-list-tables.html
#mycode2(){{
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
func main() {
// Initialize a session in us-west-2 that the SDK will use to load
// credentials from the shared credentials file ~/.aws/credentials.
sess, err := session.NewSession(&aws.Config{
Region: aws.String("ap-northeast-1")},
)
// Create DynamoDB client
svc := dynamodb.New(sess)
// Get the list of tables
result, err := svc.ListTables(&dynamodb.ListTablesInput{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Tables:")
fmt.Println("")
for _, n := range result.TableNames {
fmt.Println(*n)
}
fmt.Println("")
}
}}
#html(</div>)
https://docs.aws.amazon.com/ja_jp/sdk-for-go/v1/developer-guide/using-dynamodb-with-go-sdk.html