【问题标题】:How to solve "Transform AWS::Include failed with: The specified S3 object's content should be valid Yaml/JSON" in SAM template如何解决 SAM 模板中的“Transform AWS::Include failed with: The specified S3 object's content should be valid Yaml/JSON”
【发布时间】:2021-07-14 15:29:54
【问题描述】:

我正在尝试将 OpenApi 规范包含到我的 AWS::Serverless::Api DefinitionBody 中,如下所示:

  MyApi:
    Type: "AWS::Serverless::Api"
    Properties:
      StageName: 'dev'
      Domain:
        DomainName: 'mydomain.com'
        CertificateArn: 'my-arn'
        EndpointConfiguration: REGIONAL
        Route53:
          HostedZoneId: 'HOSTEDZONEID'
        BasePath:
          - /api
      DefinitionBody:
        'Fn::Transform':
          Name: 'AWS::Include'
          Parameters:
            Location: !Sub 'open-api.yml'

我使用Fn:Transform 来确保我的速记符号得到评估。我在open-api.yml 中使用了一些 AWS API Gateway 扩展,如下所示:

        ...
        x-amazon-apigateway-integration:
            uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${FunctionName}/invocations'
            responses:
                default:
                    statusCode: "200"
            passthroughBehavior: "when_no_templates"
            httpMethod: "GET"
            type: "aws_proxy"

当我运行sam deploy --debug 时出现以下错误:

转换 AWS::Include 失败:指定的 S3 对象的内容应该是有效的 Yaml/JSON

【问题讨论】:

    标签: amazon-web-services yaml aws-sam aws-sam-cli


    【解决方案1】:

    您收到此错误是因为您在 YAML sn-ps 中使用了速记符号。在撰写本文时,不支持通过 AWS::Include 转换包含的 YAML sn-ps 简写符号。

    这意味着,而不是这个:

    uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${FunctionName}/invocations'
    

    你必须这样做:

    uri:
      Fn::Sub:
         - 'arn:aws:apigateway:${AWSRegion}:lambda:path/2015-03-31/functions/${FunctionArn}/invocations'
         - AWSRegion:
               Ref: AWS::Region
           AWSAccountId:
               Ref: AWS::AccountId
           FunctionArn:
               Fn::GetAtt: [UserServicesFunction, Arn]
    

    请参阅AWS::Include transform 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 2020-08-31
      • 2017-10-19
      • 2016-04-28
      • 1970-01-01
      • 2018-12-01
      相关资源
      最近更新 更多