0

i wanted to automate the ec2 instance's start & stop and configured the crontab on an instance x. I followed these steps

1) Edited the crontab -e of instance X.

2) and added these lines

15 04 * * * username ec2-start-instances i-f1814c90

15 07 * * * username ec2-stop-instances i-f1814c90

10 10 * * * username ec2-start-instances i-f1814c90

3) and restarted the cron using sudo /etc/init.d/cron restart

But still am unable to either start or stop the ec2 instance using cronjob.

thanks,

Anand

Sangram Anand
  • 10,526
  • 23
  • 70
  • 103
  • Can you paste the `stderr` & `stdout` for those commands? If you donn't have one, then redirect them to a file and then post it here. – Rakesh Sankar Aug 18 '11 at 03:44

3 Answers3

0

This is why AWS Data Pipeline is for (working fine):

https://aws.amazon.com/premiumsupport/knowledge-center/stop-start-ec2-instances/

Just mind the trap: --region eu-west-1 NOT --region eu-west-1a (which is an availability zone).

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
user3526918
  • 661
  • 6
  • 9
0

I'd suggest to Schedule EC2 Start / Stop using AWS Lambda

You don't need anything more than a small script or two that you schedule. No instance to launch, just a quick invocation of the script you have built. Pick the programming language of your choice and use the AWS SDK to perform instance operations. A quite lightweight solution,.

Community
  • 1
  • 1
eQ19
  • 9,880
  • 3
  • 65
  • 77
0

Most likely the issue is that the AWS data need to run the ec2 start and stop commands are not in the cron environment.

Its better to write a separate script that does this, instead of of making the ec2 commands on the cron like that.

dbers
  • 636
  • 5
  • 16