I'm following along: Using Amazon API Gateway as a proxy for DynamoDB
Taking the blog's example, I want to tighten what and how data is written to a dynamodb table frontend by Api Gateway. To this end I define the following mapping in Api Gateway:
{
"TableName": "Comments",
"Item": {
"commentId": {
"S": "$context.requestId"
},
"pageId": {
"S": "$input.path('$.pageId')"
},
"userName": {
"S": "$input.path('$.userName')"
},
"message": {
"S": "$input.path('$.message')"
}
}
}
Following along, testing with the following example works just fine:
{
"pageId": "breaking-news-story-01-18-2016",
"userName": "Just Saying Thank You",
"message": "I really enjoyed this story!!"
}
However, let's say I want to keep the same mapping as above but want to make message optional. How would I do that? I can't get it to work. I've tried:
- using the above mapping as is, but sending a body without the
message-attribute. --> "One or more parameter values were invalid: An AttributeValue may not contain an empty string" 2 using the above mapping as is, but sending a body withmessage=null. --> "One or more parameter values were invalid: An AttributeValue may not contain an empty string" - changing above mapping by omitting the definition for
mapping-> passing a body now withoutmessagesucceeds obviously. However, sending a body withmessagedoesn't passmessagethrough (which is what I expected, but wanted to exhaust all options) - Don't use a mapping at all. Obviously that works, but now everything is passed-through unfiltered, which is unwanted.
Obviously I could use AWS lambda instead to do the mapping but this feels like such a common use-case, i.e.: optional attributes, that this must be possible directly in Api Gateway.