从GSI获取项目,但出现了“提供的键元素与模式不匹配”的错误。

huangapple go评论73阅读模式
英文:

Get item from GSI but got "The provided key element does not match the schema"

问题

以下是您要求的翻译:

我在AWS DynamoDB表中有一个带有ref1、ref2和ref3的列,就像这样
从GSI获取项目,但出现了“提供的键元素与模式不匹配”的错误。

这是概述
从GSI获取项目,但出现了“提供的键元素与模式不匹配”的错误。

我正在尝试使用ref1、ref2和ref3作为复合键在AWS DynamoDB中获取记录
从GSI获取项目,但出现了“提供的键元素与模式不匹配”的错误。

  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
从GSI获取项目,但出现了“提供的键元素与模式不匹配”的错误。

Here is overview
从GSI获取项目,但出现了“提供的键元素与模式不匹配”的错误。

I am trying to get a record in AWS DynamoDB with ref1, ref2, and ref3 as a composite key
从GSI获取项目,但出现了“提供的键元素与模式不匹配”的错误。

  params = {
    TableName: process.env.PAYMENT_DB_TRANSACTION,
    Key: {
      &quot;ref1&quot;: billPaymentRef1,
      &quot;ref2&quot;: billPaymentRef2,
      &quot;ref3&quot;: billPaymentRef3
    }
  };
  console.log(params);
  docClient.get(params, function(err, data) {
    if (err) {
        console.error(&quot;Unable to read item. Error JSON:&quot;, JSON.stringify(err, null, 2));
    } else {
        console.log(&quot;GetItem succeeded:&quot;, JSON.stringify(data, null, 2));
    }
  });

I confirm that params is correct

{
  TableName: &#39;payment-th-stg-v2-op-transaction&#39;,
  Key: { ref1: &#39;REF1&#39;, ref2: &#39;REF2&#39;, ref3: &#39;REF3&#39; }
}

Here is the error

Unable to read item. Error JSON: {
  &quot;message&quot;: &quot;The provided key element does not match the schema&quot;,
  &quot;code&quot;: &quot;ValidationException&quot;,
  &quot;time&quot;: &quot;2020-01-03T12:17:39.090Z&quot;,
  &quot;requestId&quot;: &quot;PDC6A7N22Q8BT789H3K2I1N9VNVV4KQNSO5AEMVJF66Q9ASUAAJG&quot;,
  &quot;statusCode&quot;: 400,
  &quot;retryable&quot;: false,
  &quot;retryDelay&quot;: 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.

huangapple
  • 本文由 发表于 2020年1月3日 20:23:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578600.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定