是否可以从 AWS Step 函数调用 API 网关资源?

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

我有一个步骤函数,它应该调用 API 网关资源而不是 lambda。这样做的语法是什么?

{"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": [
     ....]
}
}

我的问题是,是否可以在资源中调用 API 网关而不是 "some-lamda"

不,这不可能。

您必须使用 Lambda 函数来调用 API 网关。

2020 年 11 月 17 日发布的更新使得从 Step Functions 调用 API 网关资源成为可能。

在上面的定义中,如果调用 API 网关资源而不是 some-lambda,那么定义将如下所示:

{
    "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 注意:注意不允许headers

Example