- Newest
- Most votes
- Most comments
To proxy Step Function responses through API Gateway, you'll need to take a slightly different approach than you would with a Lambda proxy integration. While Step Functions don't have a direct proxy integration like Lambda functions do, you can achieve a similar result by following these steps:
-
Create an API Gateway API that integrates with your Step Function.
-
Set up a POST method on a resource in your API Gateway. This method will be used to start the Step Function execution.
-
Configure the integration request to map to the StartExecution API action of Step Functions. You'll need to provide the necessary parameters, including the state machine ARN, in the request mapping template.
-
In your Step Function, ensure that the final state returns the desired response format. This should include the statusCode, headers, and body that you want to return to the client.
-
In the API Gateway method response, set up the appropriate status codes and response models.
-
In the integration response, create a mapping template to transform the Step Function output into the format expected by API Gateway. This is where you'll map the Step Function's response to the actual HTTP response.
Here's an example of what your mapping template in the integration response might look like:
#set($stepFunctionsResponse = $util.parseJson($input.body))
$stepFunctionsResponse.output
This template assumes that your Step Function's final state returns a JSON object with the structure you described (headers, statusCode, body).
Remember that unlike Lambda proxy integration, you'll need to manually set up the mapping between the Step Function output and the API Gateway response. This gives you more control but requires more configuration.
Also, keep in mind that Step Functions executions are asynchronous by nature. If you need to return the final result of the execution to the client immediately, you might need to implement a polling mechanism or use a synchronous express workflow, depending on your specific use case and the complexity of your state machine.
By following these steps and adjusting the configuration as needed, you can effectively "proxy" your Step Function responses through API Gateway in a way that's similar to Lambda proxy integration.
Sources
Creating a Step Functions API using API Gateway - AWS Step Functions
Lambda proxy integrations in API Gateway - Amazon API Gateway
Invoking a Lambda function using an Amazon API Gateway endpoint - AWS Lambda

This doesn't adapt the statuscode of the api response. The lambda function could return a statusCode 400, but the api gateway responds with 200 (the statusCode 400 is contained with the body of the response instead)