Amazon cloudformation AWS云层形成。从API网关v1同步调用Step函数

Amazon cloudformation AWS云层形成。从API网关v1同步调用Step函数,amazon-cloudformation,aws-api-gateway,aws-step-functions,Amazon Cloudformation,Aws Api Gateway,Aws Step Functions,我试图通过API网关同步执行AWS步骤函数。问题是,对于API Gateway V1,我必须使用OpenAPI语法(即swagger)来指定integrationSubtype参数,但有些东西不起作用。以下是我正在使用的CloudFormation模板: { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "restApiNam

我试图通过API网关同步执行AWS步骤函数。问题是,对于API Gateway V1,我必须使用OpenAPI语法(即swagger)来指定
integrationSubtype
参数,但有些东西不起作用。以下是我正在使用的CloudFormation模板:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "restApiName": {
            "Type": "String",
            "Default": "stepApi"
        }
    },
    "Resources": {
        "MyStepFunction": {
            "Type": "AWS::StepFunctions::StateMachine",
            "Properties": {
                "StateMachineName": "HelloWorld-StateMachine",
                "StateMachineType": "EXPRESS",
                "DefinitionString": "{\"Comment\": \"A Hello World example of the Amazon States Language using Pass states\", \"StartAt\": \"Hello\", \"States\": {\"Hello\": { \"Type\": \"Pass\", \"Result\": \"Hello\", \"Next\": \"World\" }, \"World\": { \"Type\": \"Pass\", \"Result\": \"World\", \"End\": true } } }",
                "RoleArn": {
                    "Fn::GetAtt": [
                        "StepFunctionRole",
                        "Arn"
                    ]
                }
            }
        },
        "StepFuncGateway": {
            "Type": "AWS::ApiGateway::RestApi",
            "Properties": {
                "Name": {
                    "Ref": "restApiName"
                },
                "Body": {
                    "openapi": "3.0.1",
                    "info": {
                        "title": "processFormExample",
                        "version": "2020-11-06 15:32:29UTC"
                    },
                    "paths": {
                        "/step": {
                            "post": { 
                                "responses": {
                                    "200": {
                                      "description": "Pet updated.",
                                      "content": {
                                        "application/json": {},
                                        "application/xml": {}
                                      }
                                    },
                                    "405": {
                                        "description": "Method Not Allowed",
                                        "content": {
                                            "application/json": {},
                                            "application/xml": {}
                                        }
                                    }
                                },
                                "parameters": [
                                ],
                                "x-amazon-apigateway-integration": {
                                    "integrationSubtype": "StepFunctions-StartSyncExecution",
                                    "credentials": {
                                        "Fn::GetAtt": [
                                            "APIGatewayRole", 
                                            "Arn"
                                        ]
                                    },
                                    "RequestTemplates": {
                                        "application/json": {
                                            "Fn::Join": [
                                                "",
                                                [
                                                    "#set( $body = $util.escapeJavaScript($input.json('$')) ) \n\n{\"input\": \"$body\",\"name\": \"$context.requestId\",\"stateMachineArn\":\"",
                                                    {
                                                        "Ref": "MyStepFunction"
                                                    },
                                                    "\"}"
                                                ]
                                            ]
                                        }
                                    },
                                    "httpMethod": "POST",
                                    "payloadFormatVersion": "1.0",
                                    "passthroughBehavior": "NEVER",
                                    "type": "AWS_PROXY",
                                    "connectionType": "INTERNET"
                                }
                            }
                        }
                    },
                    "x-amazon-apigateway-cors": {
                        "allowMethods": [
                            "*"
                        ],
                        "maxAge": 0,
                        "allowCredentials": false,
                        "allowOrigins": [
                            "*"
                        ]
                    }
                }
            },
            "DependsOn": [
                "APIGatewayRole",
                "MyStepFunction"
            ]
        },
        "APIGatewayRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Effect": "Allow",
                            "Principal": {
                                "Service": [
                                    "apigateway.amazonaws.com"
                                ]
                            },
                            "Action": "sts:AssumeRole"
                        }
                    ]
                },
                "Path": "/",
                "ManagedPolicyArns": [
                    "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs",
                    "arn:aws:iam::aws:policy/AWSStepFunctionsFullAccess"
                ]
            }
        },
        "StepFunctionRole": {
            "Type": "AWS::IAM::Role",
            "Properties": {
                "AssumeRolePolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Sid": "",
                            "Effect": "Allow",
                            "Principal": {
                                "Service": "states.amazonaws.com"
                            },
                            "Action": "sts:AssumeRole"
                        }
                    ]
                },
                "Path": "/",
                "ManagedPolicyArns": [
                    "arn:aws:iam::aws:policy/service-role/AWSLambdaRole"
                ]
            }
        }
    },
    "Outputs": {
        "HelloWorldApi": {
            "Description": "Sync WF API endpoint",
            "Value": {
                "Fn::Sub": "https://${StepFuncGateway}.execute-api.${AWS::Region}.amazonaws.com/step"
            }
        }
    }
}
我看到的错误如下:

导入期间发现错误:无法将集成放在的“POST”上 路径“/step”处的资源:指定的集成URI无效(服务: AmazonApiGateway;状态代码:400;错误代码:BadRequestException; 请求ID:0c74acf9-147f-4561-9f4f-e457096c5533;代理:null)

我没有主意了。请帮我修一下

更新:

我不得不将以下代码添加到
x-amazon-apigateway-integration
部分,并将类型更改为
AWS

"uri": {
    "Fn::Join": [
        "",
        [
            "arn:aws:apigateway:",
            {
                "Ref": "AWS::Region"
            },
            ":states:action/StartSyncExecution"
        ]
    ]
},

我必须解决的另一个问题是
RequestTemplates
,它应该以小写字母
r
开头。在提到更改后,堆栈已正确部署,但现在我有节流问题要解决。

x-amazon-apigateway-integration
缺少
uri
属性

从中,URI属性定义为:

后端的端点URI。对于aws类型的集成, 这是一个ARN值。对于HTTP集成,这是 HTTP端点,包括https或HTTP方案

例如:

"x-amazon-apigateway-integration": {
    "type": "AWS_PROXY",
    "httpMethod": "POST",
    "uri": "http://petstore.execute-api.us-west-1.amazonaws.com/petstore/pets",
    "payloadFormatVersion": 1.0,
    "otherPropterties": "go here"
}
Amazon提供了有关URI定义的附加信息。(为方便起见复印)

对于HTTP或HTTP_代理集成,URI必须是RFC-3986规范规定的完整格式、编码的HTTP(S)URL,用于标准集成(其中connectionType不是VPC_链接)或专用集成(其中connectionType是VPC_链接)。对于专用HTTP集成,URI不用于路由

对于AWS或AWS|U代理集成,URI的形式为
arn:AWS:apigateway:{region}:{subdomain.service | service}:path | action/{service_api}
。这里,
{Region}
是API网关区域(例如,us-east-1)
{service}
是综合AWS服务的名称(例如s3);而
{subdomain}
是特定AWS服务支持的指定子域,用于快速主机名查找。操作可用于基于AWS服务操作的API,使用
action={name}&{p1}={v1}&p2={v2}…
查询字符串。随后的
{service\u api}
引用了受支持的操作
{name}
以及任何必需的输入参数。或者,路径可用于基于AWS服务路径的API。随后的
service\u api
是指AWS服务资源的路径,包括集成AWS服务的区域(如果适用)。例如,为了与
GetObject
的s3api集成,uri可以是
arn:aws:apigateway:us-west-2:S3:action/GetObject&Bucket={Bucket}&Key={Key}
arn:aws:apigateway:us-west-2:S3:path/{Bucket}/{Key}


我尝试用以下格式添加它:
“Uri”:{“Fn::Join”:[“”,[“arn:aws:apigateway:”,{“Ref”:“aws::Region”},::states:action/StartSyncExecution”]},
,但它也不起作用。你能给我指一个我可以阅读URI格式的资源吗?在答案中添加了额外的信息。