EC2 Auto-shutdown with Lambda
<p>What we are going to do throughout this project</p>
<ul>
<li>Creating IAM policy and Roles for lambda to stop and describe instances</li>
<li>Set Up AWS Lambda function</li>
<li>Create a Trigger with Event Rule</li>
<li>Identify Idle Instances with a python script in the lambda function</li>
<li>Implement the Shutdown by checking the last time they was an activity in the instance and subtracting it from the current time, if its equal to 1800 seconds (30 mins)</li>
<li>Test and Monitor your lambda function</li>
</ul>
<p>To create an <strong>AWS Lambda Function</strong> that automatically shuts down an EC2 instance when it’s idle for more than 30 minutes, you can use a combination of <strong>AWS Lambda</strong> , CloudWatch Events, and IAM roles. Here’s a high-level overview of the steps involved:</p>
<p>Head over to your AWS management console and search for IAM . Create an IAM policy:On the pane at the left click policy, at the top right corner click create policy, select json and paste the below <strong>JSON</strong> code snippet below is the policy in <strong>json</strong> format</p>
<p><a href="https://awstip.com/ec2-auto-shutdown-with-lambda-1558f456f615"><strong>Click Here</strong></a></p>