aws codepipline - creating s3 bucket using cloudformation

 In this setup we are going to create a simple code pipeline that gets code from codecommit and then build it with codebuild. Finally it uses codepipeline to create/update a s3 via cloudformation. 

Here are the steps:

1. check in your code 

2. create a codebuild to get your app build - yes although it is just a simple command

3. create a codepipeline that combine everything


Source

 You can get the source from here.

https://github.com/mitzenjeremywoo/simple-cloudformation-s3-codepipeline

Check this into your codecommit. The build file is ready, so we can just setup codebuild as well.


Setting up code build 

1. Create a build project call it cfbuild

2. Source provider - AWS code commut 

3. Repository - your repository, Branch - master, 

4. Operating system - Amazon Linux

5. Buildspec - Choose Use Buildspec 

6. Artifact - Amazon S3, Bucket name - choose your bucket name and name of the folder - configure it as cfbuild

7. Artifact packaging - zip 

Things to note here - Although artifact is zip, AWS codepipeline will be able to read s3-out.yaml. file.


Setting up AWS codepipeline

Source section

1. For the name of the pipeline, give it mytest 

2. Click next, and then under Source select Action Provider - choose AWS CodeCommit. Choose your repository name, Branch - master

3. Output - SourceArtifact

Build section 

1. For action provider - choose AWS CodeBuild

2. Input Artifact - Source Artifact

3. Project name - choose cfbuild - (the build name we configure above)

4. Output artifact - confirm it is BuildArtifact



Deploy section 

1. Provide a name. 

2. Action Provider - AWS Cloudformation (Not AWS Cloudformtion Stack Set)

3. Input artifact - BuildArtifact

4. Action mode - Create or replace a changeset

5. Stack name - give it myteststack - don't worry about the error - the stack name does not exist. 

6. Change set name - give it myteststack-changeset

7. Template -- Choose Buildartifact. Filename - s3-out.yaml - this is the output of our build process configured above. 

8. Capabilities - Capability_IAM 

9. Role name:  You need to create a role and give it access to S3. Then come back to codepipeline to complete your build.

Some of the configuration is shown below:-




Also note the template file path: BuildArtifact::s3-out.yaml



Run the codebuild pipeline. 

You will hit build error saying that it does not have access to S3 bucket. Please add the necessary permission for this role. 



















Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm