簡體   English   中英

Dynamodb獲取項目錯誤

[英]Dynamodb get item is erroring out

使用javascript aws sdk

我的表定義如下:

  resources:
  Resources:
    ImagesTable:
      Type: "AWS::DynamoDB::Table"
      Properties:
        AttributeDefinitions:
          - AttributeName: "deviceId"
            AttributeType: "S"
          - AttributeName: "timeStamp"
            AttributeType: "N"
        KeySchema:
          - AttributeName: "deviceId"
            KeyType: "HASH"
          - AttributeName: "timeStamp"
            KeyType: "RANGE"
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:custom.settings.${self:custom.myStage}.ITEMS_DYNAMODB_TABLE}
        StreamSpecification:
          StreamViewType: NEW_IMAGE

我嘗試運行查詢並獲取所有與字符串匹配的設備。

我的params對象是

        const params: DynamoDB.DocumentClient.GetItemInput = {
          TableName: eventLogTable,
          Key: {deviceId: 'device12345'}
        };

我的電話是

return this.client.get(params).promise()
        .then(result => {
            return result;
        });

在日志文件中,我看到以下錯誤:

2019-06-21T17:23:27.878Z    cc865442-8604-4f5c-8099-72eba87d9b2b    query params right before going in { TableName: 'sls-basic-operations-items-dev',
Key: { deviceId: 'device12345' } }
2019-06-21T17:23:27.904Z    cc865442-8604-4f5c-8099-72eba87d9b2b    { ValidationException: The provided key element does not match the schema

不明顯我的錯誤是什么? 有什么想法嗎?

看來這里出了問題,是您在使用dynamodb客戶端Get操作時僅指定了哈希鍵。 由於您的表具有范圍鍵(排序鍵),因此,您還應該在Getitem請求中指定該范圍。如果您只想使用哈希鍵搜索記錄,則應使用查詢操作。 params = {TableName:'eventLogTable',KeyConditionExpression:'#deviceId =:deviceId'}; DynamoDB.DocumentClient.query(參數,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM