- Lab
- A Cloud Guru
Rolling Updates to a Highly Distributed Web Application with AWS CodeDeploy
A DevOps engineer needs to deploy an application to a fleet of existing servers within AWS. When the rollout is complete, they need to push out an update, without taking the application offline. In this lab, we will use AWS CodeDeploy to manage code deployments and updates to a fleet of EC2 instances running in an Auto Scaling group and presented behind an elastic load balancer.
Path Info
Table of Contents
-
Challenge
Create an S3 Bucket to Store Application Code
- Navigate to S3.
- Select Create bucket, and enter a unique bucket name. Make a note of this name. From now on in these lab instructions, we will call this our code bucket.
- In another browser tab, navigate to the GitHub repository for this course. You'll find a link in the resources section of the lab. Download the repository.
- Upload the two zip files into your code bucket.
-
Challenge
Create a CodeDeploy In-Place Deployment
Create a CodeDeploy Application
- Navigate to the AWS CodeDeploy service page.
- Select Applications from the left-hand menu.
- Select Create application.
- For the Application name, enter "demo-app".
- For the Compute platform select EC2/On-premises.
- Select Create application.
Create a CodeDeploy Deployment Group
- From the CodeDeploy applications details page, select Create deployment group.
- For the Deployment group name, enter "demo-group".
- For Service role, select the role created with this lab (the only option).
- For Deployment type, select In-place.
- For Environment configuration, select Amazon EC2 Auto Scaling groups.
- From the dropdown box, select Auto Scaling group la-scale-asg-, which should be the only option.
- Scroll down to Load balancer, and select Classic Load Balancer. Then, from the dropdown list, select la-lab (the only option).
- Select Create deployment group.
Create a CodeDeploy Deployment
- From the CodeDeploy deployment group details page, select Create deployment.
- Ensure the Deployment group selected is demo-group.
- Ensure the Revision type selected is My application is stored in Amazon S3.
- For Revision location, enter the path of the
SampleApp_Linux.zip
object in your code bucket. For example:s3://code-bucket-123/SampleApp_Linux.zip
. - Scroll to Additional deployment behavior settings and under Content options, select Overwrite the content.
- Select Create deployment.
-
Challenge
Test the Deployed Application
- Navigate to the AWS EC2 console.
- Select Load Balancers from the left-hand menu.
- Select the Description tab, and copy the value for DNS name.
- Paste that value into a new browser tab.
- Ensure you can see the sample web application.
-
Challenge
Create a CodeDeploy Blue-Green Deployment
Create a CodeDeploy Deployment Group
- Navigate to the AWS CodeDeploy service page.
- Select Applications from the left-hand menu, then select demo-app from the list of applications.
- From the CodeDeploy applications details page, select Create deployment group.
- For the Deployment group name, enter "demo-blue-green".
- For Service role select the role created with this lab (the only option).
- For Deployment type, select Blue/green.
- For Environment configuration, select Automatically copy Amazon EC2 Auto Scaling group.
- From the dropdown box, select Auto Scaling group la-scale-asg-, which should be the only option.
- From Deployment settings, ensure Reroute traffic immediately is selected, and ensure Terminate the original instances in the deployment group is selected, and that 0's (zeros) are in place for Days, Hours, and Minutes.
- Scroll down to Load balancer, select Classic Load Balancer and from the dropdown list select la-lab (the only option).
- Select Create deployment group.
Create a CodeDeploy Deployment
- From the CodeDeploy deployment group details page, select Create deployment.
- Ensure the Deployment group selected is demo-blue-green.
- Ensure the Revision type selected is My application is stored in Amazon S3.
- For Revision location, enter the path of the
SampleApp_Linux_update.zip
object in your code bucket. For example:s3://code-bucket-123/SampleApp_Linux_update.zip
. - Scroll to Additional deployment behavior settings and under Content options, select Overwrite the content.
- Select Create deployment.
Now wait for the deployment to complete.
-
Challenge
Test the Updated Application
Note: This is a repeat of the previous testing step. If you have a browser tab open still from that testing, you may simply press refresh in your browser.
- Navigate to EC2.
- Select Load Balancers from the left-hand menu.
- Select the Description tab, and copy the value for DNS name.
- Paste that value into a new browser tab.
- Ensure you can see the sample web application.
You should notice there is a mistake on the page: It says it's deployed with Azure! Next, we will look at rolling this update back.
-
Challenge
Perform a Manual Rollback
Note: Performing a manual rollback, in this case, is the same as performing an in-place deployment and will follow the same process. There are other options for rolling back code when multiple deployments have been made from the same deployment group. In that case, you can ask CodeDeploy to roll back to the last known good state. In this lab, however, we have only deployed once per deployment group, and the error in the code is not visible to CodeDeploy, as it's a wording issue on the site.
Create a CodeDeploy Deployment Group
- Navigate to CodeDeploy.
- Select Applications from the left-hand menu, then select demo-app from the list of applications.
- From the CodeDeploy applications details page, select Create deployment group.
- For the Deployment group name, enter "quick-fix".
- For Service role, select the role created with this lab (the only option).
- For Deployment type, select In-place.
- For Environment configuration, select Amazon EC2 Auto Scaling groups.
- From the dropdown box, select Auto Scaling group demo-blue-green-, which should be the only option.
- Scroll down to Load balancer, select Classic Load Balancer, and from the dropdown list select la-lab (the only option).
- Select Create deployment group.
Create a CodeDeploy Deployment
- From the CodeDeploy deployment group details page, select Create deployment.
- Ensure the Deployment group selected is quick-fix.
- Ensure the Revision type selected is My application is stored in Amazon S3.
- For Revision location, enter the path of the
SampleApp_Linux.zip
object in your code bucket. For example:s3://code-bucket-123/SampleApp_Linux.zip
. - Scroll to Additional deployment behavior settings and under Content options, select Overwrite the content.
- Select Create deployment.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.