如何通过 CloudFormation 将 Api 网关与 Step Functions 集成

How to integrate, by CloudFormation, Api Gateway with Step Functions

我正在为我正在使用的平台创建一个 CloudFormation 模板。我需要集成 Api 网关和步骤功能,通过调用 Api 网关方法来执行我的步骤功能之一。

我没有找到关于此的任何文档。好不容易才找到Integration/Uri,应该是

arn:aws:apigateway:${region}:states:action/StartExecution

但现在我不确定在我的 RequestTemplates 中写什么。我想我实际上可以将其留空,使其充当代理,但如果您能给我任何进一步的信息,我将不胜感激。

谢谢

显然我不能将 RequestTemplates 留空,因为它包含有关要调用什么 StateMachine 的信息。 URI 本身不包含该信息,但它仅指向状态机 API 的入口点。

正确的方法来自this documentation's page.

状态机API公开了各种方法。执行Step Function的是"StartExecution"。必须向该入口点传递一个像这样形成的 body

{
"input": "string",
"name": "string",
"stateMachineArn": "string"
}

所以,在云形成中:

"Integration": {
    "Type": "AWS",
    "IntegrationHttpMethod": "POST",
    "Uri": {
        "Fn::Join": ["",
            ["arn:aws:apigateway:",
            {
            "Ref": "AWS::Region"
            },
            ":states:action/StartExecution"]]
        },
    "RequestTemplates": {
        "application/json": {
            "Fn::Sub": ["{\"input\": \"$util.escapeJavaScript($input.json('$'))\",\"stateMachineArn\": \"${arn}\"}",
            {
            "arn": {
                "Ref": "[StepMachineResourceName]"
                }
            }]
        }
    }
}