如何通过CloudFormation集成具有步骤功能的Api网关 [英] How to integrate, by CloudFormation, Api Gateway with Step Functions
问题描述
我正在为所使用的平台创建CloudFormation模板。我需要集成Api Gateway和Step Functions,以使我的其中一个step函数可以通过调用Api Gateway Method来执行。
I'm creating a CloudFormation template for the platform I'm working on. I need to integrate Api Gateway and Step Functions, to make one of my step functions be executed by a call to a Api Gateway Method.
我没有找到任何文档在此。我很难找到Integration / Uri,应该是
I'm not finding any documentation on this. I struggled to find the Integration/Uri, that should be
arn:aws:apigateway:${region}:states:action/StartExecution
但现在我不确定在RequestTemplates中写什么。我想我实际上可以将其保留为空,以使其像代理一样工作,但是如果您能给我进一步的信息,我将不胜感激。
but now I'm not sure on what to write in my RequestTemplates. I suppose that I could actually leave it empty, to make it act like a proxy, but I would really appreciate if you could give me any further information.
谢谢
推荐答案
很显然,我无法将RequestTemplates留空,因为它包含有关要调用StateMachine的信息。 URI本身不包含该信息,而只是指向State Machine API的入口点。
Obviously I could not leave RequestTemplates empty because it contains the information on what StateMachine is to be called. The URI itself doesn't contain that information, but it just points to the State Machine API's entrypoint.
正确的方法来自此文档的页面。
状态机API公开了各种方法。执行步骤功能的一个是 StartExecution。
State Machine APIs expose various methods. The one to execute the Step Function is "StartExecution". To that entrypoint a body formed like this has to be passed
{
"input": "string",
"name": "string",
"stateMachineArn": "string"
}
因此,在云形成中:
"Integration": {
"Type": "AWS",
"IntegrationHttpMethod": "POST",
"Uri": {
"Fn::Join": ["",
["arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":states:action/StartExecution"]]
},
"RequestTemplates": {
"application/json": {
"Fn::Sub": ["{\"input\": \"$util.escapeJavaScript($input.json('$'))\",\"stateMachineArn\": \"${arn}\"}",
{
"arn": {
"Ref": "[StepMachineResourceName]"
}
}]
}
}
}
这篇关于如何通过CloudFormation集成具有步骤功能的Api网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!