使用无服务器框架部署时,从 Codebuild 构建规范的第一行中删除了新行

New line stripped from first line of Codebuild build spec when deploying with Serverless Framework

我正在使用无服务器框架为 AWS codebuild 部署构建规范。当我部署时,构建规范中没有第一行之后的新行。此资源之前部署没有问题,我看不到我为破坏它所做的任何事情。这是我的问题还是 Serverless/CloudFormation 的错误?

下面是从 AWS 控制台复制的 CloudFormation 模板和生成的构建规范。

    Resources:
      CodeBuild:
        Type: 'AWS::CodeBuild::Project'
        Properties:
          Name: sls-retrobase-frontend-CodeBuild-${opt:stage}
          ServiceRole: !GetAtt CodeBuildRole.Arn
          Artifacts:
            Type: CODEPIPELINE
            Name: sls-retrobase
          Environment:
            Type: LINUX_CONTAINER    
            ComputeType: BUILD_GENERAL1_SMALL
            Image: "aws/codebuild/amazonlinux2-x86_64-standard:3.0"
          Source:
            Type: CODEPIPELINE
            BuildSpec: !Sub
              - >
                  version: 0.2
                  phases:
                    pre_build:
                      commands:
                        - echo List directory files...
                        - ls
                        - echo Installing source NPM dependencies...
                        - npm install
                    build:
                      commands:
                        - echo List active directory...
                        - ls
                        - echo Inserting Api Url into config.json from environment 
                        - node makeConfig.js ${apiUrl} ${auth0Audience} ${auth0Domain} ${auth0ClientId}
                        - echo Build started on `date`
                        - npm run build
                    post_build:
                      commands:
                        - echo List build directory...
                        - ls ./build
                        - aws s3 cp --recursive --acl public-read ./build s3://${Website}
                  artifacts:
                    files:
                      - '**/*'
              - apiUrl: !Join ['', [ "https://", !Ref QueryRestApi, ".execute-api.us-east-1.amazonaws.com/${opt:stage}/sls-retrobase-${opt:stage}"]]
                websiteUrl: !GetAtt Website.WebsiteURL
                auth0Audience: '***'
                auth0Domain: '***'
                auth0ClientId: '***'

构建规范:

    version: 0.2 phases:
    pre_build:
        commands:
        - echo List directory files...
        - ls
        - echo Installing source NPM dependencies...
        - npm install
    build:
        commands:
        - echo List active directory...
        - ls
        - echo Inserting Api Url into config.json from environment 
        - node makeConfig.js https://h0suk54yw0.execute-api.us-east-1.amazonaws.com/test/sls-retrobase-test https://sls-retrobase https://dev-y33gimcf.eu.auth0.com/ Xn6SDc43vE8P0sQHkVLtiBSBVFT5rJMU
        - echo Build started on `date`
        - npm run build
    post_build:
        commands:
        - echo List build directory...
        - ls ./build
        - aws s3 cp --recursive --acl public-read ./build s3://serverless-retrobase-resources-test-website-7cvhqlgbkfj7
    artifacts:
    files:
        - '**/*'

这可能是因为您使用了>。请将其更改为 |:

            BuildSpec: !Sub
              - |
                version: 0.2
                phases:

或者,在使用 > 时修复您的空格。 > 和您的代码不一致。