- This lab walks you through the steps to setup Blue/Green deployments with AWS Elastic Beanstalk
- You will practice it using AWS Elastic Beanstalk
- Duration: 1 hour
- AWS Region: US East (N. Virginia) us-east-1
AWS Elastic Beanstalk
- AWS Elastic Beanstalk is a Platform as a Service(PaaS) offered by Amazon for deploying and scaling web applications
- It allows us to use a wide selection of application platforms.
- It also enables us to have a variety of application deployment options.
- It enables the developer to concentrate on developing rather than spending time on managing and configuring servers.
- It gives us the ability to automatically scale an application up and down based on the application’s specific needs.
Blue/Green deployments with Elastic Beanstalk
- AWS Elastic Beanstalk performs normal deployments in the current production environment. Due to this, the application will be unavailable to users until the update is complete.
- This downtime can be avoided by performing a blue/green deployment.
- Blue/Green deployments are used to update an application from one version to another version without any downtime.
- The blue environment is your existing production environment carrying live traffic.
- The Green environment is an identical parallel new environment running a different or updated version of the application.
- Deploying of Blue/Green environments such that you can deploy a new version to a separate environment.
- Once the deployment is done, we simply route the traffic from the Blue environment to Green environment by swapping their CNAMEs or using Route 53 to slowly shift percentages of traffic over (not included in this lab).
- After the routing is complete, if you face any issues in the green environment, Elastic BeanStalk gives us an option to easily roll back to the blue environment.
- Zero downtime while updating the environments and swapping.
- It’s Easy to roll back to the older version if you face any issues in the new environment.
- Create an Elastic BeanStalk application.
- Create a Blue environment with a PHP application.
- Access the Blue environment’s URL and verify whether you get the PHP application page.
- Create a Green environment with a Node.js application.
- Access the Green environment’s URL and verify whether you get the Node.js application page.
- From the Green environment, initiated a swap of the environment URLs
- Verify whether the green environment’s URL is swapped with blue environment’s URL.
- Access the new URL of the green environment and verify whether you are getting the Node.js application page.
Task 1: Launching Lab Environment
- Launch lab environment by clicking on . This will create an AWS environment with the resources required for this lab.
- Once your lab environment is created successfully, will be active. Click on , this will open your AWS Console Account for this lab in a new tab. If you are asked to logout in AWS Management Console page, click on the here link and then click on again.
- If you have logged into other aws accounts in the same browser, after clicking on the , you will be redirected to a page asking you to logout from the other aws account.
|Note : If you have completed one lab, make sure to sign out of the AWS account before starting a new lab. If you face any issues, please go through FAQs and Troubleshooting for Labs.|
Task 2: Creating an Elastic BeanStalk Application
- Click on and select under the section.
- In the Elastic BeanStalk dashboard, click on
- Application Name : Enter whizlabs_beanstalk_application
- Leave the rest as default.
- Do not choose the Platform also. Click on .
- Ignore the Error Message and click on Applications on the left menu and Refresh the console.
- You will see an Application created.
Task 3: Creating Elastic Beanstalk Blue Environment
- Once you have created the whizlabs_beanstalk_application you initially have no environments associated with the application.
- You need to Create a new environment for the whizlabs_beanstalk_application. To do so, click on
- On the Select Environment Tier page, select the Web server environment and then click on Select.
- On the Create a web server environment page (under Environment Information) provide the Environment name as: whizlabs-blue-environment
Note: The environment name should be unique, if you face any errors while providing the name, then provide a different name.
- In the platform, under Managed platform choose PHP from the dropdown.
- Under the Application Code, select Sample application and then click on .
- The environment will take 5 to 10 minutes to provision the resources. Be patient until the environment setup is complete. In the meantime, you can see the resources being provisioned one-by-one
- Once the whizlabs-blue-environment is provisioned, you will get a page with Health status as ok and with a URL for the environment.
- Click on the URL at the top-right corner to be navigated to the PHP application page, as shown below:
Task 4: Creating Elastic Beanstalk Green Environment
- From the Elastic Beanstalk Application dashboard, click on whizlabs_elasticbeanstalk_application at the top and then click on the Create New environment from the dropdown.
- Select the Environment Tier page , then select the Web server environment and click on Select
- In the Environment information section, provide the Environment name as whizlabs-green-env (Environment name should be unique, if you face any errors while providing the name, provide a different name).
- In the platform, under Managed platform choose Node.Js from the dropdown.
- Under the Application Code, select Sample application and then click on .
- The environment will take 5 to 10 minutes to provision the resources. Be patient until the environment is provisioned. In the meantime, you can see the resources being provisioned one-by-one.
- Once the whizlabs-green-env is set up, you will get a page with Health status as ok and with a URL for the environment.
- Click on the URL at the top-right corner to be navigated to the Node.js application page, as shown below:
Task 5: Swapping the URLs from Blue to Green
- Now we have two environments namely whizlabs_blue_environment with PHP and whizlabs_green_environment with Node.js
- Next we will need to swap the URLs.
- In the Elastic BeanStalk application dashboard from whizlabs_green_env, click on Actions and select Swap Environment URLs.
- Choose the Environment name as whizlabs-blue-environment from the dropdown in the Select an Environment to Swap section and then click on Swap.
- The swap will take a few seconds to complete. You will see the Successfully completed status under Recent Events.
- Once the Swap is completed, note that the URL of the whizlabs_green_env note that replaced with that of the whizlabs_blue_environment.
- Now Click on the URL (which was the URL for the whizlabs_blue_environment) and notice the content of whizlabs_green_env instead.
NOTE: After swapping the URLs, if the new page contents don’t show up, then clear the browser cache or try to access the URL from a different browser.
Task 6: Validation Test
- Once the lab steps are completed, please click on the button on the right side panel.
- This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.
- Sample output :
Completion and Conclusion
- You have successfully created an Elastic BeanStalk application.
- You have successfully created a Blue environment with a PHP application.
- You have successfully accessed the Blue environment’s URL and verified that the content of the URL is a PHP application page .
- You have successfully created a Green environment with Node.js application.
- You have successfully accessed the Green environment’s URL and verified that the content of the URL is Node.js application page.
- From the Green environment, you have successfully initiated a swap of the environment URL.
- You have successfully verified that the green environment’s URL is swapped with that of blue environment.
- You have successfully accessed the new URL of the green environment and verified that the content of the URL is Node.js application page.