【问题标题】:How to integrate, by CloudFormation, Api Gateway with Step Functions如何通过 CloudFormation 将 API 网关与 Step Functions 集成
【发布时间】:2018-08-16 22:19:39
【问题描述】:

我正在为我正在使用的平台创建一个 CloudFormation 模板。我需要集成 Api Gateway 和 Step Functions,以通过调用 Api Gateway Method 来执行我的 Step Functions 之一。

我没有找到任何关于此的文档。我很难找到集成/Uri,应该是

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

但现在我不确定要在我的 RequestTemplates 中写什么。我想我实际上可以把它留空,让它像代理一样,但如果你能提供更多信息,我将不胜感激。

谢谢

【问题讨论】:

    标签: amazon-web-services aws-api-gateway amazon-cloudformation aws-step-functions


    【解决方案1】:

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

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

    状态机 API 公开了各种方法。执行 Step Function 的是“StartExecution”。必须将这样形成的主体传递到该入口点

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

    因此,在 Cloud Formation 中:

    "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]"
                    }
                }]
            }
        }
    }
    

    【讨论】:

    • 这是否也适用于 serverless cloudformation 转换?
    • 另外,Integration 配置属于什么资源类型/属性?
    • @Kwhitejr 您可以在 swagger 中定义 api 并将其拉入 CFN。集成在AWS::ApiGateway::Method
    猜你喜欢
    • 2017-05-02
    • 2020-05-12
    • 1970-01-01
    • 2019-07-14
    • 2020-06-16
    • 1970-01-01
    • 2018-01-29
    • 2017-04-08
    • 2019-11-03
    相关资源
    最近更新 更多