Setting up CodePipeline template to deploy CloudFo

2019-03-02 17:25发布

From a CloudFormation template, you can deploy CodeCommit and CodePipeline. From this announcement,

You can now choose AWS CloudFormation as a deployment action in your release workflows built using AWS CodePipeline.

I've worked out most of the Cloudformation Template, but I can't figure out the stages.

Resources:
  PipelineRepo:
    Type: AWS::CodeCommit::Repository
    Properties:
      RepositoryName: pipeline
      RepositoryDescription: Pipeline setup repo

  PipelineArtifacts:
    Type: AWS::S3::Bucket

  PipelineRole:
    Type: AWS::IAM::Role

  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      Name: pipeline-pipeline
      ArtifactStore:
        Type: S3
        Location:
          Ref: PipelineArtifacts
      RoleArn:
        Ref: PipelineRole
      Stages:
        ... STAGES ...

How do you set up the stages to track CodeCommit and then deploy a CloudFormation template from a file in the repo?

1条回答
神经病院院长
2楼-- · 2019-03-02 17:47

Offical Documentation:

The IAM Role is broken too. Below is a functioning stack. For various types of CF deployments, see the CF Configuration Properties. A helpful sample CF stack is here.

Resources:
  PipelineRepo:
    Type: AWS::CodeCommit::Repository
    Properties:
      RepositoryName: pipeline
      RepositoryDescription: Pipeline setup repo

  PipelineArtifacts:
    Type: AWS::S3::Bucket

  PipelineRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - codepipeline.amazonaws.com
                - cloudformation.amazonaws.com
            Action: sts:AssumeRole
      Policies:
        - PolicyName: CloudPipelinePolicy
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action: "cloudformation:*"
                Resource: "*"
              - Effect: Allow
                Action: "codecommit:*"
                Resource: "*"
              - Effect: Allow
                Action: "s3:*"
                Resource: "*"
              - Effect: Allow
                Action:
                  - iam:PassRole
                Resource: "*"

  Pipeline:
    Type: AWS::CodePipeline::Pipeline
    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: Deploy
          Actions:
            -
              Name: CreateStack
              ActionTypeId:
                Category: Deploy
                Owner: AWS
                Provider: CloudFormation
                Version: 1
              InputArtifacts:
                - Name: TemplateSource
              Configuration:
                ActionMode: CREATE_UPDATE
                RoleArn: !GetAtt [PipelineRole, Arn]
                StackName: pipeline
                Capabilities: CAPABILITY_IAM
                TemplatePath: TemplateSource::template.yml
              RunOrder: 1
查看更多
登录 后发表回答