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

# Introduction to Amazon 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/introduction-to-amazon-cloudformation" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab details

1. This lab will cover the basics of AWS CloudFormation Stack through creating a simple LAMP Server. The motive of this lab is to explore the functionality of an S3 bucket, demonstrate the process of creating a CloudFormation stack using an S3 Object URL, and guide participants through the installation of a PHP sample application.
2. Duration: **30 minutes**
3. AWS Region: **US East (N. Virginia) us-east-1**

### Introduction

#### LAMP Server

LAMP (Linux, Apache, MySQL, PHP/Perl/Python) is an acronym denoting one of the most common solution stacks for many of the web's most popular applications. However, LAMP now refers to a generic software stack model and its components are largely interchangeable.

* [Lamp Server Wiki](https://en.wikipedia.org/wiki/LAMP_\(software_bundle\))

#### AWS CloudFormation

1. CloudFormation is a service provided by AWS for designing our own infrastructure using code, i.e. infrastructure as code.
2. Currently, CloudFormation supports two languages, **JSON and YAML.** You can write your code with one of the languages.
3. CloudFormation comes with great features, being able to update your infrastructure whenever you want and also having the ability to delete the stack in case you don’t need it.
4. A fascinating feature of CloudFormation is that it saves more time in building infrastructure and helps in focusing on the development.
5. It is also possible to replicate our infrastructure in a short amount of time.
6. It eliminates human error and works according to the code you have written. It consists of two main components, **Stack and Templates.**

#### CloudFormation Template

1. It consists of various sections like

* AWS Template Format Version
* Description
* Metadata
* Parameters
* Mappings
* Conditions
* Resources **(Required Field)**
* Outputs

3. It is not mandatory that the template requires all the above-mentioned sections. By using only the **Resources** section, we will be able to create a template.
4. The resources section plays an important role in the template creation.
5. For example, to create an EC2 instance, a template shall consist of various parameters such as key name, image ID, instance type.
6. It is also possible to create two resources in the same template and refer to one from another, i.e. attaching an elastic IP with an EC2 instance.

#### CloudFormation Stack

1. A stack consists of a collection of resources.
2. In other words, the stack consists of one or more templates.
3. The advantage of the stack is that it is easy to create, delete or update the collection of resources.
4. The advanced stacks have a nested stack which holds a collection of stacks.

### Architecture diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/001.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=c5464bfdde7c58cffe3c4d774c2d2a01" alt="" width="1280" height="600" data-path="images/labs/introduction-to-amazon-cloudformation/001.png" />

### Task details

1. Sign in to AWS Management Console.
2. Exploring templates in an S3 bucket.
3. Create CloudFormation Stack.
4. Testing
5. Validation of the lab.

### Launching the lab environment

1. To launch the lab environment, Click on the **Launch lab** 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 : Exploring templates in an S3 Bucket

1. Make sure you are in the **US East (N. Virginia) us-east-1** Region.
2. Navigate to the **services** menu in the top, click on **S3** in the **Storage** section.
3. You can see the bucket present with a name similar to **whizlabs.1400.54051021**. In your case, the name of the bucket might be **different numerics**.
4. Open that bucket and you will see **LAMP\_template.json** file.
5. Now copy the **Object URL** and save it in notepad.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/002.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=2c1a724184f4442926a77a3b1c28dfe0" alt="" width="2286" height="1122" data-path="images/labs/introduction-to-amazon-cloudformation/002.png" />
6. This given **LAMP\_template.json** contains the JSON code for launching the LAMP Server using Cloudformation.

#### Task 3 : Create Cloudformation Stack

1. Navigate to CloudFormation. Click **services**, click on **CloudFormation** in the **Management and Governance** section.
2. On the CloudFormation dashboard, click on **create stack**.

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

     * Template source: Select **Amazon S3 URL**
     * Amazon S3 URL: Paste the URL copied from earlier steps.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/003.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=bdd31b20650db9ce83be083f9d91bec7" alt="" width="2632" height="1116" data-path="images/labs/introduction-to-amazon-cloudformation/003.png" />

* Click on **Next.**

3. Specify stack Details

   * Stack name: Enter a unique stack name - ***MyFirstCFStack***
   * Parameters

     * DB Name : Enter a database name - ***MyDatabase***
     * DB Password : Enter a database password - ***whizlabsdb123***
     * DB Root Password : Enter database root password - ***whizlabsdbroot123***
     * DB User : Enter the database username - ***WhizlabsDBUser***
     * Instance Type : Select **t2.micro**
     * Key Name : Select the key from the list name ***whizlabs-key***
     * SSH Location : Enter ***0.0.0.0/0***
     * Click on **Next.**

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/004.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=4fa376072bdc78b37131156ee9cfca1d" alt="" width="2316" height="1160" data-path="images/labs/introduction-to-amazon-cloudformation/004.png" />

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/005.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=caf80c8683690ba96b873a05b631582a" alt="" width="2348" height="654" data-path="images/labs/introduction-to-amazon-cloudformation/005.png" />

4. Configure stack options :

   * Tags: Click on add new tag

     * Key : Enter ***Name***
     * Value : Enter ***MyCF***

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/006.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=f3ecdf8712934c68752a15b9a2912111" alt="" width="2272" height="616" data-path="images/labs/introduction-to-amazon-cloudformation/006.png" />
   * Permissions: No need to select for this lab, leave it blank.
   * Leave all other configuration fields as **default**.
   * Click on Next.

5. **Review:** Review your stack details and click on **Submit.**

6. Once you have clicked the create button, you will be redirected to the CloudFormation stack list. A sample screenshot is provided below.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/007.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=e63e81425c677ecc9c3e6dfb7cd35504" alt="" width="1002" height="379" data-path="images/labs/introduction-to-amazon-cloudformation/007.png" />

7. Status: You will see the status **CREATE\_IN\_PROGRESS.**

8. You need to wait around 1-5 minutes to complete the stack resource creation.

9. Click on the **refresh** button to see the updates.

10. Once your stack status changes to **Create Complete.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/008.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=f7f02de53ec1b593f0ff474104980e63" alt="" width="1222" height="528" data-path="images/labs/introduction-to-amazon-cloudformation/008.png" />

#### Task 4 : Testing

1. Navigate to the **outputs** tab and you will be able to see an **URL** similar to below. Click on the URL. This will take you to your server's home page.

   * **[http://ec2-18-212-56-170.compute-1.amazonaws.com/](http://ec2-18-212-56-170.compute-1.amazonaws.com/)**
2. If you see the PHP info and your database connection, it means you have completed a LAMP server setup with AWS CloudFormation. Sample screenshot provided below:

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/009.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=0e6878dcd488f3b99ff1f09d847d76ee" alt="" width="1222" height="790" data-path="images/labs/introduction-to-amazon-cloudformation/009.png" />

<Tip>
  **Do you know?**

  By using CloudFormation, you can manage your infrastructure more efficiently, reduce manual effort, ensure consistency, and achieve faster and more reliable deployments. It provides a scalable and flexible approach to infrastructure provisioning and management, making it a valuable tool for both small and large-scale AWS deployments.
</Tip>

#### Task 5 : Validation Test

1. Once the lab steps are completed, please click on the **Check my work** button on the right 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/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-cloudformation/010.gif?s=e9464741a968bdefb6a363adfa5599ff" alt="" width="1000" height="370" data-path="images/labs/introduction-to-amazon-cloudformation/010.gif" />

### Completion and conclusion

* You have successfully created a Lamp server setup using a new Cloudformation Stack with the help of the JSON template provided in the S3 bucket.
* You have successfully tested the new lamp server created by CloudFormation.

#### End lab

1. Sign out from the AWS Management Console.
2. Click on **End lab** button in the IP Lab Portal and wait till the process gets completed.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Create a CloudFormation Stack** — Check whether a CloudFormation stack is created or not.

## Related help

* [FAQs and Troubleshooting](/aws-cp/support/faqs-and-troubleshooting)
* [SSH into EC2 Instance](/aws-cp/support/ssh-into-ec2-instance)
