状态机任务在调用 SNS 主题后卡在 "Running" 状态

State machine task gets stuck in "Running" state after calling SNS Topic

我有一个发布到 SNS 主题的步骤函数,然后该主题会发送电子邮件通知。电子邮件通知按预期发送,但任务在应该退出并终止步骤功能时卡在“运行”状态。有谁知道我哪里出错了或者是什么原因造成的?

"ErrorNotification": {
  "Type": "Task",
  "Resource":"arn:aws:states:::sns:publish.waitForTaskToken",
  "OutputPath": "$",
  "Parameters": {
    "TopicArn": "<topic-arn>",
    "Message":{  
      "Input.$":"$",
      "TaskToken.$":"$$.Task.Token"
    }
  },
   "End": true
},  

此特定行

"Resource":"arn:aws:states:::sns:publish.waitForTaskToken",

实施 Wait for a Callback with the Task Token

Call Amazon SNS with Step Functions

The following includes a Task state that publishes to an Amazon SNS topic and then waits for the task token to be returned. See Wait for a Callback with the Task Token.

{  
   "StartAt":"Send message to SNS",
   "States":{  
      "Send message to SNS":{  
         "Type":"Task",
         "Resource":"arn:aws:states:::sns:publish.waitForTaskToken",
         "Parameters":{  
            "TopicArn":"arn:aws:sns:us-east-1:123456789012:myTopic",
            "Message":{  
               "Input.$":"$",
               "TaskToken.$":"$$.Task.Token"
            }
         },
         "End":true
      }
   }
}

在这种情况下,您需要检查您是否从处理回调的(通常是 lambda)发送了适当的事件并将最终响应发回。

例如,我通过 lambda 处理我的回调功能,大致如下 successfulfailed


...
LOG.info(f"Sending task heartbeat for task ID {body['taskToken']}")
STEP_FUNCTIONS_CLIENT.send_task_heartbeat(taskToken=body["taskToken"])
is_task_success = random.choice([True, False])

if is_task_success:
    LOG.info(f"Sending task success for task ID {body['taskToken']}")
    STEP_FUNCTIONS_CLIENT.send_task_success(
        taskToken=body["taskToken"],
        output=json.dumps({"id": body['id']})
    )
else:
    LOG.info(f"Sending task failure for task ID {body['taskToken']}")
    STEP_FUNCTIONS_CLIENT.send_task_failure(
        taskToken=body["taskToken"],
        cause="Random choice returned False."
    )
..