【问题标题】:How can i call AWS Step Functions by API Gateway? [closed]我如何通过 API Gateway 调用 AWS Step Functions? [关闭]
【发布时间】:2017-05-02 11:56:26
【问题描述】:

我想知道如何让 API Gateway 调用 Step Function 并执行它。

【问题讨论】:

标签: amazon-web-services aws-api-gateway aws-step-functions


【解决方案1】:

API Gateway 目前添加了对 Step Functions 的支持。现在您可以通过 API Gateway 控制台创建 AWS 服务集成。

  • 集成类型:AWS 服务
  • AWS 服务:Step Functions
  • HTTP 方法:POST
  • 动作类型:使用动作名称
  • 操作:开始执行
  • 执行角色:开始执行的角色
  • 标题:

    X-Amz-Target -> 'AWSStepFunctions.StartExecution'
    内容类型 -> 'application/x-amz-json-1.0'

  • 正文映射模板/请求负载:

    { “输入”:“字符串”, “名称”:“字符串”, “stateMachineArn”:“字符串” }

【讨论】:

  • 您对这个错误有任何线索吗? { "__type": "com.amazonaws.swf.service.v2.model#InvalidArn", "message": "Invalid Arn: 'Invalid ARN prefix: string'" }
  • 我猜你在 stateMachineArn 中定义的 ARN 不是无效的。你能验证一下吗?
  • 嗯,arn 没问题,当我在 api 网关控制台中测试它时,通过 post 发送相同的 json 一切正常,但在邮递员中说错误,在我的应用程序中,有什么想法吗?
  • 能否启用 CloudWatch Log 进行调试?我想知道您的请求中没有正确的 accpet/content-type 标头。
  • 当然,我有从邮递员到 API Gateway application/json 和 API Gateway 集成请求 X-Amz-Target -> 'AWSStepFunctions.StartExecution' Content-Type -> 'application/x-amz- json-1.0' 有什么线索吗? @卡
【解决方案2】:

您可以使用Integration type: AWS Service 创建一个 API Gateway Endpoint,并将其设置为调用所需的 Step Function。

如果您想使用 API Gateway 来控制 Step Functions 端点的公开,您可以使用仅授予访问权限的策略创建一个新的 IAM 用户(仅限编程访问)到这个端点,例如:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "execute-api:Invoke"           
      ],
      "Resource": [
        "arn:aws:execute-api:us-east-1:my-aws-account-id:my-api-id/my-stage/GET/my-resource-path"
      ]
    }
  ]
}  

【讨论】:

  • 这种方法对我有用。你能解释一下否决票吗?如果您认为这篇文章可以改进,请考虑添加评论。
  • 您如何配置 HTTP 集成以调用 Step Function API? AFAIK,这不起作用,因为请求不会使用 SigV4 签名。如果您将集成类型更改为 AWS,这将是正确答案。
  • 感谢 Ryan,编辑了我的答案。这是个好消息!在撰写本文时,我们没有将 Step Functions 与 API Gateway 直接集成的选项,应该这样做。
【解决方案3】:

我认为您可以使用 API Gateway 代理集成到 AWS 服务。看:https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings-console.html

【讨论】:

    【解决方案4】:

    考虑创建一个支持 APIGw 端点的 AWS Lambda 函数,并让它通过代码调用 AWS StepFunctions。我们使用这种方法是因为我们的用例允许 API 端点参数指示我们需要执行几个 StepFunction 中的哪一个。

    诚然,这是“更多代码”;我们希望 AWS 详细说明 StepFunction,以便它们可以由整个 AWS 资源事件主机触发。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-12
      • 2020-09-05
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 2020-05-12
      • 2021-05-16
      相关资源
      最近更新 更多