Get a Pentest and security assessment of your IT network.

Cyber Security

Launch EC2 Spot Instances

TL;DR

This guide shows you how to launch an EC2 Spot Instance using the AWS Management Console and CLI, saving money on compute costs. We’ll cover requesting instances, checking their status, and terminating them when finished.

Launching a Spot Instance via the AWS Management Console

  1. Navigate to EC2: Open the AWS Management Console and go to the EC2 service.
  2. Request Spot Instances: In the left-hand navigation pane, under ‘Instances’, click ‘Spot Instances’. Then, click ‘Request Spot Instances’.
  3. Configure Instance Details:
    • Name and tags: Give your instance a descriptive name.
    • AMI (Amazon Machine Image): Choose the operating system you need.
    • Instance Type: Select an appropriate instance type based on your workload.
    • Spot bidding strategy: Choose ‘Request with lowest price’.
    • Number of instances: Specify how many Spot Instances you want to launch.
  4. Configure Capacity Optimised Allocation: Select whether or not to use capacity optimised allocation.
  5. Security Groups: Choose a security group that allows the necessary traffic to your instance.
  6. Key Pair (Login): Select an existing key pair, or create a new one if you don’t have one. This is essential for SSH access.
  7. Advanced Details: Configure user data if needed (e.g., scripts to run on startup).
  8. Review and Launch: Review your configuration and click ‘Request’.

Launching a Spot Instance via the AWS CLI

Before you start, make sure you have the AWS CLI installed and configured with appropriate credentials.

  1. Find an AMI ID: Use the aws ec2 describe-images command to find an AMI ID for your desired operating system. For example:
    aws ec2 describe-images --owners amazon --filters "Name=name,Values=*Amazon Linux 2*" --query 'Images[*].ImageId' --output text
  2. Request a Spot Instance: Use the aws ec2 request-spot-instances command. Replace placeholders with your values:
    aws ec2 request-spot-instances --image-id  --instance-type  --count  --security-group-ids  --key-name  --launch-specification file://launch-spec.json
  3. Create a Launch Specification (launch-spec.json): This JSON file defines the details of your instance.
    {
      "ImageId": "",
      "InstanceType": "",
      "SecurityGroupIds": [""],
      "KeyName": "",
      "UserData": "#cloud-confignpackage:n  update: truenwrite_files:n    - path: /tmp/startup.shn      permissions: '0755'n      owner: rootn      group: rootnruncmd:n    - /tmp/startup.sh" 
    }
  4. Check Spot Instance Request Status: Use the aws ec2 describe-spot-instance-requests command to check the status of your request:
    aws ec2 describe-spot-instance-requests --request-ids 

Checking Instance Status

Regardless of whether you use the console or CLI, you can check the status of your Spot Instances in the EC2 Management Console under ‘Instances’. Look for instances with a state of ‘running’ and an instance type that matches your request.

Terminating a Spot Instance

  1. Select the Instance: In the EC2 Management Console, select the Spot Instance you want to terminate.
  2. Terminate Instance: Right-click on the instance and choose ‘Instance State’ -> ‘Terminate’. Confirm your choice when prompted.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation