Jag*_*row 12 amazon-web-services aws-lambda aws-api-gateway aws-step-functions
我按照教程创建和调用步骤函数
我在api的GET请求中得到了输出
{
"executionArn": "arn:aws:states:ap-northeast-1:123456789012:execution:HelloWorld:MyExecution",
"startDate": 1.486772644911E9
}
Run Code Online (Sandbox Code Playgroud)
但是,而不是上面的响应,我想要我的步骤函数输出,由下面的结束状态给出.
{
"name":"Hellow World"
}
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?
Ede*_*haw 28
请改用 Express Step Functions。这种类型的 Step Functions 可以同步调用。转到您的 API 网关,并在集成请求部分确保您具有 StartSyncExecution 操作:
之后,在同一页面的下方找到映射模板:
并为 application/json Content-Type 包含以下模板:
#set($input = $input.json('$'))
{
"input": "$util.escapeJavaScript($input)",
"stateMachineArn": "arn:aws:states:us-east-1:your_aws_account_id:stateMachine:your_step_machine_name"
}
Run Code Online (Sandbox Code Playgroud)
之后,返回方法执行并转到集成响应,然后转到映射模板部分:
并使用以下模板从您的 lambda 中获取自定义响应:
#set ($parsedPayload = $util.parseJson($input.json('$.output')))
$parsedPayload
Run Code Online (Sandbox Code Playgroud)
我的测试Step Function是这样的:
我的 Lambda 函数代码是:
部署您的 API Gateway 阶段。
现在,如果您转到 Postman 并发送带有任何 json 正文的 POST 请求,现在您将得到如下响应:
Mik*_*AWS 19
AWS Step Functions是异步的,不会立即返回其结果.API网关方法是同步的,最大超时为29秒.
要从步骤函数获取函数输出,您必须在API网关中添加第二个方法,该方法将使用DescribeExecution操作调用步骤函数.API网关客户端必须定期调用此方法(轮询),直到返回的状态不再是"RUNNING".
Poo*_*del 11
AWS Step Functions 的新同步 Express 工作流就是答案:https : //aws.amazon.com/blogs/compute/new-synchronous-express-workflows-for-aws-step-functions/
Amazon API Gateway 现在支持与 HTTP API 的 Step Functions StartSyncExecution 集成:https : //aws.amazon.com/about-aws/whats-new/2020/12/amazon-api-gateway-supports-integration-with-step-函数-startsyncexecution-http-apis/
首先,step 函数是异步执行的,API Gateway 只能调用 step 函数(启动流)。
如果您正在等待来自 Web 应用程序的步进函数调用的结果,您可以为此使用 AWS IOT WebSockets。步骤如下。
有关使用 AWS IOT 的 WebSockets 的更多详细信息,请参阅使用 websockets 在浏览器中接收 AWS IoT 消息的中型文章。
| 归档时间: |
|
| 查看次数: |
3886 次 |
| 最近记录: |