Leonard Saers
Leonard Saers

Reputation: 663

Is it possible to make synchronous calls to AWS Step Function through AWS API Gateway?

Is there any way to make synchronous request to a AWS Step Function through an AWS API Gateway?

Or can AWS State Machine only be used to start asynchronous jobs?

A setup that starts an asynchronous job may include the following:

  ApiGatewayMethodStartExecution:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      ...
      Integration:
        Type: AWS
        Uri: arn:aws:apigateway:eu-north-1:states:action/StartExecution
        RequestTemplates: 
          application/json: !Sub 
            - |
              ....
            - StateMachineArn: !Ref AStateMachine

  ApiGatewayMethodGetResult:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      ...
      Integration:
        Type: AWS
        Uri: arn:aws:apigateway:eu-north-1:states:action/DescribeExecution
        RequestTemplates: 
          application/json: !Sub 
            - |
              ....
            - StateMachineArn: !Ref AStateMachine

  AStateMachine:
    Type: 'AWS::StepFunctions::StateMachine'
    ...

Upvotes: 1

Views: 516

Answers (2)

Adam
Adam

Reputation: 4178

No, not if you call the step function directly. However, you can mimic this behavior by wrapping the step function in a AWS Lambda. Configure an endpoint as a Lambda proxy. Have the AWS Lambda trigger an/the AWS Step Function, and have the AWS Lambda monitor the step function to determine when its complete. Once complete, have the AWS Lambda return whatever, which will be sent to the endpoint's caller. All that machinery needs to happen quickly because you have a hard 30s timeout on the API Gateway.

I have lots of situations where a step function is triggered by an endpoint call. I usually have the endpoint call a Lambda that then starts the step function returning once the step function starts. I then provide a second endpoint that callers can consume to find out the status of whatever that step function was doing.

Upvotes: 2

Prathap Reddy
Prathap Reddy

Reputation: 1749

AWS API gateway will be having ~ 30 seconds timeout as per quota limits for any integrations.

Hence they are only meant for starting asynchronous jobs IMHO.

Upvotes: 1

Related Questions