英文:
Get item from GSI but got "The provided key element does not match the schema"
问题
以下是您要求的翻译:
我在AWS DynamoDB表中有一个带有ref1、ref2和ref3的列,就像这样

我正在尝试使用ref1、ref2和ref3作为复合键在AWS DynamoDB中获取记录

  params = {
    TableName: process.env.PAYMENT_DB_TRANSACTION,
    Key: {
      "ref1": billPaymentRef1,
      "ref2": billPaymentRef2,
      "ref3": billPaymentRef3
    }
  };
  console.log(params);
  docClient.get(params, function(err, data) {
    if (err) {
        console.error("无法读取项目。错误JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("GetItem成功:", JSON.stringify(data, null, 2));
    }
  });
我确认params是正确的
{
  TableName: 'payment-th-stg-v2-op-transaction',
  Key: { ref1: 'REF1', ref2: 'REF2', ref3: 'REF3' }
}
这是错误信息
无法读取项目。错误JSON:{
  "message": "提供的键元素与架构不匹配",
  "code": "ValidationException",
  "time": "2020-01-03T12:17:39.090Z",
  "requestId": "PDC6A7N22Q8BT789H3K2I1N9VNVV4KQNSO5AEMVJF66Q9ASUAAJG",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 48.839609039271245
}
问题:<br>
我错在哪里?
英文:
I have AWS DynamoDB table with ref1, ref2, and ref3 at last column like this

I am trying to get a record in AWS DynamoDB with ref1, ref2, and ref3 as a composite key

  params = {
    TableName: process.env.PAYMENT_DB_TRANSACTION,
    Key: {
      "ref1": billPaymentRef1,
      "ref2": billPaymentRef2,
      "ref3": billPaymentRef3
    }
  };
  console.log(params);
  docClient.get(params, function(err, data) {
    if (err) {
        console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    }
  });
I confirm that params is correct
{
  TableName: 'payment-th-stg-v2-op-transaction',
  Key: { ref1: 'REF1', ref2: 'REF2', ref3: 'REF3' }
}
Here is the error
Unable to read item. Error JSON: {
  "message": "The provided key element does not match the schema",
  "code": "ValidationException",
  "time": "2020-01-03T12:17:39.090Z",
  "requestId": "PDC6A7N22Q8BT789H3K2I1N9VNVV4KQNSO5AEMVJF66Q9ASUAAJG",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 48.839609039271245
}
Question:<br>
Where am I wrong?
答案1
得分: 1
你需要使用主键来查询项目,而在你的情况下,主键由分区键 + 排序键组成:requestId + countryCode。
英文:
You will have to query the item using primary key which in your case is the partition key + sort key: requestId + countryCode.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论