我想要一个将 AWS API Gateway 与 Step Function 集成的示例。我已阅读本教程 Creating a Step Functions API Using API Gateway 但该教程需要我以以下格式发送请求
{
"input": "{}",
"name": "PostmanExecution",
"stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:Custom"
}
我想发送普通请求并仅在 API 网关中配置这个 stateMachineArn ,这样客户端就不需要发送这个了。
最佳答案
创建您的 API 网关资源和方法。然后在“方法执行”设置中,在集成请求中,使用以下设置:
然后是魔法。再往下,在 body 映射模板下:
在模板文本框中进一步向下:
#set($input = $input.json('$'))
{
"input": "$util.escapeJavaScript($input)",
"stateMachineArn": "arn:aws:states:eu-west-1:123456789012:stateMachine:yourStepFunctionName"
}
这会将发布到 API Gateway 的 json 负载传递到 Step Function。
省略执行名称,以便每次调用 API Gateway 都会创建一个新的执行。
关于amazon-web-services - 带 Step Function 的 AWS API 网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44605228/