MCPcopy Create free account
hub / github.com/aws-samples/aws-cdk-examples / handleRequest

Function handleRequest

go/lambda-dynamodb/lambda-handler/main.go:26–53  ·  view source on GitHub ↗
(ctx context.Context, event MyEvent)

Source from the content-addressed store, hash-verified

24}
25
26func handleRequest(ctx context.Context, event MyEvent) {
27
28 cfg, err := config.LoadDefaultConfig(ctx)
29 if err != nil {
30 log.Fatalf("Got error loading config: %s", err)
31 }
32
33 svc := dynamodb.NewFromConfig(cfg)
34
35 av, err := attributevalue.MarshalMap(event)
36 if err != nil {
37 log.Fatalf("Got error marshalling new movie item: %s", err)
38 }
39
40 tableName := "MyDynamoDB"
41
42 input := &dynamodb.PutItemInput{
43 Item: av,
44 TableName: aws.String(tableName),
45 }
46
47 _, err = svc.PutItem(ctx, input)
48 if err != nil {
49 log.Fatalf("Got error calling PutItem: %s", err)
50 } else {
51 log.Println("Successfully added '" + event.Message + "' to table " + tableName)
52 }
53}
54
55func main() {
56 lambda.Start(handleRequest)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected