├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app ├── LICENSE └── MyWebAppRepo.zip ├── cfn-template ├── cicd-aws-code-suite-dev.json ├── cicd-codedeploy-prod.json └── cicd-ec2-instance-with-codedeploy.json └── policies ├── cicd_codebuild_service_policy.json ├── cicd_codepipeline_cross_ac_policy.json ├── cicd_codepipeline_service_policy.json ├── cicd_codepipeline_trigger_cwe_policy.json ├── cicd_ec2_instance_profile_policy.json ├── cicd_kms_key_policy.json └── cicd_s3_bucket_policy.json /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## This repository contains essential files for AWS Blog 2 | 3 | Use the files in this repository to follow AWS Blog [Complete CI/CD with AWS CodeCommit, CodeBuild, CodeDeploy & CodePipeline](https://aws.amazon.com/blogs/devops/complete-ci-cd-with-aws-codecommit-aws-codebuild-aws-codedeploy-and-aws-codepipeline/). 4 | 5 | ## License 6 | 7 | This library is licensed under the MIT-0 License. See the LICENSE file. 8 | -------------------------------------------------------------------------------- /app/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | -------------------------------------------------------------------------------- /app/MyWebAppRepo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/cicd-with-aws-code-suite/ab7ff46a865de70ce6c90f4834e3bb3c1bc7d54b/app/MyWebAppRepo.zip -------------------------------------------------------------------------------- /cfn-template/cicd-aws-code-suite-dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion": "2010-09-09", 3 | "Description": "Create complete CI/CD using AWS CodeCommit, CodePipeline, CodeBuild and CodeDeploy - Example", 4 | "Metadata": { 5 | "AWS::CloudFormation::Interface": { 6 | "ParameterGroups": [ 7 | { 8 | "Label": { 9 | "default": "CodeCommit configuration (to build CodeCommit repository):" 10 | }, 11 | "Parameters": [ 12 | "CodeCommitWebAppRepo", 13 | "CodeCommitMainBranchName" 14 | ] 15 | }, 16 | { 17 | "Label": { 18 | "default": "CodeBuild configuration (to build CodeBuild environment):" 19 | }, 20 | "Parameters": [ 21 | "CodeBuildProjectName", 22 | "CodeBuildServiceRole" 23 | ] 24 | }, 25 | { 26 | "Label": { 27 | "default": "CodeDeploy configuration (to create CodeDeploy App & Group):" 28 | }, 29 | "Parameters": [ 30 | "CodeDeployApp", 31 | "CodeDeployGroupDev", 32 | "CodeDeployGroupProd", 33 | "CodeDeployGroupTagKey", 34 | "CodeDeployGroupTagValue", 35 | "CodeDeployConfigName", 36 | "CodeDeployServiceRole" 37 | ] 38 | }, 39 | { 40 | "Label": { 41 | "default": "CodePipeline configuration (to build a 4 stage CodePipeline):" 42 | }, 43 | "Parameters": [ 44 | "CodePipelineName", 45 | "CodePipelineArtifactS3Bucket", 46 | "CodePipelineServiceRole", 47 | "CodePipelineCWEventTriggerRole", 48 | "CodePipeRoleXAProd" 49 | ] 50 | } 51 | ] 52 | } 53 | }, 54 | "Parameters": { 55 | "CodeCommitWebAppRepo": { 56 | "Type": "String", 57 | "Default": "MyWebAppRepo", 58 | "Description": "Enter name of the new CodeCommit Repo for your Web App." 59 | }, 60 | "CodeCommitMainBranchName": { 61 | "Type": "String", 62 | "Default": "master", 63 | "Description": "Enter main branch name on your CodeCommit repository. Default is master." 64 | }, 65 | "CodeBuildProjectName": { 66 | "Type": "String", 67 | "Default": "MyCBWebAppProject", 68 | "Description": "Enter name of the new CodeBuild environment." 69 | }, 70 | "CodeBuildServiceRole": { 71 | "Type": "String", 72 | "Description": "ARN of an existing IAM Service Role to be associated with CodeBuild in order to build web app code. Ex: arn:aws:iam::111111111111:role/cicd_codebuild_service_role", 73 | "Default": "", 74 | "AllowedPattern": "^arn:aws.*:iam:.*$|^$" 75 | }, 76 | "CodeDeployApp": { 77 | "Type": "String", 78 | "Default": "MyCDWebApp", 79 | "Description": "Enter name of the new CodeDeploy App to be created for your Web App." 80 | }, 81 | "CodeDeployGroupDev": { 82 | "Type": "String", 83 | "Default": "MyCICD-Deployment-Group-Dev", 84 | "Description": "Enter name of the new CodeDeploy Deployment Group to be created in Dev account." 85 | }, 86 | "CodeDeployGroupProd": { 87 | "Type": "String", 88 | "Default": "MyCICD-Deployment-Group-Prod", 89 | "Description": "Enter name an existing CodeDeploy Deployment Group in Prod account." 90 | }, 91 | "CodeDeployGroupTagKey": { 92 | "Type": "String", 93 | "Default": "Application", 94 | "Description": "Enter Tag Key that will be used by CodeDeploy to identify the existing EC2 fleet to be used by the Deployment Group." 95 | }, 96 | "CodeDeployGroupTagValue": { 97 | "Type": "String", 98 | "Default": "MyWebApp", 99 | "Description": "Enter Tag Value that will be used by CodeDeploy to identify the existing EC2 fleet to be used by the Deployment Group." 100 | }, 101 | "CodeDeployConfigName": { 102 | "Type": "String", 103 | "Default": "CodeDeployDefault.OneAtATime", 104 | "AllowedValues": [ 105 | "CodeDeployDefault.OneAtATime", 106 | "CodeDeployDefault.HalfAtATime", 107 | "CodeDeployDefault.AllAtOnce" 108 | ], 109 | "Description": "Enter desired Code Deploy Config Name. Default is: CodeDeployDefault.OneAtATime." 110 | }, 111 | "CodeDeployServiceRole": { 112 | "Type": "String", 113 | "Description": "ARN of an existing IAM Service Role to be associated with CodeDeploy in order to deploy web app. Ex: arn:aws:iam::111111111111:role/cicd_codedeploy_service_role", 114 | "Default": "", 115 | "AllowedPattern": "^arn:aws.*:iam:.*$|^$" 116 | }, 117 | "CodePipelineName": { 118 | "Type": "String", 119 | "Default": "MyWebAppPipeline", 120 | "Description": "Enter name of the new CodePipeline to be created for your Web App." 121 | }, 122 | "CodePipelineArtifactS3Bucket": { 123 | "Type": "String", 124 | "Default": "", 125 | "Description": "Enter name of the new Amazon S3 bucket to be created where artifacts for the pipeline are stored for this web app. Ex: mywebapp-codepipeline-bucket-us-east-1-111111111111. " 126 | }, 127 | "CodePipelineServiceRole": { 128 | "Type": "String", 129 | "Description": "ARN of an existing IAM Service Role to be associated with CodePipeline in order to deploy web app. Ex: arn:aws:iam::111111111111:role/cicd_codepipeline_service_role", 130 | "Default": "", 131 | "AllowedPattern": "^arn:aws.*:iam:.*$|^$" 132 | }, 133 | "CodePipelineCWEventTriggerRole": { 134 | "Type": "String", 135 | "Description": "ARN of an existing IAM role used to trigger the Code Pipeline 'named' above upon a code push to the CodeCommit repo. Ex: arn:aws:iam::111111111111:role/cicd_codepipeline_trigger_cwe_role", 136 | "Default": "", 137 | "AllowedPattern": "^arn:aws.*:iam:.*$|^$" 138 | }, 139 | "CodePipeRoleXAProd": { 140 | "Type": "String", 141 | "Description": "ARN of an existing IAM role in the cross-account which is to be assumed by CodePipeline in order to deploy the app. Ex: arn:aws:iam::222222222222:role/cicd_codepipeline_cross_ac_role", 142 | "Default": "", 143 | "AllowedPattern": "^arn:aws.*:iam:.*$|^$" 144 | } 145 | }, 146 | "Resources": { 147 | "myKMSKey": { 148 | "Type": "AWS::KMS::Key", 149 | "Properties": { 150 | "Description": "An example of symmetric CMK", 151 | "KeyPolicy": { 152 | "Version": "2012-10-17", 153 | "Id": "kms-key-policy", 154 | "Statement": [ 155 | { 156 | "Sid": "Allow access through Amazon S3 for all principals in the account that are authorized to use Amazon S3", 157 | "Effect": "Allow", 158 | "Principal": { 159 | "AWS": "*" 160 | }, 161 | "Action": [ 162 | "kms:Encrypt", 163 | "kms:Decrypt", 164 | "kms:ReEncrypt*", 165 | "kms:GenerateDataKey*", 166 | "kms:DescribeKey" 167 | ], 168 | "Resource": "*", 169 | "Condition": { 170 | "StringEquals": { 171 | "kms:CallerAccount": { 172 | "Fn::Sub": "${AWS::AccountId}" 173 | }, 174 | "kms:ViaService": { 175 | "Fn::Sub": "s3.${AWS::Region}.amazonaws.com" 176 | } 177 | } 178 | } 179 | }, 180 | { 181 | "Sid": "Enable IAM User Permissions", 182 | "Effect": "Allow", 183 | "Principal": { 184 | "AWS": { 185 | "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:root" 186 | } 187 | }, 188 | "Action": "kms:*", 189 | "Resource": "*" 190 | }, 191 | { 192 | "Sid": "Allow use of the key", 193 | "Effect": "Allow", 194 | "Principal": { 195 | "AWS": [ 196 | { 197 | "Fn::Sub": "${CodePipelineServiceRole}" 198 | }, 199 | { 200 | "Fn::Sub": "${CodeBuildServiceRole}" 201 | }, 202 | "arn:aws:iam::222222222222:root" 203 | ] 204 | }, 205 | "Action": [ 206 | "kms:Encrypt", 207 | "kms:Decrypt", 208 | "kms:ReEncrypt*", 209 | "kms:GenerateDataKey*", 210 | "kms:DescribeKey" 211 | ], 212 | "Resource": "*" 213 | } 214 | ] 215 | } 216 | } 217 | }, 218 | "myKMSKeyAlias": { 219 | "Type": "AWS::KMS::Alias", 220 | "Properties": { 221 | "AliasName": "alias/MyCICDKey", 222 | "TargetKeyId": { 223 | "Ref": "myKMSKey" 224 | } 225 | } 226 | }, 227 | "myS3Bucket": { 228 | "Type": "AWS::S3::Bucket", 229 | "DeletionPolicy": "Retain", 230 | "Properties": { 231 | "BucketName": { 232 | "Ref": "CodePipelineArtifactS3Bucket" 233 | } 234 | } 235 | }, 236 | "myS3BucketPolicy": { 237 | "Type": "AWS::S3::BucketPolicy", 238 | "Properties": { 239 | "Bucket": { 240 | "Ref": "myS3Bucket" 241 | }, 242 | "PolicyDocument": { 243 | "Statement": [ 244 | { 245 | "Sid": "DenyUnEncryptedObjectUploads", 246 | "Effect": "Deny", 247 | "Principal": "*", 248 | "Action": "s3:PutObject", 249 | "Resource": { 250 | "Fn::Sub": "arn:${AWS::Partition}:s3:::${CodePipelineArtifactS3Bucket}/*" 251 | }, 252 | "Condition": { 253 | "StringNotEquals": { 254 | "s3:x-amz-server-side-encryption": { 255 | "Fn::Sub": "${AWS::Partition}:kms" 256 | } 257 | } 258 | } 259 | }, 260 | { 261 | "Sid": "DenyInsecureConnections", 262 | "Effect": "Deny", 263 | "Principal": "*", 264 | "Action": "s3:*", 265 | "Resource": { 266 | "Fn::Sub": "arn:${AWS::Partition}:s3:::${CodePipelineArtifactS3Bucket}/*" 267 | }, 268 | "Condition": { 269 | "Bool": { 270 | "aws:SecureTransport": "false" 271 | } 272 | } 273 | }, 274 | { 275 | "Sid": "AllowCrossAccountRWAccessForCodeDeployService", 276 | "Effect": "Allow", 277 | "Principal": { 278 | "AWS": "arn:aws:iam::222222222222:root" 279 | }, 280 | "Action": [ 281 | "s3:Get*" 282 | ], 283 | "Resource": { 284 | "Fn::Sub": "arn:${AWS::Partition}:s3:::${CodePipelineArtifactS3Bucket}/*" 285 | } 286 | }, 287 | { 288 | "Sid": "AllowCrossAccountListForCodeDeployService", 289 | "Effect": "Allow", 290 | "Principal": { 291 | "AWS": "arn:aws:iam::222222222222:root" 292 | }, 293 | "Action": "s3:ListBucket", 294 | "Resource": { 295 | "Fn::Sub": "arn:${AWS::Partition}:s3:::${CodePipelineArtifactS3Bucket}" 296 | } 297 | } 298 | ] 299 | } 300 | } 301 | }, 302 | "MyWebAppRepo": { 303 | "Type": "AWS::CodeCommit::Repository", 304 | "Properties": { 305 | "RepositoryName": { 306 | "Ref": "CodeCommitWebAppRepo" 307 | }, 308 | "RepositoryDescription": "A sample java spring boot application" 309 | } 310 | }, 311 | "CodeBuildProject": { 312 | "Type": "AWS::CodeBuild::Project", 313 | "DependsOn": "MyWebAppRepo", 314 | "Properties": { 315 | "Name": { 316 | "Ref": "CodeBuildProjectName" 317 | }, 318 | "Description": "This is sample web app project", 319 | "ServiceRole": { 320 | "Ref": "CodeBuildServiceRole" 321 | }, 322 | "Artifacts": { 323 | "Type": "S3", 324 | "Location": { 325 | "Ref": "CodePipelineArtifactS3Bucket" 326 | } 327 | }, 328 | "Environment": { 329 | "Type": "LINUX_CONTAINER", 330 | "ComputeType": "BUILD_GENERAL1_SMALL", 331 | "Image": "aws/codebuild/standard:3.0-19.11.26", 332 | "EnvironmentVariables": [] 333 | }, 334 | "Source": { 335 | "Location": { 336 | "Fn::GetAtt": [ 337 | "MyWebAppRepo", 338 | "CloneUrlHttp" 339 | ] 340 | }, 341 | "Type": "CODECOMMIT" 342 | }, 343 | "TimeoutInMinutes": 30, 344 | "Tags": [ 345 | { 346 | "Key" : "Role", 347 | "Value" : "MyJavaApp" 348 | } 349 | ] 350 | } 351 | }, 352 | "MyCodeDeployApp": { 353 | "Type": "AWS::CodeDeploy::Application", 354 | "Properties": { 355 | "ApplicationName": { 356 | "Ref": "CodeDeployApp" 357 | } 358 | } 359 | }, 360 | "DevDeploymentGroup": { 361 | "Type": "AWS::CodeDeploy::DeploymentGroup", 362 | "Properties": { 363 | "ApplicationName": { 364 | "Ref": "MyCodeDeployApp" 365 | }, 366 | "DeploymentGroupName": { 367 | "Ref": "CodeDeployGroupDev" 368 | }, 369 | "DeploymentConfigName": { 370 | "Ref": "CodeDeployConfigName" 371 | }, 372 | "AutoRollbackConfiguration": { 373 | "Enabled": true, 374 | "Events": [ 375 | "DEPLOYMENT_FAILURE", 376 | "DEPLOYMENT_STOP_ON_ALARM", 377 | "DEPLOYMENT_STOP_ON_REQUEST" 378 | ] 379 | }, 380 | "ServiceRoleArn": { 381 | "Ref": "CodeDeployServiceRole" 382 | }, 383 | "Ec2TagFilters": [ 384 | { 385 | "Key": { 386 | "Ref": "CodeDeployGroupTagKey" 387 | }, 388 | "Value": { 389 | "Ref": "CodeDeployGroupTagValue" 390 | }, 391 | "Type": "KEY_AND_VALUE" 392 | } 393 | ] 394 | } 395 | }, 396 | "MyCodePipeline": { 397 | "Type": "AWS::CodePipeline::Pipeline", 398 | "Properties": { 399 | "Name": { 400 | "Ref": "CodePipelineName" 401 | }, 402 | "RoleArn": { 403 | "Ref": "CodePipelineServiceRole" 404 | }, 405 | "Stages": [ 406 | { 407 | "Name": "Source", 408 | "Actions": [ 409 | { 410 | "Name": "ApplicationSource", 411 | "ActionTypeId": { 412 | "Version": "1", 413 | "Category": "Source", 414 | "Owner": "AWS", 415 | "Provider": "CodeCommit" 416 | }, 417 | "OutputArtifacts": [ 418 | { 419 | "Name": "WebAppRepo-SourceArtifact" 420 | } 421 | ], 422 | "Configuration": { 423 | "RepositoryName": { 424 | "Ref": "CodeCommitWebAppRepo" 425 | }, 426 | "BranchName": { 427 | "Ref": "CodeCommitMainBranchName" 428 | }, 429 | "PollForSourceChanges": false 430 | }, 431 | "RunOrder": 1 432 | } 433 | ] 434 | }, 435 | { 436 | "Name": "Build", 437 | "Actions": [ 438 | { 439 | "Name": "ApplicationBuild", 440 | "InputArtifacts": [ 441 | { 442 | "Name": "WebAppRepo-SourceArtifact" 443 | } 444 | ], 445 | "ActionTypeId": { 446 | "Category": "Build", 447 | "Owner": "AWS", 448 | "Version": "1", 449 | "Provider": "CodeBuild" 450 | }, 451 | "OutputArtifacts": [ 452 | { 453 | "Name": "WebAppRepo-BuiltArtifact" 454 | } 455 | ], 456 | "Configuration": { 457 | "ProjectName": { 458 | "Ref": "CodeBuildProject" 459 | } 460 | }, 461 | "RunOrder": 2 462 | } 463 | ] 464 | }, 465 | { 466 | "Name": "DevelopDeploy", 467 | "Actions": [ 468 | { 469 | "Name": "DevelopDeploy", 470 | "InputArtifacts": [ 471 | { 472 | "Name": "WebAppRepo-BuiltArtifact" 473 | } 474 | ], 475 | "ActionTypeId": { 476 | "Category": "Deploy", 477 | "Owner": "AWS", 478 | "Version": "1", 479 | "Provider": "CodeDeploy" 480 | }, 481 | "Configuration": { 482 | "ApplicationName": { 483 | "Ref": "CodeDeployApp" 484 | }, 485 | "DeploymentGroupName": { 486 | "Ref": "CodeDeployGroupDev" 487 | } 488 | }, 489 | "RunOrder": 3 490 | } 491 | ] 492 | }, 493 | { 494 | "Name": "ProdDeploy", 495 | "Actions": [ 496 | { 497 | "Name": "ProdExternalDeploy", 498 | "InputArtifacts": [ 499 | { 500 | "Name": "WebAppRepo-BuiltArtifact" 501 | } 502 | ], 503 | "ActionTypeId": { 504 | "Category": "Deploy", 505 | "Owner": "AWS", 506 | "Version": "1", 507 | "Provider": "CodeDeploy" 508 | }, 509 | "Configuration": { 510 | "ApplicationName": { 511 | "Ref": "CodeDeployApp" 512 | }, 513 | "DeploymentGroupName": { 514 | "Ref": "CodeDeployGroupProd" 515 | } 516 | }, 517 | "RoleArn": { 518 | "Ref": "CodePipeRoleXAProd" 519 | }, 520 | "RunOrder": 4 521 | } 522 | ] 523 | } 524 | ], 525 | "ArtifactStore": { 526 | "Type": "S3", 527 | "Location": { 528 | "Ref": "CodePipelineArtifactS3Bucket" 529 | }, 530 | "EncryptionKey": { 531 | "Id": { 532 | "Fn::GetAtt": [ 533 | "myKMSKey", 534 | "Arn" 535 | ] 536 | }, 537 | "Type": "KMS" 538 | } 539 | } 540 | } 541 | }, 542 | "CloudWatchEventRuleMasterPipeline": { 543 | "Type": "AWS::Events::Rule", 544 | "Properties": { 545 | "Name": { 546 | "Ref": "CodePipelineName" 547 | }, 548 | "EventPattern": { 549 | "source": [ 550 | "aws.codecommit" 551 | ], 552 | "detail-type": [ 553 | "CodeCommit Repository State Change" 554 | ], 555 | "resources": [ 556 | { 557 | "Fn::Join": [ 558 | "", 559 | [ 560 | "arn:", 561 | { 562 | "Ref": "AWS::Partition" 563 | }, 564 | ":codecommit:", 565 | { 566 | "Ref": "AWS::Region" 567 | }, 568 | ":", 569 | { 570 | "Ref": "AWS::AccountId" 571 | }, 572 | ":", 573 | { 574 | "Ref": "CodeCommitWebAppRepo" 575 | } 576 | ] 577 | ] 578 | } 579 | ], 580 | "detail": { 581 | "event": [ 582 | "referenceCreated", 583 | "referenceUpdated" 584 | ], 585 | "referenceType": [ 586 | "branch" 587 | ], 588 | "referenceName": [ 589 | { 590 | "Ref": "CodeCommitMainBranchName" 591 | } 592 | ] 593 | } 594 | }, 595 | "Targets": [ 596 | { 597 | "Arn": { 598 | "Fn::Join": [ 599 | "", 600 | [ 601 | "arn:", 602 | { 603 | "Ref": "AWS::Partition" 604 | }, 605 | ":codepipeline:", 606 | { 607 | "Ref": "AWS::Region" 608 | }, 609 | ":", 610 | { 611 | "Ref": "AWS::AccountId" 612 | }, 613 | ":", 614 | { 615 | "Ref": "CodePipelineName" 616 | } 617 | ] 618 | ] 619 | }, 620 | "RoleArn": { 621 | "Ref": "CodePipelineCWEventTriggerRole" 622 | }, 623 | "Id": "codepipeline-AppPipeline" 624 | } 625 | ] 626 | } 627 | } 628 | }, 629 | "Outputs": { 630 | "MyCodePipelineName": { 631 | "Description": "My CI/CD Pipeline", 632 | "Value": { 633 | "Ref": "MyCodePipeline" 634 | } 635 | }, 636 | "MyCodeCommitHttpUrl": { 637 | "Description": "My CodeCommit Repository Http Url", 638 | "Value": { 639 | "Fn::GetAtt": [ 640 | "MyWebAppRepo", 641 | "CloneUrlHttp" 642 | ] 643 | } 644 | } 645 | } 646 | } -------------------------------------------------------------------------------- /cfn-template/cicd-codedeploy-prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion": "2010-09-09", 3 | "Description": "Part of the complete CI/CD using AWS CodeCommit, CodePipeline, CodeBuild and CodeDeploy example. This template is used to setup CodeDeploy App and Deployment Group using which the app is to be installed.", 4 | "Metadata": { 5 | "AWS::CloudFormation::Interface": { 6 | "ParameterGroups": [ 7 | { 8 | "Label": { 9 | "default": "CodeDeploy configuration (to create CodeDeploy App & Group):" 10 | }, 11 | "Parameters": [ 12 | "CodeDeployApp", 13 | "CodeDeployGroupProd", 14 | "CodeDeployGroupTagKey", 15 | "CodeDeployGroupTagValue", 16 | "CodeDeployConfigName", 17 | "CodeDeployServiceRole" 18 | ] 19 | } 20 | ] 21 | } 22 | }, 23 | "Parameters": { 24 | "CodeDeployApp": { 25 | "Type": "String", 26 | "Default": "MyCDWebApp", 27 | "Description": "Enter name of the new CodeDeploy App to be created for your Web App." 28 | }, 29 | "CodeDeployGroupProd": { 30 | "Type": "String", 31 | "Default": "MyCICD-Deployment-Group-Prod", 32 | "Description": "Enter name of the new CodeDeploy Deployment Group in Prod account." 33 | }, 34 | "CodeDeployGroupTagKey": { 35 | "Type": "String", 36 | "Default": "Application", 37 | "Description": "Enter Tag Key that will be used by CodeDeploy to identify the existing EC2 fleet to be used by the Deployment Group." 38 | }, 39 | "CodeDeployGroupTagValue": { 40 | "Type": "String", 41 | "Default": "MyWebApp", 42 | "Description": "Enter Tag Value that will be used by CodeDeploy to identify the existing EC2 fleet to be used by the Deployment Group." 43 | }, 44 | "CodeDeployConfigName": { 45 | "Type": "String", 46 | "Default": "CodeDeployDefault.OneAtATime", 47 | "AllowedValues": [ 48 | "CodeDeployDefault.OneAtATime", 49 | "CodeDeployDefault.HalfAtATime", 50 | "CodeDeployDefault.AllAtOnce" 51 | ], 52 | "Description": "Enter desired Code Deploy Config Name. Default is: CodeDeployDefault.OneAtATime." 53 | }, 54 | "CodeDeployServiceRole": { 55 | "Type": "String", 56 | "Description": "ARN of an existing IAM Service Role to be associated with CodeDeploy in order to deploy web app. Ex: arn:aws:iam::222222222222:role/cicd_codedeploy_service_role", 57 | "Default": "", 58 | "AllowedPattern": "^arn:aws:iam:.*$|^$" 59 | } 60 | }, 61 | "Resources": { 62 | "MyCodeDeployApp": { 63 | "Type": "AWS::CodeDeploy::Application", 64 | "Properties": { 65 | "ApplicationName": { 66 | "Ref": "CodeDeployApp" 67 | } 68 | } 69 | }, 70 | "ProdDeploymentGroup": { 71 | "Type": "AWS::CodeDeploy::DeploymentGroup", 72 | "Properties": { 73 | "ApplicationName": { 74 | "Ref": "MyCodeDeployApp" 75 | }, 76 | "DeploymentGroupName": { 77 | "Ref": "CodeDeployGroupProd" 78 | }, 79 | "DeploymentConfigName": { 80 | "Ref": "CodeDeployConfigName" 81 | }, 82 | "AutoRollbackConfiguration": { 83 | "Enabled": true, 84 | "Events": [ 85 | "DEPLOYMENT_FAILURE", 86 | "DEPLOYMENT_STOP_ON_ALARM", 87 | "DEPLOYMENT_STOP_ON_REQUEST" 88 | ] 89 | }, 90 | "ServiceRoleArn": { 91 | "Ref": "CodeDeployServiceRole" 92 | }, 93 | "Ec2TagFilters": [ 94 | { 95 | "Key": { 96 | "Ref": "CodeDeployGroupTagKey" 97 | }, 98 | "Value": { 99 | "Ref": "CodeDeployGroupTagValue" 100 | }, 101 | "Type": "KEY_AND_VALUE" 102 | } 103 | ] 104 | } 105 | } 106 | }, 107 | "Outputs": { 108 | "MyCodeDeployApp": { 109 | "Description": "My CodeDeploy App", 110 | "Value": { 111 | "Ref": "MyCodeDeployApp" 112 | } 113 | }, 114 | "MyCodeDeployDeploymentGroup": { 115 | "Description": "My CodeDeploy Deployment Group", 116 | "Value": { 117 | "Ref": "ProdDeploymentGroup" 118 | } 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /cfn-template/cicd-ec2-instance-with-codedeploy.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion": "2010-09-09", 3 | "Description": "Part of the complete CI/CD using AWS CodeCommit, CodePipeline, CodeBuild and CodeDeploy blog. This template can be used to create a new EC2 instance with an AWS CodeDeploy agent. This instance will be used install the sample Java app that is built and deployed via AWS CodePipeline", 4 | "Parameters": { 5 | "AMI": { 6 | "Type": "AWS::EC2::Image::Id", 7 | "Default": "", 8 | "Description": "Enter name of the Linux AMI in your region, which will be used to create EC2 instance with AWS CodeDeploy agent. Example: ami-0f96495a064477ffb" 9 | }, 10 | "InstanceSubnetId": { 11 | "Type": "AWS::EC2::Subnet::Id", 12 | "Default": "", 13 | "Description": "The VPC Subnet ID to deploy this instances into. Ex: subnet-abc123453abc" 14 | }, 15 | "Ec2SshKeyPairName": { 16 | "Type": "String", 17 | "Default": "AWS-DS-KP", 18 | "Description": "Name of an existing SSH KeyPair. Example: myEc2KeyPair" 19 | }, 20 | "Ec2IamInstanceProfile": { 21 | "Type": "String", 22 | "Default": "cicd_ec2_instance_profile", 23 | "Description": "Name of an existing EC2 instance profile. Example: cicd_ec2_instance_profile" 24 | } 25 | }, 26 | "Resources": { 27 | "SampleLinuxInstance": { 28 | "Type": "AWS::EC2::Instance", 29 | "Metadata": { 30 | "AWS::CloudFormation::Init": { 31 | "config": { 32 | "packages": { 33 | "yum": { 34 | "ruby": [] 35 | } 36 | }, 37 | "files": { 38 | "/home/ec2-user/install": { 39 | "source": { 40 | "Fn::Join": [ 41 | "", 42 | [ 43 | "https://aws-codedeploy-", 44 | { 45 | "Ref": "AWS::Region" 46 | }, 47 | ".s3.amazonaws.com/latest/install" 48 | ] 49 | ] 50 | }, 51 | "mode": "000755" 52 | } 53 | }, 54 | "commands": { 55 | "00-install-agent": { 56 | "command": "./install auto", 57 | "cwd": "/home/ec2-user/" 58 | }, 59 | "01-cfn-signal": { 60 | "command": { 61 | "Fn::Join": [ 62 | "", 63 | [ 64 | "/opt/aws/bin/cfn-signal -e 0 --stack ", 65 | { 66 | "Ref": "AWS::StackName" 67 | }, 68 | " --resource SampleLinuxInstance --region ", 69 | { 70 | "Ref": "AWS::Region" 71 | } 72 | ] 73 | ] 74 | } 75 | } 76 | } 77 | } 78 | } 79 | }, 80 | "CreationPolicy": { 81 | "ResourceSignal": { 82 | "Count": "1", 83 | "Timeout": "PT5M" 84 | } 85 | }, 86 | "Properties": { 87 | "InstanceType": "t2.micro", 88 | "ImageId": { 89 | "Ref": "AMI" 90 | }, 91 | "KeyName": { 92 | "Ref": "Ec2SshKeyPairName" 93 | }, 94 | "SubnetId": { 95 | "Ref": "InstanceSubnetId" 96 | }, 97 | "IamInstanceProfile": { 98 | "Ref": "Ec2IamInstanceProfile" 99 | }, 100 | "UserData": { 101 | "Fn::Base64": { 102 | "Fn::Join": [ 103 | "", 104 | [ 105 | "#!/bin/bash\n", 106 | "yum -y update\n", 107 | "yum -y install cfn-bootstrap\n", 108 | "/opt/aws/bin/cfn-init -v", 109 | " --stack ", 110 | { 111 | "Ref": "AWS::StackName" 112 | }, 113 | " --resource SampleLinuxInstance", 114 | " --region ", 115 | { 116 | "Ref": "AWS::Region" 117 | }, 118 | "\n" 119 | ] 120 | ] 121 | } 122 | }, 123 | "Tags": [ 124 | { 125 | "Key": "Name", 126 | "Value": "MyCicdBlogWebApp" 127 | }, 128 | { 129 | "Key": "Application", 130 | "Value": "MyWebApp" 131 | } 132 | ] 133 | } 134 | } 135 | }, 136 | "Outputs": { 137 | "MyCodeDeployApp": { 138 | "Description": "My EC2 Instance", 139 | "Value": { 140 | "Ref": "SampleLinuxInstance" 141 | } 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /policies/cicd_codebuild_service_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Sid": "AllowBuildOutputStreamingToDefaultLogGroup", 6 | "Effect": "Allow", 7 | "Resource": [ 8 | "arn:aws:logs:*:*:log-group:*" 9 | ], 10 | "Action": [ 11 | "logs:CreateLogGroup", 12 | "logs:CreateLogStream", 13 | "logs:PutLogEvents" 14 | ] 15 | }, 16 | { 17 | "Sid": "AllowS3ObjectAccessOnCodePipelineBuckets", 18 | "Action": [ 19 | "s3:PutObject", 20 | "s3:GetObject", 21 | "s3:GetObjectVersion", 22 | "s3:GetBucketAcl", 23 | "s3:GetBucketLocation" 24 | ], 25 | "Resource": "*", 26 | "Effect": "Allow" 27 | }, 28 | { 29 | "Sid": "AllowPullSourceCodeFromCodeCommit", 30 | "Action": "codecommit:GitPull", 31 | "Resource": "*", 32 | "Effect": "Allow" 33 | }, 34 | { 35 | "Sid": "AllowPushDockerImageToECR", 36 | "Action": [ 37 | "ecr:BatchCheckLayerAvailability", 38 | "ecr:CompleteLayerUpload", 39 | "ecr:GetAuthorizationToken", 40 | "ecr:InitiateLayerUpload", 41 | "ecr:PutImage", 42 | "ecr:UploadLayerPart" 43 | ], 44 | "Resource": "*", 45 | "Effect": "Allow" 46 | }, 47 | { 48 | "Sid": "AllowAccessCodeBuildSSMParameters", 49 | "Effect": "Allow", 50 | "Action": "ssm:GetParameters", 51 | "Resource": "arn:aws:ssm:*:*:parameter/CodeBuild/*" 52 | }, 53 | { 54 | "Sid": "AllowRunningBuildInVpc", 55 | "Effect": "Allow", 56 | "Action": [ 57 | "ec2:CreateNetworkInterface", 58 | "ec2:DescribeDhcpOptions", 59 | "ec2:DescribeNetworkInterfaces", 60 | "ec2:DeleteNetworkInterface", 61 | "ec2:DescribeSubnets", 62 | "ec2:DescribeSecurityGroups", 63 | "ec2:DescribeVpcs" 64 | ], 65 | "Resource": "*" 66 | }, 67 | { 68 | "Sid": "AllowBuildServiceToCreateENI", 69 | "Effect": "Allow", 70 | "Action": "ec2:CreateNetworkInterfacePermission", 71 | "Resource": "arn:aws:ec2:*:*:network-interface/*", 72 | "Condition": { 73 | "StringEquals": { 74 | "ec2:AuthorizedService": "codebuild.amazonaws.com" 75 | } 76 | } 77 | } 78 | ] 79 | } 80 | -------------------------------------------------------------------------------- /policies/cicd_codepipeline_cross_ac_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Sid": "AllowCodeDeployServiceListS3Objects", 6 | "Effect": "Allow", 7 | "Action": [ 8 | "s3:GetObject*", 9 | "codecommit:ListBranches", 10 | "codecommit:ListRepositories" 11 | ], 12 | "Resource": [ 13 | "arn:aws:s3:::mywebapp-codepipeline-bucket-us-east-1-111111111111/*" 14 | ] 15 | }, 16 | { 17 | "Sid": "AllowCodeDeployServiceDeployment", 18 | "Effect": "Allow", 19 | "Action": [ 20 | "codedeploy:CreateDeployment", 21 | "codedeploy:GetDeployment", 22 | "codedeploy:GetDeploymentConfig", 23 | "codedeploy:GetApplicationRevision", 24 | "codedeploy:RegisterApplicationRevision" 25 | ], 26 | "Resource": "*" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /policies/cicd_codepipeline_service_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Statement": [ 3 | { 4 | "Sid": "AllowCodeCommitActions", 5 | "Action": [ 6 | "codecommit:CancelUploadArchive", 7 | "codecommit:GetBranch", 8 | "codecommit:GetCommit", 9 | "codecommit:GetUploadArchiveStatus", 10 | "codecommit:UploadArchive" 11 | ], 12 | "Resource": "*", 13 | "Effect": "Allow" 14 | }, 15 | { 16 | "Sid": "AllowS3ObjectAccessOnCodePipelineBuckets", 17 | "Action": [ 18 | "s3:PutObject", 19 | "s3:GetObject", 20 | "s3:GetObjectVersion", 21 | "s3:GetBucketAcl", 22 | "s3:GetBucketLocation" 23 | ], 24 | "Resource": "*", 25 | "Effect": "Allow" 26 | }, 27 | { 28 | "Sid": "AllowCodeBuildActions", 29 | "Action": [ 30 | "codebuild:BatchGetBuilds", 31 | "codebuild:StartBuild" 32 | ], 33 | "Resource": "*", 34 | "Effect": "Allow" 35 | }, 36 | { 37 | "Sid": "AllowCodeDeployActions", 38 | "Action": [ 39 | "codedeploy:CreateDeployment", 40 | "codedeploy:GetApplication", 41 | "codedeploy:GetApplicationRevision", 42 | "codedeploy:GetDeployment", 43 | "codedeploy:GetDeploymentConfig", 44 | "codedeploy:RegisterApplicationRevision" 45 | ], 46 | "Resource": "*", 47 | "Effect": "Allow" 48 | }, 49 | { 50 | "Sid": "AllowAssumeRoleCrossAccount", 51 | "Effect": "Allow", 52 | "Action": "sts:AssumeRole", 53 | "Resource": [ 54 | "arn:aws:iam::222222222222:role/cicd_codepipeline_cross_ac_role" 55 | ] 56 | } 57 | ], 58 | "Version": "2012-10-17" 59 | } 60 | -------------------------------------------------------------------------------- /policies/cicd_codepipeline_trigger_cwe_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Effect": "Allow", 6 | "Action": [ 7 | "codepipeline:StartPipelineExecution" 8 | ], 9 | "Resource": [ 10 | "arn:aws:codepipeline:us-east-1:111111111111:*" 11 | ] 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /policies/cicd_ec2_instance_profile_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Sid": "AllowAccesstoKMSKeyToDecryptArtefact", 6 | "Effect": "Allow", 7 | "Action": [ 8 | "kms:DescribeKey", 9 | "kms:GenerateDataKey*", 10 | "kms:Encrypt", 11 | "kms:ReEncrypt*", 12 | "kms:Decrypt" 13 | ], 14 | "Resource": [ 15 | "arn:aws:kms:us-east-1:111111111111:key/82215457-e360-47fc-87dc-a04681c91ce1" 16 | ] 17 | }, 18 | { 19 | "Sid": "AllowListS3Objects", 20 | "Effect": "Allow", 21 | "Action": [ 22 | "s3:Get*" 23 | ], 24 | "Resource": [ 25 | "arn:aws:s3:::mywebapp-codepipeline-bucket-us-east-1-111111111111/*" 26 | ] 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /policies/cicd_kms_key_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Id": "key-consolepolicy-3", 4 | "Statement": [ 5 | { 6 | "Sid": "Allow access through Amazon S3 for all principals in the account that are authorized to use Amazon S3", 7 | "Effect": "Allow", 8 | "Principal": { 9 | "AWS": "*" 10 | }, 11 | "Action": [ 12 | "kms:Encrypt", 13 | "kms:Decrypt", 14 | "kms:ReEncrypt*", 15 | "kms:GenerateDataKey*", 16 | "kms:DescribeKey" 17 | ], 18 | "Resource": "*", 19 | "Condition": { 20 | "StringEquals": { 21 | "kms:CallerAccount": "111111111111", 22 | "kms:ViaService": "s3.us-east-1.amazonaws.com" 23 | } 24 | } 25 | }, 26 | { 27 | "Sid": "Enable IAM User Permissions", 28 | "Effect": "Allow", 29 | "Principal": { 30 | "AWS": "arn:aws:iam::111111111111:root" 31 | }, 32 | "Action": "kms:*", 33 | "Resource": "*" 34 | }, 35 | { 36 | "Sid": "Allow use of the key", 37 | "Effect": "Allow", 38 | "Principal": { 39 | "AWS": [ 40 | "arn:aws:iam::111111111111:role/cicd_codepipeline_service_role", 41 | "arn:aws:iam::111111111111:role/cicd_codebuild_service_role", 42 | "arn:aws:iam::222222222222:root" 43 | ] 44 | }, 45 | "Action": [ 46 | "kms:Encrypt", 47 | "kms:Decrypt", 48 | "kms:ReEncrypt*", 49 | "kms:GenerateDataKey*", 50 | "kms:DescribeKey" 51 | ], 52 | "Resource": "*" 53 | } 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /policies/cicd_s3_bucket_policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Id": "SSEAndSSLPolicy", 4 | "Statement": [ 5 | { 6 | "Sid": "DenyUnEncryptedObjectUploads", 7 | "Effect": "Deny", 8 | "Principal": "*", 9 | "Action": "s3:PutObject", 10 | "Resource": "arn:aws:s3:::mywebapp-codepipeline-bucket-us-east-1-111111111111/*", 11 | "Condition": { 12 | "StringNotEquals": { 13 | "s3:x-amz-server-side-encryption": "aws:kms" 14 | } 15 | } 16 | }, 17 | { 18 | "Sid": "DenyInsecureConnections", 19 | "Effect": "Deny", 20 | "Principal": "*", 21 | "Action": "s3:*", 22 | "Resource": "arn:aws:s3:::mywebapp-codepipeline-bucket-us-east-1-111111111111/*", 23 | "Condition": { 24 | "Bool": { 25 | "aws:SecureTransport": "false" 26 | } 27 | } 28 | }, 29 | { 30 | "Sid": "AllowCrossAccountRWAccessForCodeDeployService", 31 | "Effect": "Allow", 32 | "Principal": { 33 | "AWS": "arn:aws:iam::222222222222:root" 34 | }, 35 | "Action": [ 36 | "s3:Get*" 37 | ], 38 | "Resource": "arn:aws:s3:::mywebapp-codepipeline-bucket-us-east-1-111111111111/*" 39 | }, 40 | { 41 | "Sid": "AllowCrossAccountListForCodeDeployService", 42 | "Effect": "Allow", 43 | "Principal": { 44 | "AWS": "arn:aws:iam::222222222222:root" 45 | }, 46 | "Action": "s3:ListBucket", 47 | "Resource": "arn:aws:s3:::mywebapp-codepipeline-bucket-us-east-1-111111111111" 48 | } 49 | ] 50 | } 51 | --------------------------------------------------------------------------------