In this code snippet I try to get an item from a table which has partitionKey as a messageId
case "GET /items/{messageId}":
const { messageId } = event.pathParameters;
body = await dynamo.send(
new GetCommand({
TableName: tableName,
Key: {
'messageId': messageId,
},
})
);
body = body.Items;
break;
Always getting 500 internal error response. Other calls work
I expect to get the specific item based on partitionKey whihc is messageId.
API that I am trying to call /items/66746629-7220-46fb-a8d4-7059fbf0991f
2
Answers
I was able to resolve it. It was different path parameter(id) instead of (messageId) on API gateway. As well instead of getting body.Items I needed to get the body.Item as it returns single one.
You’re not getting a 500 from DynamoDB, you’re getting it from Lambda thrown back to APIGW.
Your issue is caused by how you send responses to APIGW, you should handle all scenarios on your code using try/catch and return a response to APIGW that it understands.
Here is an example of a response in node
Actions