带有步进功能的AWS API Gateway [英] AWS API Gateway with Step Function

查看:99
本文介绍了带有步进功能的AWS API Gateway的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个将AWS API Gateway与Step Function集成的示例.我已经阅读了本教程使用以下方法创建步进函数API API网关,但该教程需要我以

I want a sample to integrate AWS API Gateway with Step Function. I have read this tutorial Creating a Step Functions API Using API Gateway but that tutorial needs me to send request in format of

{    
"input": "{}",    
"name": "PostmanExecution",    
"stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:Custom" 
}

我要发送常规请求,并仅在API网关中配置此 stateMachineArn ,以便客户端无需发送此请求.

I want to send normal request and configure this stateMachineArn in API Gateway only, so that clients dont need to send this.

推荐答案

创建您的API网关资源和方法.然后在方法执行"设置的集成请求"中,使用以下设置:

Create your API Gateway resource and method. Then in the "Method Execution" settings, in the Integration Request, use these settings:

  • 集成类型:AWS服务
  • AWS地区:您所在的地区
  • AWS服务:步骤功能
  • AWS子域:您的子域(如果有)-我将其留空
  • HTTP方法:POST
  • 操作:StartExecution
  • 执行角色:需要是具有StepFunction启动执行策略的角色,例如arn:aws:iam :: aws:policy/AWSStepFunctionsFullAccess
  • 凭据缓存:我将其保留为默认
  • 内容处理:直通
  • Integration type: AWS Service
  • AWS Region: your region
  • AWS Service: Step Functions
  • AWS Subdomain: your subdomain if you have one - I left it blank
  • HTTP method: POST
  • Action: StartExecution
  • Execution role: needs to be a role with StepFunction start execute policy, such as arn:aws:iam::aws:policy/AWSStepFunctionsFullAccess
  • Credentials cache: I left this as default
  • Content Handling: Passthrough

然后是魔法.进一步,在人体贴图模板"下:

Then the magic. Futher down, under Body Mapping Templates:

  • 请求正文通过:从不
  • 添加映射模板:application/json

在模板文本框中进一步输入

Futher down in the template text box:

#set($input = $input.json('$'))
{
   "input": "$util.escapeJavaScript($input)",
   "stateMachineArn": "arn:aws:states:eu-west-1:123456789012:stateMachine:yourStepFunctionName"
}

这会将发布到API网关的json有效负载传递到Step Function.

This will pass the json payload posted to API Gateway through to the Step Function.

省略执行名称,以便对API Gateway的每次调用都会创建一个新的执行.

Omit the execution name so that each call to API Gateway creates a new execution.

这篇关于带有步进功能的AWS API Gateway的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆