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:
- 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{ ...