AnomalyInnovations / aws-api-gateway-cli-test

A simple CLI to test API Gateway endpoints with IAM authorization
MIT License
120 stars 29 forks source link

Doesn't appear to use standard AWS API for access? #18

Open boxabirds opened 4 years ago

boxabirds commented 4 years ago

Firstly thanks for this tool! It is really useful for debugging issues.

And also, I spent a big chunk of time hunting down what was in the end a simple typo in my code for the name of the primary index column. One of the problems that slightly exacerbated it was that the HTTP status code returned was 500 but under the hood it's actually 400. E.g.

Making API request
{
  status: 500,
  statusText: 'Internal Server Error',
  data: {
    status: false,
    exception: '{"message":"The provided key element does not match the schema","code":"ValidationException","time":"2019-12-22T00:18:40.455Z","requestId":"CRVC9347J1AGP60CB6818OPN6JVV4KQNSO5AEMVJF66Q9AXXXXXX","statusCode":400,"retryable":false,"retryDelay":40.114206418810625}'
  }

Digging into the code a bit to see where this mapping was, I noticed this CLI utility, as helpful as it is, seems to refer to this independent AWS client. I'm confused because that repository does have headers that say copyright Amazon; I can only presume this is a fork?

The issue is I don't think the 400 code should be mapped to a 500 code as this loses important information and is hard to trace back to official AWS docs when the code has been changed.

jayair commented 4 years ago

Hmm I don't think it's doing any error mapping AFAIK. How do you know it was a 400 error?

boxabirds commented 4 years ago

Ah yes so when I try and run the query directly using the dynamodb cli it produces the 400 error.

The column is "noteId" as per book, but I had "nodeId" and it produced this error:

https://aws.amazon.com/premiumsupport/knowledge-center/key-element-error-dynamodb-hive-emr/

… which is error 400 apparently.

aws dynamodb update-item --cli-input-json '{
  "TableName": "notes",                                                                                                                  "Key": {                                                                                                                                 "userId": { "S": "us-east-1:…" },
    "noteId": { "S": "5bb9e890…" }
  },
  "UpdateExpression": "SET content = :content, attachment = :attachment",
  "ExpressionAttributeValues": {
    ":attachment": { "S": "hello.jpg" },
    ":content": { "S": "hello world" }
  },
  "ReturnValues": "ALL_NEW"
}
'
jayair commented 4 years ago

Right but the Lambda function returns a 500 error? The CLI isn't doing any remapping in this case right?