Overview
Lab Details
- This lab walks you through the steps to deploy the sample web application using CloudFormation and monitor it using AWS X-Ray.
- Duration: 40 minutes
- AWS Region: US East (N. Virginia) us-east-1
Introduction
AWS X-Ray
- X-Ray is a service provided by AWS to monitor requests to and from your application.
- 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.
- It helps developers to analyze and debug the application and shows a map of your application’s underlying components.
- It helps to analyze both applications in development and in production, from monolithic applications to complex microservice applications.
- It allows you to visualize relationships within highly distributed applications.
-
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
- CloudFormation is a service provided by AWS for designing our own infrastructure using code i.e infrastructure as code.
- Currently, CloudFormation supports two languages JSON and YAML. You can write your code with one of the languages.
- 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.
- A fascinating feature of CloudFormation is that it saves more time in building infrastructure and helps in focusing on the development.
- It is also possible to replicate our infrastructure in a short amount of time.
- It eliminates human error and works according to the code you have written. It consists of two main components, Stack and Templates.
Cloudformation Template
- It consists of various sections like
- AWS Template Format Version
- Description
- Metadata
- Parameters
- Mappings
- Conditions
- Resources (Required Field)
- Outputs
- 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.
- The resources section plays an important role in template creation.
- For example, to create an EC2 instance, a template shall consist of various parameters such as key name, image id, instance type.
- 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
- A stack consists of a collection of resources.
- In other words, the stack consists of one or more templates.
- The advantage of the stack is that it is easy to create, delete or update the collection of resources.
- The advanced stacks have a nested stack that holds a collection of stacks.
Architecture Diagram


Task Details
- Sign in to AWS Management Console
- Create an S3 bucket.
- Deploy a sample X-Ray application using CloudFormation.
- Test the application.
- Monitor the traffic in AWS X-Ray.
- Clean up AWS Resources.
Launching Lab Environment
- To launch the lab environment, Click on the Start Lab button.
- Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
- 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.Lab guide
Lab Steps
Task 1: Sign in to AWS Management Console
- Click on the Open Console button, and you will get redirected to AWS Console in a new browser tab.
-
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.
- 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.- Make sure you are in the US East (N. Virginia) us-east-1 Region.
- Navigate to the Services menu at the top. Click on S3 in the Storage section.
-
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.

-
Note: S3 bucket name is globally unique, choose a name which is available.
- Leave other settings as default.
- Click on Create bucket button. click on upload button and add this zip file. Click on the provided link to download the zip file


- Copy the Bucket name and Object name for later use.

Task 3: Deploy a sample X-Ray application using CloudFormation
- Navigate to CloudFormation by clicking on Services, and click on CloudFormation under the Management and Governance section.
- Before creating CloudFormation Stack, download this template.yaml and save it on your local machine.
- Link:- https://labresources.whizlabs.com/f75f897b06660829dcdb8e4e50568c6c/template.yaml
-
Navigate to IAM, search for the EC2 instance profile EC2AppObservabilityRoleProfile-<random_number>.

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

- 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

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

- On the Configure Stack options page, leave it as default and click on Next button in the bottom right corner.
- Review the Stack and then click on Submit button.
- Once you click on Create Stack, your stack (template.yml) will start deploying the sample application.
- Initially, the stack status will be CREATE_IN_PROGRESS and it will create all the resources.
-
Wait for 10 minutes till the stack status changes to CREATE_COMPLETE.
-
Note: It will create an additional nested stack.

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

- Hence, you have successfully created a few signup accounts in the sample application.
- 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.
- Click on the Explore table items button from the left navigation panel and Select the table created.
- You can view the signup details.

Task 5: Monitor the traffic in AWS X-Ray
- Go to the CloudWatch by clicking the Services menu at the top and search for CloudWatch in the search bar.
-
Now click on Trace map from left navigation menu under the Application Signals (APM)

- In the service map, you will get insight into the traffic that flows through our application.

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

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

- Click on the Analyze Traces to view detailed information.

- It will show detailed information about HTTP Method, URL, User-Agent, HTTP Method, Trace List, etc.
- You can click on any of the Trace List to view the traces.
- 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
- Make sure you are in the N.Virginia Region.
- Navigate to CloudFormation by clicking on the Services menu at the top and search for CloudFormation in the search bar.
- Select the whizlabs-xray-stack stack and click on the Delete button.
- Now click on the Delete stack button in the prompt.
- Now, wait till your stack deletion is completed. It will also delete the nested stack.
Completion and Conclusion
- You have successfully navigated to the X-Ray application.
- You have successfully deployed a sample X-ray application.
- You have successfully tested the application.
- You have successfully monitored the traffic in X-Ray.
- You have successfully deleted the AWS Resources.
End Lab
- Sign out of AWS Account.
- You have successfully completed the lab.
- 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.