Lightswitch and Janitor Patterns for AWS Cost Optimization

Lightswitch and Janitor Patterns for AWS Cost Optimization
Lightswitch and Janitor Patterns for AWS Cost Optimization

CLOUD LABS



Lightswitch and Janitor Patterns for AWS Cost Optimization

In this Cloud Lab, you’ll learn to automate resource management and cost optimization in AWS using Lightswitch and Janitor patterns.

9 Tasks

intermediate

1hr 30m

Certificate of Completion

Desktop OnlyDevice is not compatible.
No Setup Required
Amazon Web Services

Learning Objectives

A solid understanding of the Lightswitch and Janitor patterns for cost optimization in AWS
Hands-on experience implementing the Lightswitch pattern to turn off running resources efficiently
The ability to implement Janitor pattern to identify and terminate unused resources

Technologies
EventBridge logoEventBridge
Lambda logoLambda
Cloud Lab Overview

Managing cloud resources efficiently is crucial for optimizing costs and ensuring that resources only run when necessary. Without automation, manually controlling the start and stop times of EC2 instances can lead to increased operational overhead, unnecessary costs, and inefficient resource utilization. The Lightswitch and Janitor patterns offer automated solutions that help manage these resources with minimal effort.

In this Cloud Lab, you’ll first implement the complete Lightswitch pattern to automate the management of EC2 instances. You’ll begin by launching an EC2 instance to test the rules you’ll set up later. After that, you’ll provision the necessary IAM roles and create an AWS Lambda function to stop EC2 instances during non-business hours. Once the Lambda function is created, you’ll configure an EventBridge rule to automatically trigger the Lambda function at the scheduled time each day. After setting up the automation, you’ll test the Lightswitch pattern to ensure it stops the EC2 instances as expected.

After successfully testing the Lightswitch pattern, you’ll move on to implement the Janitor pattern. This will involve creating a separate Lambda function to identify and terminate stale instances that have been stopped for a certain period and configuring another EventBridge rule to trigger the Janitor Lambda function. Once the infrastructure is in place, you’ll perform testing to verify that the Janitor patterns are working as expected.

By completing this Cloud Lab, you’ll gain hands-on experience automating resource management using Lightswitch and Janitor patterns. You’ll learn to reduce cloud costs by scheduling instance stop/start actions and terminating stale instances. This will help you streamline operations and optimize resource utilization in your AWS environment.

Here’s a high-level architecture diagram of the infrastructure that you’ll create in this Cloud Lab:

Optimizing costs using Lightswitch and Janitor patterns
Optimizing costs using Lightswitch and Janitor patterns

Cloud Lab Tasks
1.Introduction
Getting Started
2.Set Up the Pre-Required Infrastructure
Launch an EC2 Instance
Create an IAM Role
3.Implement the Lightswitch Pattern
Create a Lambda Function
Create an EventBridge Rule
4.Implement the Janitor Pattern
Create a Lambda Function
Create an EventBridge Rule
5.Conclusion
Clean Up
Wrap Up
Labs Rules Apply
Stay within resource usage requirements.
Do not engage in cryptocurrency mining.
Do not engage in or encourage activity that is illegal.
Hear what others have to say
Join 1.4 million developers working at companies like