【问题标题】:Deploying Serverless Transforms with AWS CodePipelines使用 AWS CodePipelines 部署无服务器转换
【发布时间】:2018-06-22 23:25:10
【问题描述】:

我根据this CloudFormation Template 设置了一个管道。

当我尝试部署使用 AWS SAM 的模板时,管道中出现错误

动作执行失败 CreateStack 不能与包含变换的模板一起使用。 (服务:AmazonCloudFormation;状态代码:400;错误代码:ValidationError;请求 ID:167007a4-7672-11e8-8f67-67e79ae9de20)

这主要是抱怨我的动作模式,

Configuration:
  ActionMode: CREATE_UPDATE

我可以使用 Pipeline Code Build stage,它使用 AWS CLI cloudformation 包 like this

version: 0.1
phases:
  install:
    commands:
      - npm install time
      - aws cloudformation package --template-file samTemplate.yaml --s3-bucket bucket-name 
                                   --output-template-file outputSamTemplate.yaml
artifacts:
  type: zip
  files:
    - samTemplate.yaml
    - outputSamTemplate.yaml

但我宁愿使用预先构建的东西。如何使用 CodePipelines 部署无服务器转换 Cloudformation 模板?我可以不使用 AWS CLI 打包和部署模板吗?

【问题讨论】:

    标签: amazon-web-services


    【解决方案1】:

    启动 CodeStar Python 项目给了我答案。值得注意的是,他们在部署阶段有两个 Cloudformation 操作,分别执行 CHANGE_SET_REPLACECHANGE_SET_EXECUTE

    从CF模板中去除无关信息,可以看到里面的动作结构,

    Resources:
      ...
      ProjectPipeline:
        Type: 'AWS::CodePipeline::Pipeline'
        Properties:
          Stages:
            -
              Name: Deploy
              Actions:
                - Name: GenerateChangeSet
                  ActionTypeId:
                    Provider: CloudFormation
                  Configuration:
                    ActionMode: CHANGE_SET_REPLACE
                - Name: ExecuteChangeSet
                  ActionTypeId:
                    Provider: CloudFormation
                  Configuration:
                    ActionMode: CHANGE_SET_EXECUTE
    

    以下是管道的完整模板资源。使用与上面相同的buildspec.yml,他们的 CodePipeline 模板看起来像,

    Resources:
      ...
      ProjectPipeline:
        Type: 'AWS::CodePipeline::Pipeline'
        Description: Creating a deployment pipeline for your project in AWS CodePipeline
        Properties:
          Name: pipeline-pipeline
          ArtifactStore:
            Type: S3
            Location:
              Ref: PipelineArtifacts
          RoleArn: !GetAtt [PipelineRole, Arn]
          Stages:
            -
              Name: Source
              Actions:
                -
                  Name: CheckoutSourceTemplate
                  ActionTypeId:
                    Category: Source
                    Owner: AWS
                    Version: 1
                    Provider: CodeCommit
                  Configuration:
                    PollForSourceChanges: True
                    RepositoryName: !GetAtt [PipelineRepo, Name]
                    BranchName: master
                  OutputArtifacts:
                    - Name: TemplateSource
                  RunOrder: 1
            -
              Name: Build
              Actions:
                - ActionTypeId:
                    Owner: AWS
                    Category: Build
                    Version: 1
                    Provider: CodeBuild
                  Configuration:
                    ProjectName: !Ref ProjectId
                  InputArtifacts:
                    - Name: TemplateSource
                  OutputArtifacts:
                    - Name: BuildTemplate
                  RunOrder: 1
            -
              Name: Deploy
              Actions:
                - Name: GenerateChangeSet
                  ActionTypeId:
                    Owner: AWS
                    Category: Deploy
                    Version: 1
                    Provider: CloudFormation
                  Configuration:
                    ActionMode: CHANGE_SET_REPLACE
                    RoleArn: !GetAtt [PipelineRole, Arn]
                    StackName: project-stack
                    Capabilities: CAPABILITY_IAM
                    TemplatePath: BuildTemplate::outputSamTemplate.yaml
                    ChangeSetName: pipeline-changeset
                  InputArtifacts:
                    - Name: BuildTemplate
                  RunOrder: 1
                - Name: ExecuteChangeSet
                  ActionTypeId:
                    Owner: AWS
                    Category: Deploy
                    Version: 1
                    Provider: CloudFormation
                  Configuration:
                    ActionMode: CHANGE_SET_EXECUTE
                    ChangeSetName: pipeline-changeset
                    StackName: project-stack
                  RunOrder: 2
    

    【讨论】:

    • 不知道为什么有人不赞成这个。为我节省了数小时的时间!
    猜你喜欢
    • 2020-08-20
    • 1970-01-01
    • 2020-01-01
    • 2019-08-04
    • 2019-01-02
    • 2021-05-12
    • 2018-08-09
    • 1970-01-01
    • 2018-06-14
    相关资源
    最近更新 更多