Auto Shutdown and Start Amazon EC2 Instance

后端 未结 14 1135
执念已碎
执念已碎 2020-12-04 06:49

Can I automatically start and terminate my Amazon instance using Amazon API? Can you please describe how this can be done? I ideally need to start the instance and stop the

14条回答
  •  星月不相逢
    2020-12-04 07:07

    AutoScaling is limited to terminating instances. If you want to stop an instance and retain the server state then an external script is the best approach.

    You can do this by running a job on another instance that is running 24/7 or you can use a 3rd party service such as Ylastic (mentioned above) or Rocket Peak.

    For example in C# the code to stop a server is quite straightforward:

    public void stopInstance(string instance_id, string AWSRegion)
            {
                RegionEndpoint myAWSRegion = RegionEndpoint.GetBySystemName(AWSRegion);
                AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(AWSAccessKey, AWSSecretKey, myAWSRegion);
                ec2.StopInstances(new StopInstancesRequest().WithInstanceId(instance_id));
            }
    

提交回复
热议问题