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개 답변
1
수락된 답변

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

profile picture
joahna
답변함 2년 전
profile picture
전문가
검토됨 한 달 전
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
전문가
답변함 2년 전
0

Bingo! I needed POST in DynamoDB integration "spasiba"

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠