rest api gateway + dynamodb 在 GET 调用时给出 404

0

【以下的问题经过翻译处理】 你好, 我正在按照 本指南 在发电机数据库表前创建测试 REST api gw。

虽然 POST 调用测试有效,但当我尝试 GET 检索用户名时,我总是得到 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


这是我的 GET 集成请求应用程序/json 映射模板


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


如果我在 dynamodb 上测试查询,是正常工作的:

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

其中 file://expression-attributes.json

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

gives

{ "Items": [ { "realname": { "S": "xxxxx" }, "username": { "S": "ABE" }, "uid": { "S": "fc1d4fa5-6157-47c7-85a7-3953e477b396" } }
profile picture
专家
已提问 8 个月前79 查看次数
1 回答
0

【以下的回答经过翻译处理】 对于GET方法的集成请求,请确保选择POST作为HTTP方法,因为所有DynamoDB查询都是使用POST方法。

profile picture
专家
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则