Skip to content
GitHub Discord

AWS Lambda Go DynamoDB

An example on how to use a Go runtime Lambda with DynamoDB.

You configure the DynamoDB client.

src/main.go
import (
"github.com/sst/sst/v3/sdk/golang/resource"
)
func main() {
cfg, err := config.LoadDefaultConfig(context.Background())
if err != nil {
panic(err)
}
client := dynamodb.NewFromConfig(cfg)
tableName, err := resource.Get("Table", "name")
if err != nil {
panic(err)
}
}

And make a request to DynamoDB.

src/main.go
_, err = r.client.PutItem(ctx, &dynamodb.PutItemInput{
TableName: tableName.(string),
Item: item,
})
sst.config.ts
const table = new sst.aws.Dynamo("Table", {
fields: {
PK: "string",
SK: "string",
},
primaryIndex: { hashKey: "PK", rangeKey: "SK" },
});
new sst.aws.Function("GoFunction", {
url: true,
runtime: "go",
handler: "./src",
link: [table],
});

View the full example.