dynamodb“ GetItem操作:找不到请求的资源” /“提供的关键元素与架构不匹配”

时间:2019-12-29 09:11:22

标签: amazon-web-services amazon-dynamodb serverless

我不知道该怎么解释:

$aws dynamodb scan --table-name Todos-dev  
...
{
    "Items": [
        {
            "todoId": {
                "S": "9e6e7f0f-97ee-4289-93b9-cb1bf46d5190"
            },
            "createdAt": {
                "S": "2019-12-29T07:11:09.581Z"
            },
            "name": {
                "S": "test4"
            },
            "userId": {

$ aws dynamodb get-item --table-name Todos.dev --key file://key.json

An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found

其中

$ cat key.json 
{"todoId": {"S": "9e6e7f0f-97ee-4289-93b9-cb1bf46d5190"}}

serverless.yml

    TodosTable:
      Type: AWS::DynamoDB::Table
      Properties:
        AttributeDefinitions:
          - AttributeName: todoId
            AttributeType: S
          - AttributeName: createdAt
            AttributeType: S
          - AttributeName: dueDate
            AttributeType: S
        KeySchema:
          - AttributeName: todoId
            KeyType: HASH
          - AttributeName: createdAt
            KeyType: RANGE
        BillingMode: PAY_PER_REQUEST
        TableName: ${self:provider.environment.TODOS_TABLE}
        LocalSecondaryIndexes:
          - IndexName: ${self:provider.environment.INDEX_NAME}
            KeySchema:
              - AttributeName: todoId
                KeyType: HASH
              - AttributeName: dueDate
                KeyType: RANGE
            Projection:
              ProjectionType: ALL

我收到的消息“所提供的键元素与架构不匹配”,来自docClient.delete,尝试了多种组合以指定键,但没有用。

1 个答案:

答案 0 :(得分:2)

关键元素与架构不匹配

您的表具有哈希键和范围键。您的key.json文件只有哈希键。使用getItem时,必须提供完整的(哈希和范围)键。如果要为同一哈希键获取多个值,或者如果范围键值未知,则只能使用哈希键,但必须使用query API。

找不到资源

您在扫描调用中使用Todos-dev,但在getItem调用中使用Todos.dev