Friday, November 16, 2018

Start AWS EC2 with automated Lambda script


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 

  1. Login to your AWS account
  2. 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]
  3. Download the script from my github public account[https://github.com/gvnirmalaa/utilities/blob/master/l_startEC2_UseTags.py]
  4. Create new lambda function in AWS console and place this code after selecting script as Pythonxx
  5. Now tag the cloud watch event 
  6. 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
  7. Under 'Add Target' -> Lambda function -> select the new lambda function you just created in step 2
  8. Click on configure details and yes, an automated EC2 start nstance action is automated

No comments:

Post a Comment