Skip to main content
Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console. Open IP Lab Portal

Overview

Lab details

  1. This lab walks you through the provisioning of an EC2 instance using an AWS CloudFormation template.
  2. Duration: 30 minutes
  3. AWS Region: US East (N. Virginia) us-east-1

Architecture diagram

Task details

  1. Sign into the AWS Management Console.
  2. Understand the Cloudformation Template
  3. Create a CloudFormation Stack to provision an EC2 Instance
  4. Check the newly-provisioned EC2 instance
  5. Validation of the lab.

Launching the lab environment

  1. To launch the lab environment, Click on the Start button.
  2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
  3. Once the Lab is started, you will be provided with IAM user name, Password, Access Key, and Secret Access Key.
You can only start one lab at any given time

Lab guide

Lab steps

Task 1: Sign in to AWS Management Console

  1. Click on the Open console button, and you will get redirected to AWS Console in a new browser tab.
  2. On the AWS sign-in page,
    • Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
    • Now copy your User Name and Password in the Lab Console to the IAM Username and Password in AWS Console and click on the Sign in button.
  3. Once Signed In to the AWS Management Console, Make the default AWS Region as US East (N. Virginia) us-east-1.

Task 2: Understand the Cloudformation Template

In this task, you will explore the CloudFormation template used to provision an EC2 instance and understand its key components and parameters.
  1. Make sure you are in the US East (N. Virginia) us-east-1 Region.
  2. Navigate to Services menu at the top, then click on S3 in the Storage section.
  3. You will see a bucket present with a name similar to whizlabs.32665.95018693. In your case, the name of the bucket will have slightly different trailing numbers since all bucket names have to be globally unique.
  4. Open that bucket and select the Lab_AWS_EC2_Provisioning_template.json file.
  5. Click on the Download button and save the file to your local.
  6. Lab_AWS_EC2_Provisioning_template_json contains the JSON code for provisioning an EC2 instance using Cloudformation.
  7. Open the file in any text editor and go through the JSON configuration code provided.
  8. If you open the URL in a new browser tab, you will be able to see the JSON code used for creating the Cloudformation stack.
  9. Below are some important details provided in the Cloudformation template.
    • KeyName : Name of an existing EC2 KeyPair to enable SSH access to the instance. It must be the name of an existing EC2 KeyPair.
    • InstanceType : It is a WebServer EC2 instance type. It must be a valid EC2 instance type.
    • SSHLocation : The IP address range that can be used to SSH into the EC2 instances. It must be a valid IP CIDR range of the form x.x.x.x/x.
    • HTTPLocation : The IP address range that can be used for HTTP traffic to the EC2 instances. It must be a valid IP CIDR range of the form x.x.x.x/x.
    • ICMPLocation : The IP address range that can be used for ICMP traffic to the EC2 instances. It must be a valid IP CIDR range of the form x.x.x.x/x.
    • AWSInstanceType2Arch : Provides architecture type of EC2 Instance.
    • AWSRegionArch2AMI : Provides the region and AMI details of the EC2 instance.
    • EC2Instance : Details of the EC2 instance to be provisioned. It contains InstanceType, SecurityGroups, KeyName, ImageID etc.
    • InstanceSecurityGroup : Provides the security group details which will be attached to the EC2 instance.
    • Outputs : Once the EC2 is provisioned using this Cloudformation template, parameters found here will be displayed to the user for further use. It includes InstanceId, AZ, PublicDNS, and PublicIP.
  10. Next, copy the Object URL to the clipboard or make a note of it for use in the CloudFormation template. Choose the Lab_AWS_EC2_Provisioning_Using_CF.template.json object and click on Copy URL
  11. Next go to EC2 Services, Select Key Pair and click on Create Key pair.
  12. Enter whizlabs-key as Key pair name and click on Create Key Pair.

Task 3: Create an Cloudformation Stack to provision an EC2 Instance

In this task, you will create an AWS CloudFormation stack to provision an EC2 instance using a predefined template. The CloudFormation stack automates the process of setting up the necessary resources and configurations required for the EC2 instance.
  1. Make sure you are in the N.Virginia Region.
  2. Navigate to CloudFormation. Click Services, and then click on CloudFormation in the Management & Governance section.
  3. On the CloudFormation dashboard, click on Create Stack.
  4. Specify stack Details :
    • Stack name: Enter a unique stack name - MyEC2CFStack
    • As you can see below, the details are autoloaded. These details are loaded from Lab_AWS_EC2_Provisioning_Using_CF.template.json.
    • Parameters :
      • HTTPLocation : 0.0.0.0/0
      • ICMPLocation : 0.0.0.0/0
      • InstanceType : t2.micro
      • KeyName : Make sure to select the created Key Pair i.e., whizlabs-key
      • SSHLocation : 0.0.0.0/0
      • You can update the details if you want to or leave them as is.
      • Click on Next.
      • Ignore the following error.
  1. Configure stack options :
    • Tags
      • Key : Enter Name
      • Value : Enter MyEC2CF
    • Permissions: No need to select for this lab, you can leave it blank.
    • Leave all other configuration fields as default.
    • Click on Next.
  2. Review: Review your stack details and click on Create Stack.
  3. Once you click the create button, you will be redirected to CloudFormation stack list. A sample screenshot has been provided below:
  4. Status: You should see the status CREATE_IN_PROGRESS.
  5. You will need to wait around 1-5 minutes for the stack to finish creating.
  6. Click on the refresh button beside New events available to refresh the status.
  7. Once your stack status changes to CREATE_COMPLETE, it is done.

Task 4: Check the newly-provisioned EC2 instance

  1. Make sure you are in the N.Virginia Region.
  2. Navigate to the EC2 page from the Services menu under Compute section.
  3. Click on Instances in the left panel.
  4. The EC2 instance should have been provisioned with the following values:
    • Name : MyEC2CF
    • InstanceID : i-09e3768d977ca2c3c (As per the ec2 screenshot)
    • InstanceType : t2.micro
Do you know?CloudFormation Stack Sets enable you to provision and manage EC2 instances across multiple AWS accounts and regions simultaneously. With Stack Sets, you can deploy EC2 instances consistently across your entire organization, ensuring uniformity and simplifying management.

Task 5: Validation Test

  1. Once the lab steps are completed, please click on the Validate button on the left side panel.
  2. This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.
  3. Sample output :

Completion and conclusion

  1. You have successfully provisioned an EC2 Instance using Cloudformation Stack with the help of a Cloudformation JSON template.
  2. You have analyzed the JSON code to understand the various parameters within a Cloudformation template.

End lab

  1. Sign out of AWS Account.
  2. You have successfully completed the lab.
  3. Once you have completed the steps, click on End lab in the IP Lab Portal.

What gets checked

When you press Check my work, the platform verifies each of these:
  • Validate EC2 Instance Type t2.micro — Check whether the EC2 instance type is t2.micro.
  • Launch an EC2 Instance — Check whether an EC2 Instance is launched or not.
  • Launch EC2 AMI type Amazon Linux — Check whether the EC2 instance is launched using an Amazon AMI.
  • Create a CloudFormation Stack — Check whether a CloudFormation stack is created or not.