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

# Create a sample Web Application and monitor it in AWS X-Ray

> Hands-on lab · 40m

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/create-a-sample-web-application-and-monitor-it-in-aws-x-ray" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab Details

1. This lab walks you through the steps to deploy the sample web application using CloudFormation and monitor it using AWS X-Ray.
2. Duration: **40 minutes**
3. AWS Region: **US East (N. Virginia) us-east-1**

### Introduction

#### AWS X-Ray

1. X-Ray is a service provided by AWS to monitor requests to and from your application.
2. It collects data on the requests that the application serves and provides insight into data to identify and troubleshoot the root cause of the performance issue.
3. It helps developers to analyze and debug the application and shows a map of your application’s underlying components.
4. It helps to analyze both applications in development and in production, from monolithic applications to complex microservice applications.
5. It allows you to visualize relationships within highly distributed applications.
6. The colors in the X-Ray service graph represents the following:

   * Green: successful calls
   * Red: server faults
   * Yellow: client errors
   * Purple: throttling errors

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

2. 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.
3. The resources section plays an important role in template creation.
4. For example, to create an EC2 instance, a template shall consist of various parameters such as key name, image id, instance type.
5. 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 that holds a collection of stacks.

### Architecture Diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/001.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=536e5c2d799f383049cb05a0f1e7a7e0" alt="" width="1868" height="1534" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/001.png" />

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/002.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=a24572da147e69d62d789cdd1fe78289" alt="" width="813" height="580" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/002.png" />

### Task Details

1. Sign in to AWS Management Console
2. Create an S3 bucket.
3. Deploy a sample X-Ray application using CloudFormation.
4. Test the application.
5. Monitor the traffic in AWS X-Ray.
6. Clean up AWS Resources.

### Launching Lab Environment

1. To launch the lab environment, Click on the **Start 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

## Files you need

Download these before you start — the lab cannot be completed without them.

* [Download Zip](/images/saa-files/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/download-zip.zip)

## 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: Create an S3 bucket

In this task, we are going to create an S3 bucket by providing the required configurations and uploading the zip file as an object.

1. Make sure you are in the **US East (N. Virginia) us-east-1** Region.

2. Navigate to the **Services** menu at the top. Click on **S3** in the **Storage** section.

3. On the S3 Page, click on **Create bucket** button and fill in the bucket details.

   * Bucket type: **General purpose**

   * Bucket name: Enter ***mys3bucket\<Random\_Numbers>***

     * **Note:** S3 bucket name is globally unique, choose a name which is available.

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/003.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=d8dd711ed5fbd1d292234c98f1046d7e" alt="" width="1222" height="624" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/003.png" />

4. Leave other settings as default.

5. Click on **Create bucket** button. click on upload button and add this zip file. Click on the provided link to download the zip file

[https://labresources.whizlabs.com/f75f897b06660829dcdb8e4e50568c6c/whizlabs-aws-xray-node-sample-app.zip](https://labresources.whizlabs.com/f75f897b06660829dcdb8e4e50568c6c/whizlabs-aws-xray-node-sample-app.zip)

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/004.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=030ee91244b7ace34f7a3e766155b213" alt="" width="1862" height="589" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/004.png" />

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/005.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=a5f7a383fd2629d5537c7667ff2b0f99" alt="" width="1895" height="490" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/005.png" />

6. **Copy** the **Bucket name** and **Object name** for later use.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/006.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=94c2aa75e9c235d0b2508f0ce21efa7c" alt="" width="1898" height="515" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/006.png" />

#### Task 3: Deploy a sample X-Ray application using CloudFormation

1. Navigate to **CloudFormation** by clicking on **Services**, and click on **CloudFormation** under the **Management and Governance** section.
2. Before creating CloudFormation Stack, download this template.yaml and save it on your local machine.
3. Link:-  [https://labresources.whizlabs.com/f75f897b06660829dcdb8e4e50568c6c/template.yaml](https://labresources.whizlabs.com/f75f897b06660829dcdb8e4e50568c6c/template.yaml)
4. Navigate to IAM, search for the EC2 instance profile EC2AppObservabilityRoleProfile-\<random\_number>.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/007.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=c87df1c4877399a71143af1558e73b13" alt="" width="1573" height="406" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/007.png" />
5. The CloudFormation template will create below resources:

* Elastic Beanstalk application: host sample X-Ray application.
* IAM Role: used by the EC2 in Elastic Beanstalk.
* DynamoDB: store signup details.
* S3 bucket: store the template.
* SQS and SQS: decouple the application.

4. On the CloudFormation dashboard, click on **Create stack** button.

* Prepare Template: Select **Choose an existing template**
* Specify template: Select **Upload a template file**
* Click on **Choose file** and choose the **template.yml** from your local machine
* Click on the **Next button.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/008.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=3e34222f3f6c333665d8844f163f3d45" alt="" width="1356" height="722" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/008.png" />

5. On the **Specify stack details** page, provide the following details\*\*:\*\*

* Stack Name: Enter a name of your choice.
* EC2InstanceProfileName : Enter Profile name you copied earlier

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/009.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=a988b2ef005269f9f6e5cd630e197e7a" alt="" width="1003" height="207" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/009.png" />

* S3BucketName : Enter **S3 Bucket Name**
* S3ObjectKey : Enter **Object key**
* Subnet: **Select any subnet** from the dropdown (any default subnet)
* VPC: **Select the default VPC** from the dropdown
* Click on the **Next button.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/010.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=ab331171ea019315fdcd4d2540628d3e" alt="" width="2382" height="1236" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/010.png" />

6. On the **Configure Stack options** page, leave it as **default** and click on **Next** button in the bottom right corner.
7. Review the Stack and then click on **Submit** button.
8. Once you click on **Create Stack,** your stack (**template.yml**) will start deploying the sample application.
9. Initially, the stack status will be **CREATE\_IN\_PROGRESS** and it will create all the resources.
10. Wait for 10 minutes till the stack status changes to **CREATE\_COMPLETE.**

    * **Note: It will create an additional nested stack.**

      <img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/011.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=15dc2b71ac6739a7fd335d7d47231d1e" alt="" width="1591" height="741" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/011.png" />

#### Task 4: Test the Application

1. Navigate to Elastic Beanstalk from the Services menu and open the created environment.
2. Select the Elastic Beanstalk Environment, Copy the Elastic Beanstalk Environment URL (domain) from the environment details.
3. Open the copied domain in a new browser tab. It will open the sample X-Ray application.
4. Let’s generate some traffic by signing up for the application.
5. For this step, you can manually signup into the application. But you will **automate the process** by clicking on the **Start button**.
6. You should wait for **three minutes** and then click on the **Stop button**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/012.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=63220f2b968a0fcbc673f215dd3b70cf" alt="" width="981" height="886" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/012.png" />

7. Hence, you have successfully created a **few signup accounts** in the sample application.

8. To view the signup details, navigate to **DynamoDB** by clicking on the **Services** menu at the top and search for **DynamoDB** in the search bar.

9. Click on the **Explore table items** button from the left navigation panel and **Select** the table created.

10. You can view the signup details.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/013.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=68716847963d45403c3850a2326abce4" alt="" width="1021" height="635" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/013.png" />

#### Task 5: Monitor the traffic in AWS X-Ray

1. Go to the **CloudWatch** by clicking the **Services** menu at the top and search for **CloudWatch** in the search bar.
2. Now click on **Trace map** from left navigation menu under the **Application Signals (APM)**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/014.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=313617ef6fa27af60d7d644f9866aad4" alt="" width="504" height="650" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/014.png" />
3. In the service map, you will get insight into the traffic that flows through our application.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/015.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=8a0d70e4192427cab3eef96e31e4b46e" alt="" width="1268" height="509" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/015.png" />

* **Note: If you got a warning as Data not found, then click on 5 minutes at the top right corner and select 1 hour.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/016.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=3efa402ebd1279a777e784e2102c05b4" alt="" width="397" height="33" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/016.png" />

3. Now click on any of the components to view the response distribution.
4. It will show the traffic response status along with the graph.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/017.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=e7e3eec2628b6d920cca84c9984265f6" alt="" width="1808" height="434" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/017.png" />

5. Click on the **Analyze Traces** to view detailed information.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/W4cMlDeUlYUkURKo/images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/018.png?fit=max&auto=format&n=W4cMlDeUlYUkURKo&q=85&s=2a662114401982e39704a59b478e1816" alt="" width="1609" height="760" data-path="images/labs/create-a-sample-web-application-and-monitor-it-in-aws-x-ray/018.png" />

6. It will show detailed information about **HTTP Method, URL, User-Agent, HTTP Method, Trace List, etc**.
7. You can click on any of the **Trace List** to view the traces.
8. You can also filter the traces by clicking on **Question mark(?)** at the top right corner.

#### Task 6: Clean up AWS Resources

##### Delete CloudFormation Stack

1. Make sure you are in the **N.Virginia** Region.
2. Navigate to **CloudFormation** by clicking on the **Services** menu at the top and search for **CloudFormation** in the search bar.
3. Select the **whizlabs-xray-stack** stack and click on the **Delete** button.
4. Now click on the **Delete stack** button in the prompt.
5. Now, wait till your stack deletion is completed. It will also delete the nested stack.

### Completion and Conclusion

1. You have successfully navigated to the X-Ray application.
2. You have successfully deployed a sample X-ray application.
3. You have successfully tested the application.
4. You have successfully monitored the traffic in X-Ray.
5. You have successfully deleted the AWS Resources.

### 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** from your 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.
* **Create Amazon DynamoDB Table** — Check whether a DynamoDB Table is created or not.
* **Create acl enabled S3 bucket** — Check whether an S3 Bucket is created with acl enabled or not
* **check s3 object** — Check whether an object is uploaded to the S3 bucket.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.