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 steps to launch an EC2 Spot Instance using the AWS Management Console. It will help learners to understand the differences between higher and lower spot instance prices and how they can set the maximum price for spot instances
  2. Duration: 1 hour
  3. AWS Region: US East (N. Virginia) us-east-1

Introduction

What is EC2 Spot Instance

  • EC2 Spot Instances allow you to bid on unused EC2 capacity in a specific AWS region.
  • The hourly cost of an EC2 Spot Instance can fluctuate depending on supply and demand.
  • You can save up to 90% on EC2 instance costs compared to On-Demand pricing.
  • EC2 Spot Instances can be terminated by AWS at any time if the Spot price goes above your bid price, or if AWS needs the capacity for other purposes.
  • You can use EC2 Spot Instances for fault-tolerant and flexible workloads that can handle interruptions, such as batch processing, data analysis, and testing environments.
  • EC2 Spot Instances can be launched using the same process as regular EC2 instances, and can be integrated with other AWS services like Auto Scaling Groups and Spot Fleets.
  • If your EC2 Spot Instance is terminated by AWS, you will not be charged for the partial hour of usage. However, if you terminate the instance yourself, you will be charged for the entire hour.

Architecture diagram

Task details

  1. Sign into AWS Management Console.
  2. Select an Amazon Linux Spot Instance from an Amazon Linux AMI.
  3. Setting the price of a spot instance to Higher and lower values compared to a given value.
  4. Launch the Spot Instance, to understand the difference between higher and lower prices.
  5. Explore the Spot request, Saving Summary, and Pricing history options.
  6. Test HTML page is launched or not using public IP.
  7. 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 username, 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 Username 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: Launching an EC2 Instance

In this task, we will launch and manage an EC2 Spot Instance, while also gaining an understanding of how spot pricing works and learning how to set a maximum price for instances in order to save costs
  1. Make sure you are in US East (N. Virginia) us-east-1 Region.
  2. Navigate to EC2 by clicking on the Services menu in the top, then click on EC2 in the Compute section.
  3. Navigate to Instances on the left panel and click on Launch instances button.
  1. Enter name as MySpotInstance
  2. Choose an Amazon Machine Image (AMI): Search for Amazon Linux 2023 AMI in the search box and click on the select button.
  3. Choose an Instance Type: Select t2.micro
  1. For Key pair : Choose Proceed without a key pair.
  2. Under Network Settings, Click on Edit button
  • Auto-assign public IP : Select Enable
  • Choose Create security group.
  • Security group name: Enter MyEC2Server_SG
  • Description: Enter Security Group to allow traffic to EC2
  • To add SSH,
    1. Choose Type: SSH
    2. Source: Select Anywhere
  • For HTTP, Select Add Security rule Button
    1. Choose Type: HTTP
    2. Source: Select Anywhere
  1. Under Advanced Details,
  • Purchasing option: Check the Spot instance option
  • Click on Customize Spot instance options.
  • Maximum price : Choose Set your maximum price(per instance/hour)
  • Set $ 0.003 as the price.
  • Request Type : Choose One-time
  • Valid to : Choose No request expiry date.
  • Persistent request: we will not choose the option, but you should know what that means. Below is the explanation A persistent Spot Instance request remains active until it expires, or you cancel it, even if the request is fulfilled. If capacity is not available, your Spot Instance is interrupted. After your instance is interrupted, when capacity becomes available again, the Spot Instance is started if stopped or resumed if hibernated. You can stop a Spot Instance and start it again if capacity is available. If the Spot Instance is terminated (irrespective of whether the Spot Instance is in a stopped or running state), the Spot Instance request is opened again and Amazon EC2 launches a new Spot Instance.
  1. Under the User data section, enter the following script, (which creates an HTML page served by Apache)
#!/bin/bash
systemctl enable httpd
  1. Keep rest thing Default and Click on Launch Instance Button.
  2. If you get an error message stating that your Maximum price is less than the current price shown in the Availability zone and Current Price table, click on “Edit instance config” and set the Maximum price to $0.01, then click on “Launch Instances.”
  3. Wait for the instances to launch. Navigate to the Instances page from the left menu and wait for the status of the EC2 Instance to change to “running” and the health check status to change to “2/2 checks passed.”
  1. To test if the HTML page is published, copy the Public IPv4 Address of your EC2 Instance and run it on the browser. Make sure the URL Protocol is http and not https.

Task 3: View the Spot Request

  1. Click on Spot Requests in the left sidebar, you will see the Spot requests.
  1. Click on the Request ID, to see more details about your spot request.
  • Max price: The maximum price you are willing to pay per hour for the Spot instance. Spot instances are available at variable prices, and your request will be fulfilled as long as the current price is below your specified maximum price.
  • Instance ID: This is the unique identifier for the specific instance you are requesting. It can be specified if you have a preference for a particular instance type or configuration.
  • Interruption: Interruptions occur when the Spot price goes above your specified maximum price or when Amazon EC2 needs the capacity back for On-Demand instances. When an interruption occurs, your Spot instance will be terminated, and you will receive a notification before it happens.
  • Availability Zone: Current Price of the Spot instance varies by Availability Zone, There might be a possibility that in other AZ you can get the same instance at a lower price.

Task 4: Explore the Saving Summary and Pricing history

In this task, we are going to explore the different cost-saving options available when using EC2 Spot Instances
  1. Click on the Spot Requests in the Left sidebar and you will see the Spot requests.
  2. Let’s explore two options named Spot saving summary and Pricing history.
  3. Below the Spot Request you’ll be able to see the Spot Saving Summary. You will save a total of 75% as compared to on-demand instances. Details are also available.
It’s important to note that Spot prices are dynamic and can vary significantly over time. Therefore, savings percentages may continue to fluctuate based on market conditions and the utilization of your Spot instance.
  1. Now click on the Pricing history option on the top right.
  2. Here you will see the pricing history, but wait a minute, it’s showing for some other Instance size, let’s modify the options.
  • Graph: Availability Zones
  • Instance type: Enter t2.micro
  • Platform**: Linux/UNIX**
  • Date Range**: Select 3 months**
Do you know?Amazon announced a new feature called “AWS Spot Instance Draining” that helps customers manage stateful workloads running on Spot Instances. This feature enables customers to configure their instances to gradually wind down workloads instead of being abruptly terminated, giving applications time to complete important tasks and minimize disruption. This can be especially useful for applications that store data on local instance storage or perform other stateful operations.

Task 5: Validation Test

  1. Once the lab steps are completed, please click on the Check my work 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 created and launched Amazon EC2 Spot Instance.
  2. You have successfully created a webpage and published it.

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:
  • Launch EC2 AMI type Amazon Linux — Check whether the EC2 instance is launched using an Amazon AMI.
  • Install Apache Web Server — Check whether Apache Web Server is installed in EC2 Instance or not.