ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[AWS] CloudFormation Template Connect Github Version 2 Using CodeStar

2022-09-05 07:30:51  阅读:216  来源: 互联网

标签:GitHub AWS Effect CloudFormation Github Allow Action Type



Using CloudFormation template to create CodePipeline should be the best practice to maintain a pipeline. There are a lot of posts or videos online that can teach you how to do it, for example, this youtube video. The above tutorial is very good to teach you how to create a pipeline with yaml template file, the only thing is that it is still using Github Version 1 Connection which is not recommended by AWS anymore.


Recommended: The GitHub version 2 action uses Github app-based auth backed by a CodeStarSourceConnection for Bitbucket, GitHub, and GitHub Enterprise Server actions resource. It installs an AWS CodeStar Connections application into your GitHub organization so that you can manage access in GitHub.

Not recommended: The GitHub version 1 action uses OAuth tokens to authenticate with GitHub and uses a separate webhook to detect changes. This is no longer the recommended method.

The following is part of the CloudFormation template file that use CodeStar to create Github Version 2 Connection:


Parameters:
  GitHubOwner:
    Type: String
    AllowedPattern: '[A-Za-z0-9-]+'
    Default: <YourUserName>
  GitHubRepository:
    Type: String
    AllowedPattern: '[A-Za-z0-9-]+'
    Default: <YourRepo>
  GitHubBranch:
    Type: String
    AllowedPattern: '[A-Za-z0-9-]+'
    Default: master
Resources:
  CodePipelineServiceRole:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service: codepipeline.amazonaws.com
            Action: 'sts:AssumeRole'
      Policies:
        - PolicyName: root
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Sid: CodeStarConnectionPolicy
                Effect: Allow
                Action:
                  - 'codestar-connections:UseConnection'
                Resource: '*'
              - Sid: CloudWatchLogsPolicy
                Effect: Allow
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource:
                  - '*'
              - Sid: S3GetObjectPolicy
                Effect: Allow
                Action:
                  - 's3:GetObject'
                  - 's3:GetObjectVersion'
                Resource:
                  - '*'
              - Sid: S3PutObjectPolicy
                Effect: Allow
                Action:
                  - 's3:PutObject'
                Resource:
                  - '*'
              - Sid: S3BucketIdentity
                Effect: Allow
                Action:
                  - 's3:GetBucketAcl'
                  - 's3:GetBucketLocation'
                Resource:
                  - '*'
              - Sid: CodeBuildPolicy
                Action:
                  - 'codebuild:BatchGetBuilds'
                  - 'codebuild:StartBuild'
                Resource: '*'
                Effect: Allow
  CodePipelineArtifactStore:
    Type: 'AWS::S3::Bucket'
    DeletionPolicy: Delete
    Properties:
      VersioningConfiguration:
        Status: Enabled
  CodeStarConnection:
    Type: 'AWS::CodeStarConnections::Connection'
    Properties:
      ConnectionName: SupGitHubConnection
      ProviderType: GitHub
  CodePipeline:
    Type: 'AWS::CodePipeline::Pipeline'
    Properties:
      Name: !Ref 'AWS::StackName'
      RoleArn: !GetAtt 
        - CodePipelineServiceRole
        - Arn
      ArtifactStore:
        Type: S3
        Location: !Ref CodePipelineArtifactStore
      Stages:
        - Name: Source
          Actions:
            - Name: Source
              ActionTypeId:
                Category: Source
                Owner: AWS
                Version: 1
                Provider: CodeStarSourceConnection
              Configuration:
                ConnectionArn: !Ref CodeStarConnection
                BranchName: !Ref GitHubBranch
                FullRepositoryId: !Sub ${GitHubOwner}/${GitHubRepository}
              OutputArtifacts:
                - Name: SourceCode

References:

Complete GitHub CI/CD Pipeline with AWS CodeBuild and AWS CodePipeline using CloudFormation template

Using Cloudformation To Automate Build, Test, And Deploy With Codepipeline (part 3)

Update a GitHub version 1 source action to a GitHub version 2 source action

标签:GitHub,AWS,Effect,CloudFormation,Github,Allow,Action,Type
来源: https://www.cnblogs.com/grandyang/p/16656747.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有