> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS EC2 Provisioning - Cloudformation

> Hands-on lab · 30m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/aws-ec2-provisioning-cloudformation" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## 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

<img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/001.png?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=c54aea4c7b6c686cc8820ddf6b2a95a2" alt="" width="880" height="280" data-path="images/labs/aws-ec2-provisioning-cloudformation/001.png" />

### 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**.

<Note>
  You can only start one lab at any given time
</Note>

## 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.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/002.jpg?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=579604d1a3f4067938c7fa342cb22856" alt="" width="715" height="84" data-path="images/labs/aws-ec2-provisioning-cloudformation/002.jpg" />
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.**

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/003.png?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=c6c996e6ec17bb6ae84420eaf4a5f97e" alt="" width="2898" height="1372" data-path="images/labs/aws-ec2-provisioning-cloudformation/003.png" />

#### 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**.

   * Prerequisite - Prepare template : Select **Choosing an existing template**
   * Specify Template :

     * Template source : Select **Amazon S3 URL**
     * Amazon S3 URL : Enter the S3 URL copied earlier.
     * **For example : [https://whizlabs44010075.s3.amazonaws.com/Lab\\\_AWS\\\_EC2\\\_Provisiong\\\_Using\\\_CF.template.json](https://whizlabs44010075.s3.amazonaws.com/Lab\\_AWS\\_EC2\\_Provisiong\\_Using\\_CF.template.json)**
   * Click on **Next**.
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**

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/004.png?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=d62e1b2780fbd311a2b50c979db73566" alt="" width="2046" height="1220" data-path="images/labs/aws-ec2-provisioning-cloudformation/004.png" />
     * You can update the details if you want to or leave them as is.
     * Click on **Next**.
     * Ignore the following error.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/005.png?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=27cf8545287cd179022f3fffe07e9e2e" alt="" width="356" height="51" data-path="images/labs/aws-ec2-provisioning-cloudformation/005.png" />

5. 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**.

6. **Review:** Review your stack details and click on **Create Stack.**

7. Once you click the **create** button, you will be redirected to CloudFormation stack list. A sample screenshot has been provided below:

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/006.png?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=a2577935292b59709bc0f936a2cdb86c" alt="" width="2788" height="956" data-path="images/labs/aws-ec2-provisioning-cloudformation/006.png" />

8. Status: You should see the status **CREATE\_IN\_PROGRESS.**

9. You will need to wait around 1-5 minutes for the stack to finish creating.

10. Click on the **refresh** button beside **New events available** to refresh the status.

11. Once your stack status changes to  **CREATE\_COMPLETE**, it is done.

    <img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/007.png?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=331c4e9a4905144d06623d10c2ab57d8" alt="" width="2802" height="998" data-path="images/labs/aws-ec2-provisioning-cloudformation/007.png" />

#### 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.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/008.png?fit=max&auto=format&n=qRudZfyc-Pm9Aad9&q=85&s=5c0fe9a830db04d7d7a81a11c5cb97ca" alt="" width="2444" height="1208" data-path="images/labs/aws-ec2-provisioning-cloudformation/008.png" />

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**

<Tip>
  **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.
</Tip>

#### 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 :

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/qRudZfyc-Pm9Aad9/images/labs/aws-ec2-provisioning-cloudformation/009.gif?s=8d6173671b8f92737db257be7550e9ee" alt="" width="1000" height="600" data-path="images/labs/aws-ec2-provisioning-cloudformation/009.gif" />

### 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.

## Related help

* [FAQs and Troubleshooting](/aws-cp/support/faqs-and-troubleshooting)
