Use AWS Instance Scheduler to Shut Down an EC2 instance

1 hour
  • 6 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we will deploy the AWS Instance Scheduler solution to shut down an EC2 instance based on a custom schedule we will create. Instance Scheduler can help you save money and provide cost optimization for workloads.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Deploy AWS Instance Scheduler
  1. Navigate to the AWS Instance Scheduler.
  2. Click Launch solution in the AWS Console.
  3. In the CloudFormation console, enter a name for our CloudFormation stack.
  4. Add tags:
    • started-by=InstanceScheduler
    • stopped-by=InstanceScheduler
Edit the DynamoDB Tables
  1. Navigate to DynamoDB > Tables.
  2. elect the ConfigTable.
  3. Select the uk-office-hours item.
  4. Click Actions > Duplicate.
  5. Change the description to "Office hours in US".
  6. Change the string to "us-office-hours".
  7. Change the time zone to "US/Eastern".
  8. Click Save and then refresh the table.
Add Tag to EC2 Instance
  1. Navigate to EC2 > Instances.
  2. Select the running instance.
  3. Add the following tag:
    • Key: Schedule
    • Value: us-office-hours
  4. Click Save.
Update Amazon EventBridge Events Rule
  1. Navigate to Amazon EventBridge > Events > Rules.
  2. Select the listed rule.
  3. Click Actions > Edit.
  4. Click Edit, then Next.
  5. Change the 0/5 minutes to 0/1 minute.
  6. Click Next, Next, Next.
  7. Click Update rule.
Update DynamoDB Config Table
  1. Navigate to DynamoDB > Tables.
  2. Click the ConfigTable.
  3. Update the endtime so the business day ends five minutes from your current time (e.g., if it’s 8 AM where you are right now, change the endtime to 08:05.)
  4. Click Save.
Verify EC2 Instance Stopped
  1. Navigate to EC2 > Instances.
  2. Verify our EC2 instance has stopped.

Additional Resources

As the senior engineer, you have been tasked with architecting a solution to turn off EC2 instances when they are not being used, especially after business hours. You have decided to use the AWS Instance Scheduler solution to automatically turn off your EC2 instances after business hours so your account receives an immediate cost savings each night.

The AWS Instance Scheduler link can be found here: https://aws.amazon.com/solutions/instance-scheduler/

To get started, log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

CloudWatch Event Rules are now found in Amazon EventBridge. To view DynamoDB items, click Explore table items.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?