- Newest
- Most votes
- Most comments
Hi - Have you checked this blog https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for-dynamodb/. It has similar use which you are trying to build.
Also this "API Gateway REST API to DynamoDB" https://serverlessland.com/patterns/apigw-dynamodb would also help a lot.
You are trying to take the DynamoDB response from a PutItem API call and return meaningful data in the API Gateway API Response. The problem is the data you want to return is not in the direct integration response from DynamoDB. This link shows the details around PutItem and the response. https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html
As explained in that document, the PutItem API call is limited in what it can return. The ReturnValues section lists two options: "NONE" (no return values) & "ALL_OLD" (data that was overwritten). Other API calls support options like "ALL_NEW" and "UPDATED_NEW" which might work for your use case.
If you use UpdateItem in place of PutItem and then include "ReturnValues": "ALL_NEW" or "ReturnValues": "UPDATE_NEW" in your integration request, the response will contain either the new or updated item attributes in the "body-json" as "Attributes". https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
Relevant content
- Accepted Answerasked 8 months ago
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
Thank you. But in the example in the blogpost does no approach this from a POST request, it does it from a GET request where they retrieve the data from the DB Items. Since my POST request is not retrieving but it is creating records, I need to a way to map in the response those items that were added.