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: