Api gateway get output results from step function?

后端 未结 4 1977
别那么骄傲
别那么骄傲 2020-12-14 19:07

I followed tutorial on creating and invoking step functions

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

 {
  \"executionArn\": \"arn:aws:states:         


        
相关标签:
4条回答
  • 2020-12-14 19:23

    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/

    0 讨论(0)
  • 2020-12-14 19:29

    First of all the step functions executes asynchronously and API Gateway is only capable of invoking the step function (Starting a flow) only.

    If you are waiting for the results of a step function invocation from a web application, you can use AWS IOT WebSockets for this. The steps are as follows.

    • Setup AWS IOT topic with WebSockets.
    • Configure the API Gateway and Step functions invocation.
    • From the Web Frontend subscribe to the IOT Topic as a WebSocket listener.
    • At the last step (And in error steps) in the Step Functions workflow use AWS SDK to trigger the IOT Topic which will broadcast the results to the Web App running in the browser using WebSockets.

    For more details on WebSockets with AWS IOT refer the medium article Receiving AWS IoT messages in your browser using websockets.

    0 讨论(0)
  • 2020-12-14 19:29

    Expanding on what @MikeD at AWS says, if you're certain that the Step Function won't exceed the 30 second timeout, you could create a lambda that executes the step function and then blocks as it polls for the result. Once it has the result, it can return it.

    It is a better idea to have the first call return immediately with the execution id, and then pass that id into a second call to retrieve the result, once it's finished.

    0 讨论(0)
  • 2020-12-14 19:33

    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

    0 讨论(0)
提交回复
热议问题