Aws lambda AWS SAM/Cloudformation“;路径'处的集成格式不正确;错误

Aws lambda AWS SAM/Cloudformation“;路径'处的集成格式不正确;错误,aws-lambda,aws-api-gateway,amazon-cloudformation,aws-sam,Aws Lambda,Aws Api Gateway,Amazon Cloudformation,Aws Sam,我在尝试部署lambda和API网关配置时遇到以下错误 “路径/profile/v1处的集成格式不正确。(服务: AmazonApiGateway;状态代码:400;错误代码:BadRequestException“ 什么会导致此错误以及如何解决此错误 获得了与AWS支持合作的最终工作设置,你们可能都感兴趣: 当我们在外部swagger模板中引用cloudformation资源详细信息时,我们没有获得资源详细信息,因此收到上述错误。例如:“Fn::Sub:arn:aws:apigateway:

我在尝试部署lambda和API网关配置时遇到以下错误

“路径/profile/v1处的集成格式不正确。(服务: AmazonApiGateway;状态代码:400;错误代码:BadRequestException“

什么会导致此错误以及如何解决此错误



获得了与AWS支持合作的最终工作设置,你们可能都感兴趣:

当我们在外部swagger模板中引用cloudformation资源详细信息时,我们没有获得资源详细信息,因此收到上述错误。例如:“Fn::Sub:arn:aws:apigateway:${aws::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.arn}/invocations当您尝试使用资源“LambdaFunction.Arn”(即CloudFormation资源)在swagger定义中创建API网关集成端点uri时,“将不起作用。”

为了解决这些问题,我在cloudformation模板中做了以下更改:

为了引用cloudformation模板中的swagger文件,我将swagger模板上传到s3 bucket中,然后使用以下定义。我使用:

AWS::Include转换允许您在Amazon S3 bucket中创建对转换片段的引用。它允许在外部swagger文件中引用cloudformation资源详细信息。有关“AWS::Include”转换的更多详细信息,请参阅[1]中的文档

然后,我检查了swagger模板,发现您正在使用速记符号来指定集成uri。但是,“AWS::Include”目前不支持使用文档[2]中提到的YAML片段速记符号。因此,我使用了内在函数“Fn::Sub”并且能够在swagger模板中引用所需的云形成参数


以前的定义:
新定义: 参考资料:

  • 我也有同样的错误,你已经弄明白了吗?
    swagger: '2.0'
    info:
      version: v1
      title: ProfileAPI
    paths:
      "/profile/v1":
        get:
          tags:
          - Values
          operationId: ProfileV1Get
          consumes: []
          produces:
          - text/plain
          - application/json
          - text/json
          parameters: []
          responses:
            '200':
              description: Success
              schema:
                type: array
                items:
                  type: string
          x-amazon-apigateway-integration:
            httpMethod: post
            type: aws_proxy
            uri:
              Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ProfileFunction.Arn}/invocations
    definitions: {}
    
        ZazzoAPI:
            Type: AWS::Serverless::Api
            Properties:
                StageName: Prod
                Variables:
                    LambdaFunctionName: !Ref LambdaFunction
                #Configure API settings and options
                MethodSettings: [{
                    LoggingLevel: "INFO",
                    MetricsEnabled: True ,
                    HttpMethod: "GET",
                    ResourcePath: "/"
                }]
                DefinitionBody:
                    'Fn::Transform':
                      Name: 'AWS::Include'
                      Parameters:
                            Location: "s3://s3.code-deploy/swagger_SAM.yaml"
    
    uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations”
    
    uri: 
          Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations"