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&nbsp;<strong>AWS Lambda Function</strong>&nbsp;that automatically shuts down an EC2 instance when it&rsquo;s idle for more than 30 minutes, you can use a combination of&nbsp;<strong>AWS Lambda</strong>&nbsp;, CloudWatch Events, and IAM roles. Here&rsquo;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&nbsp;<strong>JSON</strong>&nbsp;code snippet below is the policy in&nbsp;<strong>json</strong>&nbsp;format</p> <p><a href="https://awstip.com/ec2-auto-shutdown-with-lambda-1558f456f615"><strong>Click Here</strong></a></p>
Tags: Auto shutdown