user3002273
user3002273

Reputation:

Deploying Serverless Transforms with AWS CodePipelines

I have a pipeline set up per this CloudFormation Template.

When I try to deploy a template that is using AWS SAM, I get an error in the pipeline

Action execution failed CreateStack cannot be used with templates containing Transforms. (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 167007a4-7672-11e8-8f67-67e79ae9de20)

which is notabily complain about my Action Mode,

Configuration:
  ActionMode: CREATE_UPDATE

I can use a Pipeline Code Build stage that uses AWS CLI cloudformation package 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

But I would rather use something prebuilt. How do I deploy Serverless Transform Cloudformation Templates with CodePipelines? Can I do it without using the AWS CLI to package and deploy the template?

Upvotes: 0

Views: 360

Answers (1)

user3002273
user3002273

Reputation:

Spinning up a CodeStar Python project gave me the answer. They notably have two Cloudformation actions in their deploy stage that do CHANGE_SET_REPLACE and CHANGE_SET_EXECUTE.

Removing extraneous info from the CF template, you can see the structure of the actions in,

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

Below is the full template resource for the pipeline. Using the same buildspec.yml as above, their CodePipeline template looks like,

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

Upvotes: 1

Related Questions