2

I'm creating a CloudFormation template for the platform I'm working on. I need to integrate Api Gateway and Step Functions, to make one of my step functions be executed by a call to a Api Gateway Method.

I'm not finding any documentation on this. I struggled to find the Integration/Uri, that should be

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

but now I'm not sure on what to write in my RequestTemplates. I suppose that I could actually leave it empty, to make it act like a proxy, but I would really appreciate if you could give me any further information.

Thank you

1 Answer 1

3

Obviously I could not leave RequestTemplates empty because it contains the information on what StateMachine is to be called. The URI itself doesn't contain that information, but it just points to the State Machine API's entrypoint.

The correct way comes from this documentation's page.

State Machine APIs expose various methods. The one to execute the Step Function is "StartExecution". To that entrypoint a body formed like this has to be passed

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

So, in 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]"
                }
            }]
        }
    }
}
3
  • Does this work with serverless cloudformation transform as well?
    – Kwhitejr
    Dec 18, 2018 at 18:54
  • Also, what resource type / property does the Integration config come under?
    – Kwhitejr
    Dec 18, 2018 at 20:06
  • @Kwhitejr you can define the api in swagger and pull that into the CFN. Integration goes under AWS::ApiGateway::Method
    – samtoddler
    Jan 2, 2021 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.