A Cloud Architect Company
Amazon Web Services

How to run cloudformation from codepipeline using S3

INTRODUCTION:

In this article we will run cloudformation from codepipeline using S3CodePipeline is a continuous integration and continuous delivery (CI/CD) service provided by Amazon Web Services (AWS). It automates the process of building, testing, and deploying your code changes.CodePipeline allows you to create custom pipelines to fit your specific development workflow. It also integrates with various AWS services and third-party tools, making it versatile and widely used for automating software release processes.

 

 

WHAT IS CLOUDFORMATION:

AWS CloudFormation is a service that allows you to define and provision infrastructure resources in a declarative way, using templates. These templates are written in JSON or YAML format and describe the desired state of your AWS infrastructure, including resources such as EC2 instances, databases, load balancers, IAM roles, and more. CloudFormation simplifies and streamlines the process of managing AWS infrastructure, making it easier to provision and maintain resources in a reliable and consistent manner.

PREREQUISITES:

  • AWS account.
  • AWS account with Cloudformation and S3 full access.
  • Basic knowledge about Codepipeline.

INTENDED AUDIENCE:

  • Engineer

CLOUDFORMATION TEMPLATE:

This is the template of the cloudformation. you can replace the key pair with your own key pair. if you already have an vpc you can give the vpc id, public subnets id. you can also change the imaged id. Check this Repository for Template https://github.com/Sakthiyuva/cloudformation-codepipeline.git

Cloudformation template

compress the template file to an zipped file.

zipped file

CREATING BUCKET:

click on create bucket.

creating bucket

After giving name to the bucket, enable the bucket versioning > create bucket.

bucket versioning

Go inside the bucket we created > click on upload

uploading file

Now click on Add files.

Adding files

Upload the file which we zipped > click on upload.

Adding file

CREATING ROLE FOR CODEPIPELINE:

Go to the IAM console. now we should create an role for codepipeline > click create role.

creating role

As we dont have Codepipeline in role, we are selecting EC2 in service. Later we will change EC2 to Codepipeline > click next. choosing service

Dont add any policy > click next > Give name to the policy > create Role.

Role name

Go inside the role we created > Go inside the Trust relationship > Edit Trust policy.

Trust Relationship

Change the name from ec2 to codepipeline > Update policy.

Trust Relationship

Go to permissions > click on add permissions > create inline policy.

Create inline policy

In service select codepipeline > click on JSON

Selecting service

Paste the inline policy > click next.check the repository for the inline policy

https://github.com/Sakthiyuva/cloudformation-codepipeline.git

Inline policy

Give the policy name > create role.

policy name

CREATING ROLE FOR CLOUDFORMATION:

Next we should create role for cloudformation > select cloudformation in service > Next.

Choosing service

In policy select EC2 and S3 full access > Next > give name to the policy > create Role.

Role name

CREATING PIPELINE:

Now go to the codepipeline > click create pipeline.

Creating pipeline

Give name to the pipeine > Next.

Pipeline name

In source provider select Amazon S3 > select the bucket which you created > Give the object key of the bucket you created > Next

Source stage

Skip the Build stage > select Deploy provider as AWS cloudformation > select the region where you are working > In action mode select create or update stack > In artifact name select SourceArtifact and give the File name > select the role we created > next.

Deploy stage

Create pipeline > pipeline is successfully deployed.

Deployed

Go to ec2 instance. you can see that the instance is created.

Instance created

Now lets make some changes in Template and we can reupload it, lets see if the pipeline is automatically running or not.In template i have changed the instance name from codepipeline to codepipeline2 > save it.

Changing instance name

Zip the template file.

Zipping the file

Now go to the bucket we created > click on upload > add files.

Upload

upload the file which we zipped.

Uploading File

You can see that the pipeline got autotriggered and deployed.

Deployed

You can see that the instance name is changed.

Instance name

When we changed content in the template, the pipeline got auto triggered and deployed the cloudformation.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

back to top
advanced-floating-content-close-btn

Contact Us to save your AWS bill by 40%

X