Create an AWS CICD Project with CodeCommit, CodeDeploy, Codepipeline and EC2 Instance
In the project, you will learn how to set up a continuous integration and continuous delivery (CI/CD) pipeline on AWS.
A pipeline helps you automate steps in your software delivery process, such as initiating automatic builds and then deploying to Amazon EC2 instances.
AWS CodePipeline, a service that builds, tests, and deploys your code every time there is a code change, based on the release process models you define.
Use CodePipeline to orchestrate each step in your release process. As part of your setup, you will plug other AWS services into CodePipeline to complete your software delivery pipeline.
With this setup, we can learn to create a very simple pipeline that pulls code from a source repository and automatically deploys it to an Amazon EC2 instance.
Create a CodeCommit Repository
Pushing local code to CodeCommit
Perform all the tasks directly with IAM User because without IAM user we are not able to push the local code
Open CodeCommit and click to create a repository
Click to create after giving the name
Create an IAM User
Create an IAM user for further steps
Attaching policies directly
After selecting clicked to create
Again clicked to create a user
Now I am accessing the AWS account with an IAM user in Private windows
Search for CodeCommit and click to copy HTTPS URL
https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
Add sample code to our CodeCommit Repository
#Use this Blog to understand how to push code from a local machine to CodeCommit or GitHub
Generate credentials for this, click on the security credentials of the IAM user
Click to generate and download
After entering the credentials my local code is now available at by CodeCommit
Creating an IAM Role
Select EC2 and clicked on the next button
Click to Next, then search for the Permission Policy
Gave a name to the Role
Click to Create Role
Create an EC2 Linux Instance and install the CodeDeploy Agent
Creating an EC2 Instance to deploy the CodeDeploy agent there, while creating EC2 allow SSH and HTTP anywhere and in additional details select IAM user.
In this step, we create the Amazon EC2 instance where we deploy a sample application.
As part of this process, create an instance role that allows the installation and management of the CodeDeploy agent on the instance.
The CodeDeploy agent is a software package that enables an instance to be used in CodeDeploy deployments.
We also attached policies that allow the instance to fetch files that the CodeDeploy agent uses to deploy your application and to allow the instance to be managed by SSM.
Went to IAM Role again to create a new role, this time select CodeDeploy from the Usecases for other AWS Services
Role created
Creating Application on CodeDeploy
In CodeDeploy, an application is a resource that contains the software application you want to deploy.
Later, we use this application with CodePipeline to automate deployments of the sample application to your Amazon EC2 instance.
First, we created a role that allows CodeDeploy to perform deployments. Then, you created a CodeDeploy application.
Click to Applications
Click to Create Deployment Group
A deployment group is a resource that defines deployment-related settings like which instances to deploy to and how fast to deploy them.
I am having only one EC2 Instance so I selected Amazone EC2 Instances options instead of others
Agent configuration with AWS systems manager is the default
I have one instance so I selected
I disable the load balancer because I have only one Instance
Rest things are default so I clicked to Create Default
Creating the First Pipeline in the CodePipeline
Click to create Pipeline
Gave a name select details
Go with the default settings
I skipped the build stage
Select the details
Click to Next and review the parameters then click to Create Pipeline
Done
Modified code and again created a push
So Whenever I made changes in my local repository or make a push that time CodePipeline will start working automatically
Thankyou