Skip to content

Instantly share code, notes, and snippets.

@noid11
Last active January 2, 2021 11:25
Show Gist options
  • Save noid11/2be297845ec12efbe441c4c44b64afeb to your computer and use it in GitHub Desktop.
Save noid11/2be297845ec12efbe441c4c44b64afeb to your computer and use it in GitHub Desktop.
AWS SDK for Go を使って DynamoDB に PutItem するコードのサンプル
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"fmt"
)
func main() {
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
svc := dynamodb.New(sess)
tableName := "MyTable"
putItemResult, err := svc.PutItem(
&dynamodb.PutItemInput{
TableName: aws.String(tableName),
Item: map[string]*dynamodb.AttributeValue{
"id": {
S: aws.String("myID"),
},
"body": {
S: aws.String("mybody"),
},
},
},
)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(putItemResult)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment