Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Api gateway get output results from step function?

I followed tutorial on creating and invoking step functions

I'm getting output in my GET request of api as

 {
  "executionArn": "arn:aws:states:ap-northeast-1:123456789012:execution:HelloWorld:MyExecution",
  "startDate": 1.486772644911E9
}

But, instead of above response I want my step functions output, which is given by end state as below.

{
   "name":"Hellow World"
}

How to achieve this?

like image 273
Jagdish Idhate Avatar asked May 18 '17 07:05

Jagdish Idhate


People also ask

Can we call step function from API gateway?

You can use Amazon API Gateway to associate your AWS Step Functions APIs with methods in an API Gateway API. When an HTTPS request is sent to an API method, API Gateway invokes your Step Functions API actions.

How do you pass data between Step Functions?

You can give AWS Step Functions initial input data by passing it to a StartExecution action when you start an execution, or by passing initial data using the Step Functions console . Initial data is passed to the state machine's StartAt state. If no input is provided, the default is an empty object ( {} ).


Video Answer


2 Answers

Update: You can now use Express Step Functions for synchronous requests.

AWS Step Functions are asynchronous and do not immediately return their results. API Gateway methods are synchronous and have a maximum timeout of 29 seconds.

To get the function output from a Step Function, you have to add a second method in API Gateway which will call the Step Function with the DescribeExecution action. The API Gateway client will have to call this periodically (poll) until the returned status is no longer "RUNNING".

Here's the DescribeExecution documentation

like image 131
MikeD at AWS Avatar answered Oct 14 '22 05:10

MikeD at AWS


New Synchronous Express Workflows for AWS Step Functions is the answer: https://aws.amazon.com/blogs/compute/new-synchronous-express-workflows-for-aws-step-functions/

Amazon API Gateway now supports integration with Step Functions StartSyncExecution for HTTP APIs: https://aws.amazon.com/about-aws/whats-new/2020/12/amazon-api-gateway-supports-integration-with-step-functions-startsyncexecution-http-apis/

like image 12
Pooya Paridel Avatar answered Oct 14 '22 06:10

Pooya Paridel