为什么我需要获得项目'使用AWS步骤函数在DynamoDB中更新项目时?

发布于 2025-02-01 12:00:22 字数 1080 浏览 2 评论 0原文

我正在尝试在设置有条件表达式时通过步骤函数推动DynamoDB记录,但是由于某种原因,我会遇到错误:

您的状态计算机定义中存在亚马逊状态语言错误。修复错误继续。 需要“项目”字段,但丢失(在/state/mystep/parameters)

我不想推item。我想使用更新表达式。

这是我的代码:

{
  "StartAt": "MyStep",
  "States": {
    "MyStep": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Parameters": {
        "TableName.$": "$.table_name",
        "Key": {
          "test_id_path_method_executor_id": {"S.$": "$.update_key.test_id_path_method_executor_id"},
          "result_timestamp": {"S.$": "$.update_key.result_timestamp"}
        },
        "ConditionExpression": "#max_db < :max_values",
        "ExpressionAttributeValues": {
          ":max_values": {"N.$": "$.result_value"}
        },
        "ExpressionAttributeNames": {
          "#max_db": "max"
        },
        "UpdateExpression": "SET #max_db = :max_values"
      },
      "Next": "EndSuccess"
    },
    "EndSuccess": {
      "Type":"Succeed"
    }
  }
}

问题是什么?

I'm trying to push a DynamoDB record through Step Functions while setting up a conditional expression but for some reason, I'm getting the error:

There are Amazon States Language errors in your state machine definition. Fix the errors to continue.
The field 'Item' is required but was missing (at /States/MyStep/Parameters)

I don't want to push an Item. I want to use an update expression.

Here's my code:

{
  "StartAt": "MyStep",
  "States": {
    "MyStep": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:putItem",
      "Parameters": {
        "TableName.
quot;: "$.table_name",
        "Key": {
          "test_id_path_method_executor_id": {"S.
quot;: "$.update_key.test_id_path_method_executor_id"},
          "result_timestamp": {"S.
quot;: "$.update_key.result_timestamp"}
        },
        "ConditionExpression": "#max_db < :max_values",
        "ExpressionAttributeValues": {
          ":max_values": {"N.
quot;: "$.result_value"}
        },
        "ExpressionAttributeNames": {
          "#max_db": "max"
        },
        "UpdateExpression": "SET #max_db = :max_values"
      },
      "Next": "EndSuccess"
    },
    "EndSuccess": {
      "Type":"Succeed"
    }
  }
}

What's the issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾其所爱 2025-02-08 12:00:22

有2个主要DynamoDB API用于修改项目:

在简而言之,putiTem'更新项目'通过替换&amp;因此,它需要通过替换项目。这是您正在使用的API调用,这就是为什么您需要获得“项目”,但缺少。这是正确的,item 是使用putitem时需要

取而代之的是,您需要使用updateItem,该>不需要全部新项目&amp;将根据更新表达式(这是您拥有的)修改项目的属性。

在您的步骤函数定义中,替换

"Resource": "arn:aws:states:::dynamodb:putItem",

为:

"Resource": "arn:aws:states:::dynamodb:updateItem",

There are 2 main DynamoDB APIs for modifying items:

  1. PutItem
  2. UpdateItem

In a nutshell, PutItem 'updates' the item by replacing it & because of this, it requires the replacement item to be passed. This is the API call you're using and is why you're getting The field 'Item' is required but was missing. It's correct, Item is required when using PutItem.

Instead, you need to use UpdateItem which does not require the new item in full & will modify the attributes of an item based on an update expression (which is what you have).

In your step function definition, replace:

"Resource": "arn:aws:states:::dynamodb:putItem",

With:

"Resource": "arn:aws:states:::dynamodb:updateItem",
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文