为什么我需要获得项目'使用AWS步骤函数在DynamoDB中更新项目时?
我正在尝试在设置有条件表达式时通过步骤函数推动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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有2个主要DynamoDB API用于修改项目:
在简而言之,
putiTem
'更新项目'通过替换&amp;因此,它需要通过替换项目。这是您正在使用的API调用,这就是为什么您需要获得“项目”,但缺少
。这是正确的,item
是使用putitem
时需要。取而代之的是,您需要使用
updateItem
,该>不需要全部新项目&amp;将根据更新表达式(这是您拥有的)修改项目的属性。在您的步骤函数定义中,替换
为:
There are 2 main DynamoDB APIs for modifying items:
PutItem
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 gettingThe field 'Item' is required but was missing
. It's correct,Item
is required when usingPutItem
.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:
With: