rest api gateway in front of dynamodb gives 404 on GET calls

0

Hi, I am following this guide to create a test REST api gw in front of a dynamo db table.

While the POST call tests work, when I try the GET to retrieve a username I always get a 404


Fri Feb 11 07:17:40 UTC 2022 : Endpoint request URI: https://dynamodb.us-east-1.amazonaws.com/?Action=Query
Fri Feb 11 07:17:40 UTC 2022 : Endpoint request headers: {Authorization=****************************************************************************************************************************************************************************************************************************************************************************************82e823, X-Amz-Date=20220211T071740Z, x-amzn-apigateway-api-id=2xxp28f39k, Accept=application/json, User-Agent=AmazonAPIGateway_2xxp28f39k, X-Amz-Security-Token=xxxxx
Fri Feb 11 07:17:40 UTC 2022 : Endpoint request body after transformations: {
    "TableName": "users",
    "IndexName": "username-index",
    "KeyConditionExpression": "username = :val",
    "ExpressionAttributeValues": {
        ":val": {
            "S": "ABE"
        }
    }
}
Fri Feb 11 07:17:40 UTC 2022 : Sending request to https://dynamodb.us-east-1.amazonaws.com/?Action=Query
Fri Feb 11 07:17:40 UTC 2022 : Received response. Status: 404, Integration latency: 2 ms

this is my GET integration request application/json mapping template


{
    "TableName": "users",
    "IndexName": "username-index",
    "KeyConditionExpression": "username = :val",
    "ExpressionAttributeValues": {
        ":val": {
            "S": "$input.params('username')"
        }
    }
}

If I test the query on dynamodb it works:

aws dynamodb query \
    --table-name $tablename \
    --index-name $indexname \
    --key-condition-expression "username = :v1" \
    --expression-attribute-values file://expression-attributes.json \
    --select ALL_PROJECTED_ATTRIBUTES \
    --return-consumed-capacity INDEXES

where file://expression-attributes.json

{
    ":v1": {"S": "ABE"}
}



gives

{ "Items": [ { "realname": { "S": "xxxxx" }, "username": { "S": "ABE" }, "uid": { "S": "fc1d4fa5-6157-47c7-85a7-3953e477b396" } }

any idea what I am missing?
3 Antworten
1
Akzeptierte Antwort

For the GET method Integration Request, ensure you choose POST for the HTTP method since all DynamoDB Queries are POST.

profile picture
joahna
beantwortet vor 2 Jahren
profile picture
EXPERTE
überprüft vor einem Monat
1

From a really quick glance it seems you do not pass the username in to the query string: https://dynamodb.us-east-1.amazonaws.com/?Action=Query

Have you enabled CloudWatch logging on your API GW Endpoint? Should see better information there.

https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html

profile pictureAWS
EXPERTE
beantwortet vor 2 Jahren
0

Bingo! I needed POST in DynamoDB integration "spasiba"

beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen