Finally, in order to delete an item from DynamoDB, the following Lambda function should be implemented:
- Register a new handler to delete a movie. The handler will encode the payload in the request body to a Movie struct:
var movie Movieerr := json.Unmarshal([]byte(request.Body), &movie)if err != nil { return events.APIGatewayProxyResponse{ StatusCode: 400, Body: "Invalid payload", }, nil}
- Then, call the DeleteItem method with the movie ID as a parameter to remove it from the table:
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.DeleteItemRequest(&dynamodb.DeleteItemInput{ ...