AWSメモ >

Go言語でAWS Lambdaを書いてみる

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

Goのインストール

https://golang.org/doc/install

Goの動作確認

src/hello/hello.go

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

ビルド、実行

cd src/hello
go build && hello, world
hello, world

AWS SDK for Go のインストール

go get -u github.com/aws/aws-sdk-go/...

AWS SDK for Go の動作確認

https://docs.aws.amazon.com/ja_jp/sdk-for-go/v1/developer-guide/dynamo-example-list-tables.html

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("")
}

https://docs.aws.amazon.com/ja_jp/sdk-for-go/v1/developer-guide/using-dynamodb-with-go-sdk.html


トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS