Stop AWS EC2 with automated Lambda script
Earlier, in this blog, I have posted utility script on stopping the running EC2 instances in any account automatically, using Lambda scripts and Cloudwatch cron scheduler
Now let us see how the EC2 instances can be started automatically by scheduled time, say 9AM
- Login to your AWS account
- Open EC2 console screen and open and add the tag value 'start' as key and 'value:yes' if EC2 instances has to be started automatically; Script will respond only to this key-value tags, and if you need, you can amend the script to read other tag[key-values]
- Download the script from my github public account[https://github.com/gvnirmalaa/utilities/blob/master/l_startEC2_UseTags.py]
- Create new lambda function in AWS console and place this code after selecting script as Pythonxx
- Now tag the cloud watch event
- Under cloud watch -> create rule -> Event source(scheduler) -> here set the time lines to stop the EC2 in your account, according to your requirement; ex., I have set to 9AM
- Under 'Add Target' -> Lambda function -> select the new lambda function you just created in step 2
- Click on configure details and yes, an automated EC2 start nstance action is automated
No comments:
Post a Comment