|
| 1 | +AWSTemplateFormatVersion: '2010-09-09' |
| 2 | +Transform: 'AWS::Serverless-2016-10-31' |
| 3 | + |
| 4 | +Resources: |
| 5 | + CodePipelineServerlessRepoPublishApp: |
| 6 | + Type: 'AWS::Serverless::Application' |
| 7 | + Properties: |
| 8 | + Location: |
| 9 | + ApplicationId: ${PUBLISH_APP_ARN} |
| 10 | + SemanticVersion: 0.0.1 |
| 11 | + |
| 12 | + Pipeline: |
| 13 | + Type: AWS::CodePipeline::Pipeline |
| 14 | + Properties: |
| 15 | + ArtifactStore: |
| 16 | + Type: S3 |
| 17 | + Location: |
| 18 | + Ref: ArtifactStoreBucket |
| 19 | + RoleArn: !GetAtt PipelineRole.Arn |
| 20 | + Stages: |
| 21 | + - Name: Source |
| 22 | + Actions: |
| 23 | + - Name: Source |
| 24 | + ActionTypeId: |
| 25 | + Category: Source |
| 26 | + Owner: AWS |
| 27 | + Provider: S3 |
| 28 | + Version: '1' |
| 29 | + Configuration: |
| 30 | + S3Bucket: !Ref SourceBucket |
| 31 | + S3ObjectKey: testapp.zip |
| 32 | + OutputArtifacts: |
| 33 | + - Name: SourceArtifact |
| 34 | + RunOrder: '1' |
| 35 | + - Name: Build |
| 36 | + Actions: |
| 37 | + - Name: Build |
| 38 | + ActionTypeId: |
| 39 | + Category: Build |
| 40 | + Owner: AWS |
| 41 | + Provider: CodeBuild |
| 42 | + Version: '1' |
| 43 | + Configuration: |
| 44 | + ProjectName: !Ref CICodeBuildProject |
| 45 | + InputArtifacts: |
| 46 | + - Name: SourceArtifact |
| 47 | + OutputArtifacts: |
| 48 | + - Name: BuildArtifact |
| 49 | + RunOrder: '1' |
| 50 | + - Name: Deploy |
| 51 | + Actions: |
| 52 | + - Name: DeployToServerlessRepo |
| 53 | + ActionTypeId: |
| 54 | + Category: Invoke |
| 55 | + Owner: AWS |
| 56 | + Provider: Lambda |
| 57 | + Version: '1' |
| 58 | + Configuration: |
| 59 | + FunctionName: !GetAtt CodePipelineServerlessRepoPublishApp.Outputs.ServerlessRepoPublishFunctionName |
| 60 | + InputArtifacts: |
| 61 | + - Name: BuildArtifact |
| 62 | + RunOrder: '1' |
| 63 | + |
| 64 | + ArtifactStoreBucket: |
| 65 | + Type: AWS::S3::Bucket |
| 66 | + Properties: |
| 67 | + VersioningConfiguration: |
| 68 | + Status: Enabled |
| 69 | + |
| 70 | + ArtifactStoreBucketPolicy: |
| 71 | + Type: AWS::S3::BucketPolicy |
| 72 | + Properties: |
| 73 | + Bucket: |
| 74 | + Ref: ArtifactStoreBucket |
| 75 | + PolicyDocument: |
| 76 | + Version: '2012-10-17' |
| 77 | + Statement: |
| 78 | + - Action: ['s3:GetObject'] |
| 79 | + Effect: Allow |
| 80 | + Principal: |
| 81 | + Service: 'serverlessrepo.amazonaws.com' |
| 82 | + Resource: |
| 83 | + - !Sub ${ArtifactStoreBucket.Arn}/* |
| 84 | + |
| 85 | + SourceBucket: |
| 86 | + Type: AWS::S3::Bucket |
| 87 | + Properties: |
| 88 | + VersioningConfiguration: |
| 89 | + Status: Enabled |
| 90 | + |
| 91 | + PipelineRole: |
| 92 | + Type: AWS::IAM::Role |
| 93 | + Properties: |
| 94 | + AssumeRolePolicyDocument: |
| 95 | + Statement: |
| 96 | + - Action: ['sts:AssumeRole'] |
| 97 | + Effect: Allow |
| 98 | + Principal: |
| 99 | + Service: [codepipeline.amazonaws.com] |
| 100 | + Version: '2012-10-17' |
| 101 | + Path: / |
| 102 | + Policies: |
| 103 | + - PolicyName: CodePipelineAccess |
| 104 | + PolicyDocument: |
| 105 | + Version: '2012-10-17' |
| 106 | + Statement: |
| 107 | + - Action: |
| 108 | + - 'iam:PassRole' |
| 109 | + Effect: Allow |
| 110 | + Resource: '*' |
| 111 | + - Effect: Allow |
| 112 | + Action: |
| 113 | + - "codebuild:BatchGetBuilds" |
| 114 | + - "codebuild:StartBuild" |
| 115 | + Resource: |
| 116 | + - !GetAtt CICodeBuildProject.Arn |
| 117 | + - Effect: Allow |
| 118 | + Action: |
| 119 | + - "lambda:InvokeFunction" |
| 120 | + Resource: |
| 121 | + - !GetAtt CodePipelineServerlessRepoPublishApp.Outputs.ServerlessRepoPublishFunctionArn |
| 122 | + - Action: |
| 123 | + - 's3:ListBucket' |
| 124 | + - 's3:GetBucketVersioning' |
| 125 | + Effect: Allow |
| 126 | + Resource: |
| 127 | + - !Sub ${ArtifactStoreBucket.Arn} |
| 128 | + - !Sub ${SourceBucket.Arn} |
| 129 | + - Action: |
| 130 | + - 's3:PutObject' |
| 131 | + - 's3:GetObject' |
| 132 | + - 's3:GetObjectVersion' |
| 133 | + Effect: Allow |
| 134 | + Resource: |
| 135 | + - !Sub ${ArtifactStoreBucket.Arn}/* |
| 136 | + - !Sub ${SourceBucket.Arn}/* |
| 137 | + |
| 138 | + CICodeBuildProject: |
| 139 | + Type: AWS::CodeBuild::Project |
| 140 | + Properties: |
| 141 | + ServiceRole: !GetAtt CICodeBuildRole.Arn |
| 142 | + Source: |
| 143 | + Type: CODEPIPELINE |
| 144 | + Artifacts: |
| 145 | + Type: CODEPIPELINE |
| 146 | + Environment: |
| 147 | + ComputeType: BUILD_GENERAL1_SMALL |
| 148 | + Image: aws/codebuild/python:3.7.1 |
| 149 | + Type: LINUX_CONTAINER |
| 150 | + EnvironmentVariables: |
| 151 | + - Name: PACKAGE_BUCKET |
| 152 | + Value: !Ref ArtifactStoreBucket |
| 153 | + |
| 154 | + CICodeBuildRole: |
| 155 | + Type: AWS::IAM::Role |
| 156 | + Properties: |
| 157 | + AssumeRolePolicyDocument: |
| 158 | + Version: "2012-10-17" |
| 159 | + Statement: |
| 160 | + - Effect: Allow |
| 161 | + Principal: |
| 162 | + Service: |
| 163 | + - "codebuild.amazonaws.com" |
| 164 | + Action: |
| 165 | + - "sts:AssumeRole" |
| 166 | + Path: /service-role/ |
| 167 | + Policies: |
| 168 | + - PolicyName: CICodeBuildRolePolicy |
| 169 | + PolicyDocument: |
| 170 | + Version: "2012-10-17" |
| 171 | + Statement: |
| 172 | + - Effect: Allow |
| 173 | + Action: |
| 174 | + - "logs:CreateLogGroup" |
| 175 | + - "logs:CreateLogStream" |
| 176 | + - "logs:PutLogEvents" |
| 177 | + Resource: |
| 178 | + - !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/* |
| 179 | + - Effect: Allow |
| 180 | + Action: |
| 181 | + - "s3:PutObject" |
| 182 | + - "s3:GetObject" |
| 183 | + - "s3:GetObjectVersion" |
| 184 | + Resource: |
| 185 | + - !Sub ${ArtifactStoreBucket.Arn}/* |
| 186 | + - Effect: Allow |
| 187 | + Action: |
| 188 | + - "s3:ListBucket" |
| 189 | + Resource: |
| 190 | + - !Sub ${ArtifactStoreBucket.Arn} |
0 commit comments