Save Cost on EC2 - ShutDown All EC2 at Night
Shutdown EC2 periodically to save cost
Many a times you might forget to shutdown ec2 after late night learning and forget to turn off your ec2 instances. This article focuses on to Shutdown EC2 periodically to save cost
Task
Create a Lambda function that shutdowns ec2 instances periodically using AWS CloudWatch Events.
This task is achieved using two ways 1. Manually (Recommended for first time practise) 2. Automated using CloudFormation (Recommended for saving time)
2. Automated using CloudFormation IaaC Template
I like automating things. So here is the how to achieve this
- Create an IAM Role for CloudFormation to deploy stacks and create resources. Skip if you already have a role.
- GoTo AWS Console. Goto ClouFormation and Create a Stack.
- Pass Params to CloudFormation
- Select IAM Role for CloudFormation to create stacks.
- Checkbox CAPABILITY IAM as Ticked
- Deploy Stack. Wait for Stack to deploy.
- Check for ec2 instances if they are running or stopped.