1

I'm having an issue when calling a GET REST (Regional) API which then invokes DynamoDB Scan API to get all the items of a table called City-Temperature.

As a request parameter, I'm adding only 'tablename' since it's required to call DynamoDB:Scan API. But on testing the API, I'm getting a 400 status from DynamoDB with error as follows:

{
  "__type": "com.amazon.coral.validate#ValidationException",
  "message": "1 validation error detected: Value null at 'tableName' failed to satisfy constraint: Member must not be null"
}

For simplicity, the dynamoDB table "City-Temperature" contains five items with each item 'City' (primary key - String) containing a single attribute (string) "Temperature".

My steps to generate API Service Proxy:

  1. Created a new REST API.
  2. Created a resource named "get-cities-temp"
  3. Created a child resource named 'table-name' with path {tablename}
  4. Created a GET method to child resource with:
    • Integration-type: AWS Service
    • Region: Same as DynamoDB region
    • Service: DynamoDB
    • Action: Scan
    • HTTP Method: POST (since all requests to DynamoDB are made using POST)
    • Execution role ARN: (Assumed role created for API-Gateway and attached a policy which allows only single action "DynamoDB:Scan" with a resource ARN pointing to DyanmoDB "City-Temperature" table.
  5. In Integration-Method pane, I kept the 'Content-handling' to 'passthrough', and added Mapping Template with content-type 'application/json' to transform request with single param 'tablename' to be DynamoDB compatible as follows:

To add here: 'Request Body Passthrough' is set to 'When there are no templates defined (recommended)'

{
    "tableName": "$input.params('tablename')"
}

Finally, in test section, I add tablename=City-Temperature as a query string to pass in table's name for Scan API and hit 'Test'. But an error as mentioned above is being thrown in response.

Update:

In logs, it looks like request body after transformation is being properly converted: { "tablename": "City-Temperature" }. But yet, same error as above

1 Answer 1

3

Based on https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for-dynamodb/, tableName is not of attribute object type, but rather a simple string. EDIT: also property should be pascal cased. Thus following change should do

{
    "TableName":"$input.params('tablename')"
}
Sign up to request clarification or add additional context in comments.

4 Comments

I changed the request mapping template to this. But still getting same error.
Can you try to change template to Pascal cased property? i.e. "TableName":"$input.params('tablename')"
Can't believe I overlooked that! Few blogs that are related to this topic did have PascalCase in mapping template.
Good news :-), I edited the answer so that it specifies Pascal cased property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.