1
votes

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

1 Answers

3
votes

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')"
}