DEV Community

Cover image for AWS CODE PIPELINE
Shivani Patel
Shivani Patel

Posted on

AWS CODE PIPELINE

I implemented continuous integration for my Python application using AWS and GitHub. To begin, I created a GitHub repository for my code. Then, I set up an AWS CodePipeline to automate the integration, linking it to my GitHub repository and configuring AWS CodeBuild to handle the build process. I specified the necessary build environment and commands in CodeBuild. Once configured, I initiated the CI process by making updates to my GitHub code, which automatically triggered the pipeline, building and deploying the application as planned. This approach optimized my workflow by automating the steps from code updates to deployment, ensuring seamless and efficient integration and deployment.

Image description
Step 1: GitHub Repository Setup
Create a GitHub repository to store the source code for your Python application.(https://github.com/she0407/CI-CD-PIPELINE-DEMO)
Ensure that the repository is correctly configured with the necessary files for your project.

Step 2: AWS CodePipeline Creation
Create a new AWS CodePipeline to automate the CI process.
Connect the pipeline to the GitHub repository, specifying the repository and branch.

Step 3: AWS CodeBuild Setup
In the AWS CodeBuild service, create a new build project.
Under the Source Provider, log in to your GitHub account and choose the repository for the project.
In the Environment section, choose Ubuntu as the operating system and select the latest image version. Create a new service role if needed.
In the Buildspec section, switch to the editor mode and enter the commands for building your Python application.
Create the build project once everything is configured.

Image description

Image description

under the environment section I chose the os as ubuntu and cjhose the latest image version and created new service role.

Image description

under the buildspec I chose inster build commands and switch to editor and wrote commands for building

Image description

Image description
and I have created a code build.
afterwards I chose aws system manager and created three parameters to connect to my dockerhub one is url (docker.io) and username and passwords

Image description

Image description

Step 4: AWS Systems Manager Parameter Store Setup
Navigate to AWS Systems Manager and create three parameters to connect to Docker Hub:
Docker Hub URL (e.g., docker.io)
Docker Hub Username
Docker Hub Password
These parameters will be used later to push the Docker image to Docker Hub.
so I have successfully created a three parameters as shown below:

Image description

Step 5: IAM Role and Permissions
In IAM, create the necessary roles and permissions for your build process. You’ll need roles for CodeBuild and CodeDeploy, ensuring they have access to push images to Docker Hub and interact with EC2 instances.

Image description

Image description
Step 6: Build Execution
Return to AWS CodeBuild and click on Start Build. The build process will run according to the specified build commands.
Once the build is complete, the Docker image will be created and pushed to Docker Hub.

Image description

Image description

Image description
the image has been created in the Docker hub

Image description

Step 7: Pipeline Configuration
Set up the pipeline by defining the source, build, and deploy stages. For the source stage, select the GitHub repository and the branch to monitor.
Skip the deployment stage for now if it’s not required.

Image description

under the source stage I chose the latest git version and connected to github.

Image description

I chose the repo and the branch and format

Image description

Image description
and I have created pipeline skipping the deployment stage.

Image description

Step 8: EC2 Instance Setup for Deployment
In AWS EC2, launch a new instance for deployment. Ensure that the appropriate security groups are configured, and connect to the instance via SSH.
Verify that the CodeDeploy Agent is running.
as we can see under the build “build has succeeded ”
now I have created an application in the codedeploy then created application

Image description

Image description

Image description

Image description

Image description

Image description

I have gave the command to update and install the code deploy agent and checked if the instance has started or no

Image description

Image description

Image description

Image description
as the agent is under running status we can see from the below capture,

Image description

after that we create role to give the necessary information one I have created is for ec2 role full access and the code deploy role

Image description
Step 9: CodeDeploy Configuration
In AWS CodeDeploy, create a new application and deployment group.
Select the EC2 service role for CodeDeploy.
For deployment, select GitHub as the source and provide the repository token and commit ID for the latest version of the application.
Execute the deployment, which will pull the application code from GitHub and deploy it on the EC2 instance.

Image description

Image description

Image description

Image description

Image description

after that will move to dockerhub and copy the pull command and paste it into the startcontainer.sh file

Image description

Image description
and will commit and push it to github

Image description

Image description
will take the latest commit and then edit in the code deployment and now paste it ,

Image description

then all three build source and deployment stage individually succeed so will create a pipeline for that will add a stage to running pipeline and then add the build artifact as input artifact and run the pipeline ,

Image description

Image description

Image description

Step 11: Final Deployment and Pipeline Success
Use the latest commit and edit the CodeDeploy settings to deploy this updated version.
Verify that all three stages (source, build, and deployment) succeed, ensuring the complete CI pipeline runs smoothly.

Image description
and the whole pipeline is succeed as well .

Image description

Image description

Top comments (0)