How to start an Amazon EC2 instance programmatically in .NET

前端 未结 5 1792
醉话见心
醉话见心 2020-12-28 09:03

I have been attempting to start an instance of EC2 in C# without luck.

When passing in an instance id to start the instance I get an error that the instance cannot b

5条回答
  •  Happy的楠姐
    2020-12-28 09:36

    try this.

    var startRequest = new StartInstancesRequest
                        {
                            InstanceIds = new List() { instanceId }
                        };
                    bool isError = true;
                    StartInstancesResponse startInstancesResponse = null;
                    while (isError)
                    {
                        try
                        {
                            startInstancesResponse=amazonEc2client.StartInstances(startRequest);
                            isError = false;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                            isError = true;
                        }
                    }
    

提交回复
热议问题