Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to call API Gateway resource from AWS Step function?

I have a step function which should call an API Gateway resource instead of a lambda. What is the syntax to do that ?

{"Comment": "A Hello World example of the Amazon States Language using a Pass state",
  "StartAt": "QueueProducts",
  "States": {
    "GetProductsFromDb": {
      "Type": "Task",
      "Resource":"some-lambda",
      "Next": "InvokeAPIGatewayWorkers"
    }
  },
 "InvokeAPIGatewayWorkers":{
    "Type": "Parallel",
    "Branches": [
     ....]
}
}

My question is, Is it possible to invoke an API Gateway in the Resource instead of "some-lamda"

like image 450
Hexy Avatar asked Feb 05 '23 18:02

Hexy


2 Answers

No, this is not possible.

You would have to use a Lambda function to make the call to API Gateway.

like image 141
Bob Kinney Avatar answered Feb 07 '23 08:02

Bob Kinney


Updates released on 17/11/2020 has made it possible to call API Gateway resource from Step Functions.

In above definition, instead of some-lambda if API Gateway resource is called then definition will look like this :

{
    "Comment": "An example of calling an API Gateway Resouce from one of the states of Step Function",
    "StartAt": "QueueProducts",
    "States": {
        "GetProductsFromDb": {
            "Type": "Task",
            "Resource": "arn:aws:states:::apigateway:invoke",
            "Parameters": {
                "ApiEndpoint": "{{api_gateway_id}}.execute-api.{{aws_region}}.amazonaws.com",
                "Method": "GET",
                "Headers": {
                    "session_id.$": "States.Array($.token)"
                },
                "Stage": "prod",
                "Path": "products",
                "QueryParameters": {
                    "category.$": "States.Array($.category)"
                }
            },
            "ResultSelector": {
                "ProductList.$": "$.ResponseBody"
            },
            "Next": "InvokeAPIGatewayWorkers"
        }
    },
    "InvokeAPIGatewayWorkers": {
        "Type": "Parallel",
        "Branches": []
    }
}

Documentation Note : Pay attention to not permitted headers

Example

like image 29
Jay Avatar answered Feb 07 '23 08:02

Jay