How to Use AWS CodePipeline For Continuous Integration and Deployment? (original) (raw)

Last Updated : 23 Jul, 2025

**AWS CodePipeline automates the continuous integration (CI) and continuous deployment (CD) process by streamlining the build, test, and deployment phases. By integrating AWS CodeCommit, CodeBuild, and CodeDeploy, CodePipeline automates code commits, builds, and deployments. CI ensures that code is automatically built and stored with every commit, while CD automates swift and consistent deployments. This reduces manual errors and enhances deployment efficiency and reliability

aws_codepipeline

Using AWS CodePipeline For Continuous Integration and Deployment

**Step 1: First create a CodeCommit repository.

create-repo-on-code-commit

**Step 2: On the top right corner of page, click Clone URL to copy the **HTTPS URL .

copy-the-repo-url

**Step 3: Now go to a local editor terminal (for e.g. visual studio) and write the git clone using the copied URL . But here you will see a new screen will pop out and it will be asking GIT credential.

git clone <__copied URL_>

now-try-to-git-clone-at-local-with-copied-url-but-a-git-credential-it-will-ask

**Step 4: Now to generate GIT credential, go to the IAM service. Here go to the IAM user account that you are using using now. There you will find Security Credential, select that and scroll down to **HTTPS GIT credentials for AWS CodeCommit. Here click **Generate credentials.

create-git-credentials

**Step 5: Now we have the GIT credentials. So we can now git clone using the HTTPS URL of CodeCommit repository (_the same command used in step 3). You can now successfully clone the repository after entering the GIT credentials.

git-credentials

**Step 6: Now go inside the repository and create a index.html. Basically here all the changes are in local environment, so to make sync the changes with the CodeCommit repository you need to **push all the changes to the master branch of CodeCommit repository.

git add . git commit -m "first commit in codecommit" (you can give any message inside the inverted commas) git push origin master

created-and-pushed-the-indexhtml-to-the-repo

**Step 7: Now we have all these code present inside the CodeCommit repository. We need to build these code now. Before using AWS CodeBuild, we need a **buildspec.yml file inside the repository. This buildspec.yml defines the set of build commands and settings which is necessary for providing a structured way to specify how CodeBuild should build and package your application. Create a buildspec.yml file and push it CodeCommit repository.

version : 0.2

phases: install: commands: - echo Start with NGINX install - sudo apt-get update - sudo apt-get install nginx -y build: commands: - echo Building... - cp index.html /var/www/html/ artifacts: files: - /var/www/html/index.html

add-buildspecyml-to-repo-as-it-is-needed-during-code-build

**Step 8: Now go to AWS CodeBuild and create a build. Here provide the project name. Add **CodeCommit as code source and here also mention the branch you are using. Select **Ubuntu as operating system, **standard runtime and use the latest image. Here automatically a new service role will be created and attached to the build. Mention the build file, but if you have already selected buildspec.yml then then there is no need for mentioning in the Buildspec name. Select no artifacts. Here you can untick the Cludwatch logs and create the build.

**Step 9: After creating code build you can start the build to see whether your build is successful or not. This build is creating some artifacts which needs to be stored. So select edit and then select artifacts.

artifact select

**Step 10: Here we have used Amazon S3 bucket to store the artifacts. Mention the s3 bucket previously created here and in names write **artifacts.zip (.zip).

artifacts

**Step 11: Then start the build. You can check the phase details status.

build-successful

**Step 12: After build status is successful, now we have to deploy our website. Create an **application on AWS CodeDeploy. Here mention the application name and select EC2/On-premises as compute platform.
create-application

**Step 13: In the previous step we have taken EC2 as compute platform. So now we have to create an EC2 instance(select base image ubuntu22). This EC2 instance needs is used as deployment platform which is interacting with AWS S3 bucket, AWS CodeDeploy service. So after creating EC2 instance you have to **create a IAM role and attach the role to the EC2 instance with some policies **AmazonEC2FullAccess, **AmazonS3FullAccess and **AWSCodeDeployFullAccess.

ec2-policy

**Step 14: Create another IAM role for deployment group with the policies **AmazonEC2FullAccess, **AmazonS3FullAccess, AWSCodeDeployFullAccess, **AmazonEC2RoleforAWSCodeDeploy, **AWSCodeDeployRole and **AmazonEC2RoleforAWSCodeDeployLimited. This role will attach to the deployment group that we will create in the next step.
policy-attached-(2)

**Step 15: Now go to AWS CodeDeploy and create a deployment group. Here mention deployment group name, attach the IAM role you have created in the previous step, select EC2 for environment configuration and attach the **EC2 instance created in step 13. And here we will install codedeploy agent manually and so select **never in install codedeploy agent.

**Step 16: Now we have to install the codedeploy agent on EC2 instance. You can install the codedeploy by following the official documentation of AWS or you can directly install codedeploy agent using the following script (_make sure that you are using us-east-1 or else you have change the region name in the script):

sudo apt-get update sudo apt-get install ruby-full ruby-webrick wget -y cd /tmp wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/releases/codedeploy-agent_1.3.2-1902_all.deb mkdir codedeploy-agent_1.3.2-1902_ubuntu22 dpkg-deb -R codedeploy-agent_1.3.2-1902_all.deb codedeploy-agent_1.3.2-1902_ubuntu22 sed 's/Depends:.*/Depends:ruby3.0/' -i ./codedeploy-agent_1.3.2-1902_ubuntu22/DEBIAN/control dpkg-deb -b codedeploy-agent_1.3.2-1902_ubuntu22/ sudo dpkg -i codedeploy-agent_1.3.2-1902_ubuntu22.deb systemctl list-units --type=service | grep codedeploy sudo service codedeploy-agent status

codedeploy-running

**Step 17: Like CodeBuild stage, CodeDeploy stage also needs a configuration file called **appspec.yml which provides instructions to CodeDeploy on how to deploy your application. Create appspec.yml in the local environment.

version: 0.0 os: linux files:

Here there are two scripts used, one script install the nginx service and another script to start the nginx service.

**install_nginx_service.sh

#!/bin/bash

sudo apt-get update sudo apt-get install -y nginx

**start_nginx_service.sh

#!/bin/bash

sudo service nginx start

After creating all these files you have to push all the changes to AWS CodeCommit repository.

added-appspecyml

**Step 18: Now you need to update the artifacts files in the **buildspec.yml and then push the changes to AWS CodeCommit repository.

changed-buildspec-to-solve-error

**Step 19: Now here we have to create a deployment using revise location as S3 bucket's URL . Previously we have used artifacts.zip to store the artifacts in S3 bucket, so mention the revision file type as ****.zip**.

deployment-using-artifacts

**Step 20: After this check the CodeCommit repository if all the files are present or not. Now again start the codebuild and then create the deployment.

deployment-suceeded

**Step 21: After the successful deployment then access the Public IP of EC2 instance to access the webpage.

after-deployment-succefully-accessed

**Step 22: Till now all the above steps are done manually. To automate the CodeCommit, CodeBuild and CodeDeploy stage we need to use AWS CodePipeline. So create an AWS CodePipeline.

create-pipeline

**Step 23: Select code source as AWS CodeCommit and mention the repository name and branch also. Here choose **AWS **CodePipeline in Change detection options (_After selecting this it will automatically detect changes in the repository and start the code build, code deploy stage).

code-source-provider

**Step 24: Select AWS CodeBuild as build provider and enter the project name.

build

**Step 25: Here also mention the AWS CodeDeploy as deploy provider and mention the application name and deployment group name.

deployment

**Step 26: After this the pipeline will be executed successfully.

pipeline-succeded

**Step 27: Now access the webpage using the Public IP of EC2 instance.

after-deployment-succefully-accessed

**Step 28: To check whether the AWS CodePipeline working properly or not make some changes in the index.html and push the changes to the AWS CodeCommit repository.

indexhtml-file-code-is-updated

**Step 29: After changes are pushed to AWS CodeCommit repository, you will notice that pipeline will automatically start and can see the recent commit message also.

look-here-the-message-also-updated

**Step 30: Finally access the updated webpage using the Public IP of EC2 instance.

updated-webpage

Benefits of CodePipeline

AWS CodePipeline Use Cases

AWS CodePipeline Pricing

Pipeline Type Pricing Structure Free Tier Additional Charges
V1 $1.00 per active pipeline per month. An active pipeline is one that has existed for more than 30 days and has at least one code change running through it during the month. One free active pipeline per month Additional charges may apply for storing and accessing pipeline artifacts in Amazon S3 and for triggering actions from other AWS and third-party services connected to your pipeline
V2 $0.002 per action execution minute. Action execution duration is calculated in minutes, from the time an action in your pipeline starts executing until it reaches a completion state, rounded up to the nearest minute 100 free action execution minutes per month, shared across all V2 pipelines in the account. Unused minutes do not carry over to the next month. Additional charges may apply for storing and accessing pipeline artifacts in Amazon S3 and for triggering actions from other AWS and third-party services connected to your pipeline.

Conclusion

So you have now learned why continuous integration and continuous deployment is important . Also we have gone through the various steps to automate the different stages like code commit , code build and code deploy using AWS CodePipeline . Finally we successfully accessed the website using the Public IP of EC2 instance .