Skip to main content

Redeploy a Failed Deployment with AWS Elastic Beanstalk

Hands-On Lab

 

Photo of Craig Arcuri

Craig Arcuri

AWS Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

Welcome to this hands-on AWS Learning Activity in which you will learn to deploy an Elastic Beanstalk environment and then rollback to a previous version of the environment. When performing updates to an environment, things don’t always go as planned. It is important to understand how these environments are configured and how to quickly perform a rollback if problems arise during a deployment. First, you will deploy an Elastic Beanstalk environment and verify that it is working properly. You will then perform an update but intentionally introduce an error into the code being deployed. After verifying the error, you will then redeploy the previous working version, effectively performing a rollback, getting your environment live and buying time to troubleshoot an error if this was a live situation.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Redeploy a Failed Deployment with AWS Elastic Beanstalk

Introduction

In this lab, we'll learn how to deploy an Elastic Beanstalk environment and then roll it back to a previous version of the environment.

First, we'll deploy an Elastic Beanstalk environment and verify it's working properly. We'll then perform an update, intentionally introducing an error into the code being deployed. After verifying the error, we'll redeploy the previous working version, effectively performing a rollback, getting our environment live and buying time to troubleshoot an error if this was a live situation.

Log in to the AWS environment by using the cloud_user credentials provided. Once inside the AWS account, make sure you are using us-east-1 (N. Virginia) as the selected region.

Also, be sure to download the .zip file in the Downloads section of the main course page, as we'll need it for part of the lab.

Redeploy Failed Deployments with Elastic Beanstalk

Create Elastic Beanstalk Environment

  1. Navigate to Elastic Beanstalk.
  2. Click Create New Application.
  3. Give the application a name of "EB Redeploy", and click Create.
  4. No environments currently exist for this application, so click Create one now.
  5. On the Select environment tier page, make sure Web server environment is selected, and click Select.
  6. In the Environment Information section, give it the Domain name "ebredeploy".
  7. Under Base configuration, for the Platform, select Preconfigured platform and choose Node.js from the dropdown.
  8. For Application code, select Sample application.
  9. Click Configure more options.
  10. On the Configure EbRedeploy-env page, in the Network box, click Modify.
  11. On the Modify network page, select the provided VPC in the dropdown.
  12. In the Instance Settings section, Check the box to Assign a public IP address to the Amazon EC2 instances in your environment.
  13. For an availability zone, check the box next to us-east-1a.
  14. Click Save and then Create environment. It should take about five minutes to generate, so hold tight.
  15. Once the new environment is created, open the URL listed at the top in a new browser tab to verify it worked. You should see an Elastic Beanstalk Node.js application is now running.

Download Provided Code and Edit to Introduce an Error

  1. It tends to be easier to unzip the downloaded file in a terminal, so open a terminal window.
  2. Change to your downloads directory, and enter unzip and then drag the actual .zip file itself onto the same line in the terminal window.
  3. Once the contents are listed/unzipped, we want to edit our file, so enter:
    sudo nano app.js
  4. Enter the cloud_user passphrase.
  5. In the empty line above var server, enter:
    intentional bugging
  6. Hit Ctrl+O to save, Enter to verify, and Ctrl+X to exit.
  7. We need to zip it back up, including the names of the four files we want to include in the zip file, so enter:
    zip ebredeploy.zip app.js cron.yaml index.html package.json

Create a New App Version

  1. Back in the Elastic Beanstalk console, click EB Redeploy at the top and select Application Versions.
  2. Click Upload.
  3. Since we know we've introduced an error, give it a Version label of "bugpackage".
  4. Click Choose File, select the ebredploy.zip file, and click Upload.
  5. Now, check the box next to bugpackage, click Deploy, and then Deploy again.
  6. Keep an eye on its progress by clicking the events page link that appears in the Info popup.
  7. We'll see the environment update completes successfully, but open the URL at the top in a new browser tab — our application is no longer working because of the error we added to the code.

Perform Rollback to Previously Working App Version

  1. Back in the Elastic Beanstalk console, click EB Redeploy at the top and select Application Versions.
  2. Check the box next to Sample Application, click Deploy, and then Deploy again.
  3. Click the events page link that appears in the Info popup to watch its progress.
  4. Once we see the environment is successfully updated, open the URL at the top in a new browser tab. This time, we'll see the application is back up and running.

Conclusion

We've successfully simulated an error in performing an update on our application, and then rolled it back within a couple minutes by redeploying the previously working version of the application.

Congratulations on completing this lab!