![autoturn of ec2 at a time autoturn of ec2 at a time](https://miro.medium.com/max/1400/1*bWyFE2Ncf2wU5C9fzSFViQ.png)
- #Autoturn of ec2 at a time how to
- #Autoturn of ec2 at a time full
- #Autoturn of ec2 at a time code
- #Autoturn of ec2 at a time free
It assumes you want to control a specific instance id. If you just want to start and stop instances, here's another take on this which also make use of the Lambda service. These aren't generally necessary, but could be for someone so I'll include them.
#Autoturn of ec2 at a time code
The code for the lambda function is available on Github.
![autoturn of ec2 at a time autoturn of ec2 at a time](https://xan.manning.io/images/2017/11/lambda_ec2_shutdown.png)
There are metrics as well, so you can see when it runs, time it runs for, etc. If you want to see logs from your Lambda Function go into Cloudwatch Events. I've included my policies below in case they're helpful for anyone. The Lambda function runs using an "ec2 scheduler role" that the script creates. Whatever role you run this script as the same role and inline permissions are created within IAM. In retrospect this is obvious, but it wasn't obvious to me when I started. It specifies only the role used to run the CloudFormation script, it makes no difference to the resources created or the role used when the lambda function runs. The Permissions / IAM role section of the CloudFormation template is a red herring - ie it's largely irrelevant.
#Autoturn of ec2 at a time how to
I haven't spent the time to work out how to disable them, I just deleted it re-ran the Cloudformation template to reinstall.
#Autoturn of ec2 at a time free
Because the DynamoDB free tier doesn't expire most people are unlikely to be charged.
#Autoturn of ec2 at a time full
AWS have released a tool called the "Instance Scheduler", including a full configuration guide which is linked from that page.