I would like to know how to make API Gateway call a Step Function and execute it.
Conclusion. The Step Functions integration with API Gateway provides customers with the ability to call REST APIs and HTTP APIs directly from a Step Functions workflow. Step Functions' built in error handling helps developers reduce code and decouple business logic.
Log in to the AWS Identity and Access Management console. On the Roles page, choose Create New Role. On the Set Role Name page, type APIGatewayToStepFunctions for Role Name, and then choose Next Step. On the Select Role Type page, under Select Role Type, select Amazon API Gateway.
Open the Step Functions console and choose Create state machine. Choose Run a sample project, and then choose Make a call to API Gateway. The state machine Code and Visual Workflow are displayed. Choose Next.
API Gateway added support for Step Functions currently. Now you can create an AWS Service integration via API Gateway Console.
Headers:
X-Amz-Target -> 'AWSStepFunctions.StartExecution'
Content-Type -> 'application/x-amz-json-1.0'
Body Mapping Templates/Request payload:
{ "input": "string", "name": "string", "stateMachineArn": "string" }
You can create an API Gateway Endpoint with Integration type: AWS Service
and set it up to invoke the required Step Function.
In case you want to use API Gateway so that you can control the exposure of your Step Functions endpoint, you can create a new IAM user (programmatic access only) with a policy that only grants access to this endpoint, eg:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"execute-api:Invoke"
],
"Resource": [
"arn:aws:execute-api:us-east-1:my-aws-account-id:my-api-id/my-stage/GET/my-resource-path"
]
}
]
}
I think you can use API Gateway Proxy Integration to AWS service. Look: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings-console.html
Consider creating an AWS Lambda function that backs the APIGw endpoint and having it call AWS StepFunctions via code. We use this approach because our use case allows the API endpoint parameters to direct which of several StepFunctions we need to execute.
Admittedly, it is "more code"; we're hoping AWS elaborates StepFunctions such that they can be triggered by the whole host of AWS resource events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With