问题描述
每当我在以下代码中使用“ ResultPath”时,我都会不断收到错误消息:“ Step Functions不支持字段'ResultPath'”:
{
"StartAt": "OuterFunction","States": {
"OuterFunction": {
"Type": "Map","Iterator": {
"StartAt": "GetIteration","States": {
"GetIteration": {
"Type": "Pass","ResultPath": "$.iteration","Next": "ReadDynamoDB"
},"ReadDynamoDB": {
"Type": "Task","Resource": "arn:aws:states:::dynamodb:getItem","Parameters": {
"TableName": "TestTable","Key": {
"Keyword": "$.iteration"
},"ResultPath": "$.dynamoDBResult"
},"Next": "DoWork"
},"DoWork": {
"Type": "Task","InputPath": "$.dynamoDBResult","Resource": "arn:aws:states:::states:startExecution.sync","Parameters": {
"StateMachineArn":"arn:aws:states:46372839402:stateMachine:do-work","Input.$": "$.dynamoDBResult"
},"End": true
}
}
},"End": true
}
}
}
对于每次迭代,都打算转到DynamoDB表中,获取与键字符串对应的项目,然后将该项目发送到其他地方以完成更多工作。但是,每当我尝试保存代码时,都会收到一条消息,告诉我不支持“ ResultPath”,并且step函数将不会运行。我非常困惑,因为我看到许多人在线使用“ ResultPath”的例子。这是因为我在迭代器中使用它吗?我还能如何在任务之间传递每次迭代的输入?
解决方法
我认为问题在于您将 ResultPath
包含在 Parameters
中,而它应该在外部。
看这个例子: https://docs.aws.amazon.com/step-functions/latest/dg/connect-ddb.html
"Read Next Message from DynamoDB": {
"Type": "Task","Resource": "arn:aws:states:::dynamodb:getItem","Parameters": {
"TableName": "TransferDataRecords-DDBTable-3I41R5L5EAGT","Key": {
"MessageId": {"S.$": "$.List[0]"}
}
},"ResultPath": "$.DynamoDB","Next": "Send Message to SQS"
}
这意味着您的代码应该是:
I keep receiving the error,"The field 'ResultPath' is not supported by Step Functions" whenever I use "ResultPath" in the following code:
{
"StartAt": "OuterFunction","States": {
"OuterFunction": {
"Type": "Map","Iterator": {
"StartAt": "GetIteration","States": {
"GetIteration": {
"Type": "Pass","ResultPath": "$.iteration","Next": "ReadDynamoDB"
},"ReadDynamoDB": {
"Type": "Task","Parameters": {
"TableName": "TestTable","Key": {
"Keyword": "$.iteration"
}
},"ResultPath": "$.dynamoDBResult","Next": "DoWork"
},"DoWork": {
"Type": "Task","InputPath": "$.dynamoDBResult","Resource": "arn:aws:states:::states:startExecution.sync","Parameters": {
"StateMachineArn":"arn:aws:states:46372839402:stateMachine:do-work","Input.$": "$.dynamoDBResult"
},"End": true
}
}
},"End": true
}
}
}