The Cloud has made a lot of things simpler for developers. In this thread, let's explore how easy it is to set up a CICD Pipeline in AWS using GitHub, AWS CodePipeline and Elastic Beanstalk.
What is CI/CD?
CI/CD is the combined practice of continuous integration (CI) with continuous delivery or continuous deployment (CD). The purpose of CI/CD is to allow developers and teams to deliver code changes more frequently and reliably.
The reference to the word pipeline is to explain how all of these processes are executed in a sequence, one after the other. The key to CI/CD is automation. The process can be more and more efficient if there is not a lot of manual involvement. It is crucial to have an efficient pipeline when you're dealing with large codebases in production since a lot of changes are made at different parts of an application.
Prerequisites
- An AWS Account (preferably Free Tier so that you are not charged for using cloud infrastructure)
Tools Used
- GitHub
- AWS CodePipeline
- AWS Elastic Beanstalk
For this demonstration, we'll use a sample PHP application and deploy it to Elastic Beanstalk.
Creating a Deployment Environment in Elastic Beanstalk
Open up Elastic Beanstalk in the AWS Console and click on Create Application.
Give a name to your application, choose PHP for the platform and Sample Application for your code type. Now, click on Create Application.
Wait for a minute, while Beanstalk creates a sample environment for you to deploy your application. By default, it creates an EC2 instance, a security group, an Auto Scaling group, an Amazon S3 Bucket, Amazon CloudWatch alarms and a domain name for your application.
You can click on the URL to visit the application. You'll get a custom PHP welcome page by default.
Getting your sample code
A sample application is provided in a tutorial for creating a simple pipeline in the AWS Documentation. You can either upload those files to your GitHub repository or simply fork my GitHub repository here.
Since we are using GitHub as the source, we do not need the scripts folder, so you can delete it if you want. The scripts folder can come in handy if you are using Amazon S3 as the source for your application :)
Creating a CodePipeline
Open up the CodePipeline Dashboard. In this step, we will create a simple pipeline where we specify our GitHub Repository for the source code and deploy the code to the Beanstalk app we just created.
- Step 1
Enter a name for your pipeline and allow AWS to create a service role for this pipeline.
- Step 2
Create a Connection to Connect your pipeline to GitHub.
Ideally, you should only allow access to the specific GitHub Repository you're currently using.
After the connection, choose the repository and the branch and go with the default CodePipeline for Output artifact format.
- Step 3
Skip the build stage (since we do not have any build command) and fill in the Beanstalk application details in the Deployment Stage and lastly, review the data and click on Create Pipeline.
View Pipeline Progress
Wait for a few minutes while the Pipeline is executed and you can see that the process was completed. You can click on AWS Elastic Beanstalk which takes you back to the Beanstalk application we created. Now, if you click on the URL, you can see that our application is successfully deployed.
Congratulations, we just deployed our application to AWS Elastic Beanstalk via a pipeline.
Make Changes to re-run the pipeline
Open up the pipeline repository on GitHub and make some changes in the index.html file using the default GitHub text editor.
After making the changes, quickly switch back to the pipeline and observe the changes. You can notice that the pipeline is being re-executed on your new commit.
Once the pipeline execution is complete and successful, go back to the website.
As you can see, our changes were immediately reflected in our application and we didn't have to do anything extra for it.
You can take this to the next level, where you deploy your Node.js or Python projects to Beanstalk, set up Tests, and run them on every new commit to your production branch.
Recommended Cleanup
It is good practice to clean up/delete/terminate all services you have used on AWS (on any Cloud really) so that you are not charged in the future.
Firstly, delete your CodePipeline. Then, go to the Elastic Beanstalk Dashboard and delete your Application. This will also delete and terminate all other services used by the application.
This was a small demonstration of CICD in AWS. I hope you liked it. If you have used AWS CodePipeline before, do share your experience.
Thank you for reading :)
Top comments (0)