2017-08-28 103 views
1

我想和失敗,刪除條件的記錄。我不斷收到此錯誤:The provided key element does not match the schema無服務器:dynamodb刪除條件

這是我在陽明定義:

resources: 
    Resources: 
    vuelosTable: 
     Type: 'AWS::DynamoDB::Table' 
     DeletionPolicy: Delete 
     Properties: 
     AttributeDefinitions: 
      - 
      AttributeName: id 
      AttributeType: S 
      - 
      AttributeName: vuelta 
      AttributeType: S 
     KeySchema: 
      - 
      AttributeName: id 
      KeyType: HASH 
      - 
      AttributeName: vuelta 
      KeyType: RANGE 
     ProvisionedThroughput: 
      ReadCapacityUnits: 1 
      WriteCapacityUnits: 1 
     TableName: ${self:provider.environment.DYNAMODB_TABLE} 

這些試圖刪除的時候是PARAMS:

params = { 
    RequestItems: { 
     [process.env.DYNAMODB_TABLE]: [{ 
     DeleteRequest: { 
      Key: { 
      "vuelta": "2017-09-09" 
      } 
     } 
     }] 
    } 
    }; 

我知道這件事情,我沒有得到,但我不知道什麼。有任何想法嗎?

回答

0

您的表格密鑰既是id也是vuelta,但您只是在刪除請求中提供了vuelta。修改您的刪除請求中的密鑰,使其包含idvuelta

另外,根據您的客戶端庫可能需要指定

Key: { 
    id: { S: "some value" }, 
    vuelta: { S: "some value" } 
} 
+0

好的,但限制了我。我必須有ID才能刪除。我希望能夠刪除只有vuelta值。另外,考慮到vuelta在不同記錄中並不是唯一的。 – yBrodsky

+0

DeleteItem僅刪除單個項目。沒有批量刪除API。唯一的選擇是掃描/查詢表或其索引以找到密鑰,然後單獨刪除它們。 –

+0

我正在使用batchWrite,它可以用來放置/刪除文檔。 http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html – yBrodsky