EC2 startup on schedule

后端 未结 11 796
后悔当初
后悔当初 2020-12-01 09:13

I need to start up an EC2 instance at (say) 6am every day. The constraints are that I\'d like to avoid having a computer running all day to do the startup or use a paid solu

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 09:59

    I just faced the same problem and solved it by using Autoscaling just as many of the answers here mentioned. The only thing you need for that is an AMI image that you want to run and the Autoscaling API command-line tools.

    After you downloaded the tools, follow the instructions in the readme to set the environmental variables and add your AWS credentials. Than put the following commands in a batch file (this example is for Windows):

    as-create-launch-config --key "MYLAUNCHCONFIGNAME" --instance-type t1.micro --image-id MYAMI-IMAGEID --launch-config "MYLAUNCHCONFIGNAME"
    as-create-auto-scaling-group --auto-scaling-group "MYSCALINGGROUPNAME" --launch-configuration "MYLAUNCHCONFIGNAME" --availability-zones "us-east-1a,us-east-1b,us-east-1c,us-east-1d" --min-size 0 --max-size 0
    
    rem Don't restart instance after shutdown
    as-suspend-processes "MYSCALINGGROUPNAME" --processes ReplaceUnhealthy
    
    rem Start instance at 22:15
    as-put-scheduled-update-group-action --name "startMyInstance" --auto-scaling-group "MYSCALINGGROUPNAME" --min-size 1 --max-size 1   --recurrence "15 22 * * *"
    
    rem Stop instance at 23:05
    as-put-scheduled-update-group-action --name "stopMyInstance" --auto-scaling-group "MYSCALINGGROUPNAME" --min-size 0 --max-size 0 --recurrence "05 23 * * *"
    

    Replace the capitalized names with some of your choice and set the correct AMI-ID for your AMI image. A new instance based on your AMI image will start at 22:15 and terminate at 23:05. Of course you can also change the instance type and availability zone(s).

提交回复
热议问题