PutItem request

So far, we have learned how to list all items and return a single item from DynamoDB. The following section describes how we can implement a Lambda function to add a new item to a database:

  1. Update the insert handler to call the PutItem method to insert a new movie into the table:
func insert(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {  ...    cfg, err := external.LoadDefaultAWSConfig()  if err != nil {    return events.APIGatewayProxyResponse{      StatusCode: http.StatusInternalServerError,      Body: "Error while retrieving AWS credentials",    }, nil  }  svc := dynamodb.New(cfg)  req := svc.PutItemRequest(&dynamodb.PutItemInput{    TableName: aws.String(os.Getenv("TABLE_NAME")), Item: map[string]dynamodb.AttributeValue{ ...

Get Hands-On Serverless Applications with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.