EC2 Instance Bootstrapping

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. In this lab, we configure a web server to corporate standards, noting how much effort it can take to walk through these steps manually each time. We then learn how to bootstrap an instance using a user data script, allowing us to automatically build servers. By the end of this lab, the user will understand what an EC2 bootstrap script is and how to use one to automate one of the most tedious parts of server building.

Note: On the EC2 service dashboard, toggle the “New EC2 Experience” toggle in the top left to the off position to match with the lab videos. Our maintenance team has been alerted to the AWS UI change to help in the lab’s update.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Manually Install Software on webserver-01

"Note: On the EC2 service dashboard, toggle the "New EC2 Experience" toggle in the top left to the off position to match with the lab videos. Our maintenance team has been alerted to the AWS UI change to help in the lab’s update."

On the instance webserver-01, which is already setup in the AWS Account, complete the following tasks:

  • Update the cache of available packages using the Aptitude Package Manager
  • Install the Apache2 Web Server, and ensure you can connect to it using your browser
  • Install the unzip utility, and use it to download and install the AWS CLI v2
  • Build a new index.html file for Apache to include the following details, gathered from the instance metadata service
    • Availability Zone
    • Instance ID
    • Public IP
    • Private IP Address
  • Confirm that the new page loads in your browser
Use a Bootstrap Script to Build webserver-02 and Debug Issues

We will now create an instance to be configured the same as above, but accomplished using bootstrapping instead of manual configuration.

Create a new EC2 instance running Ubuntu Server 20.04. Ensure it is created with a Public IP, using the EC2SecurityGroup, and with the name webserver-02. When creating the instance, use the bootstrap script provided on the A Cloud Guru GitHub:

https://github.com/ACloudGuru-Resources/course-aws-certified-solutions-architect-associate/blob/main/lab/ec2-instance-bootstrapping/webserver-02.sh

After launching the instance:

  • Use aws --version to confirm that the correct version of the CLI is installed
  • Use ps to confirm that Apache is running

Note that despite the bootstrap script attempting to install mysqld, it isn’t present on the server. We will troubleshoot this in the next objective.

Use a Fixed Bootstrap Script to Build webserver-03

Lastly, we will use a modified version of our previous bootstrap script to configure a third web server.

When configuring webserver-02, our script attempted to install mysqld, but it failed to complete. Before setting up webserver-03, we will need to fix the bootstrap script which we used on webserver-02.

Analyze the bootstrap script for webserver-02, and resolve the issue that would have prevented mysqld from installing, then run the lab. The fully repaired bootstrap script is also available in the Lab Guide when running this lab in Guided mode (not available in Challenge mode).

Tip! Remember that bootstrap scripts can’t require user interaction. Check the commands used to install other packages to identify the difference

Build the instance using the same specifications as previously, but with the name webserver-03, and the repaired bootstrap script. Login to the instance, and use ps to confirm that mysql is running as expected.

Additional Resources

For coverage on the lab's topics, see:

  • EC2 Metadata and User Data https://learn.acloud.guru/course/certified-solutions-architect-associate/learn/c91a47a3-9bdd-424e-89dd-71c9c866d736/07e8512f-3e4a-4950-9650-c63658c366e1/watch
  • Security Groups and Bootstrap Scripts https://learn.acloud.guru/course/certified-solutions-architect-associate/learn/c91a47a3-9bdd-424e-89dd-71c9c866d736/4cd7b523-0cb7-49ae-b7ee-4089a6a83872/watch For related AWS documentation, see:
  • Run commands on your Linux instance at launch: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
  • Retrieve instance metadata https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
  • Work with instance user data
  • https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-add-user-data.html

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?