Last active
January 2, 2021 11:25
-
-
Save noid11/2be297845ec12efbe441c4c44b64afeb to your computer and use it in GitHub Desktop.
AWS SDK for Go を使って DynamoDB に PutItem するコードのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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