示例#1
0
 public void TerminateInstance(string instanceId)
 {
     TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest()
     {
         InstanceId = new List <string>()
         {
             instanceId
         }
     };
     var terminateInstancesResponse = amazonEc2.TerminateInstances(terminateInstancesRequest);
 }
示例#2
0
        public void terminate(string instanceId)
        {
            try
            {
                TerminateInstancesRequest request = new TerminateInstancesRequest();
                request.InstanceId.Add(instanceId);

                TerminateInstancesResponse response = _service.TerminateInstances(request);
            }
            catch (AmazonEC2Exception ex)
            {
                throw new Exception("Caught Exception: " + ex.XML);
            }
        }
        /// <summary>
        /// The TerminateInstances operation shuts down one or more instances. This
        /// operation is idempotent; if you terminate an instance more than once, each call
        /// will succeed.
        /// Terminated instances will remain visible after termination (approximately one
        /// hour).
        /// 
        /// </summary>
        /// <param name="service">Instance of AmazonEC2 service</param>
        /// <param name="request">TerminateInstancesRequest request</param>
        public static void InvokeTerminateInstances(AmazonEC2 service, TerminateInstancesRequest request)
        {
            try 
            {
                TerminateInstancesResponse response = service.TerminateInstances(request);
                
                
                Console.WriteLine ("Service Response");
                Console.WriteLine ("=============================================================================");
                Console.WriteLine ();

                Console.WriteLine("        TerminateInstancesResponse");
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata  responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }
                if (response.IsSetTerminateInstancesResult())
                {
                    Console.WriteLine("            TerminateInstancesResult");
                    TerminateInstancesResult  terminateInstancesResult = response.TerminateInstancesResult;
                    List<TerminatingInstance> terminatingInstanceList = terminateInstancesResult.TerminatingInstance;
                    foreach (TerminatingInstance terminatingInstance in terminatingInstanceList)
                    {
                        Console.WriteLine("                TerminatingInstance");
                        if (terminatingInstance.IsSetInstanceId())
                        {
                            Console.WriteLine("                    InstanceId");
                            Console.WriteLine("                        {0}", terminatingInstance.InstanceId);
                        }
                        if (terminatingInstance.IsSetShutdownState())
                        {
                            Console.WriteLine("                    ShutdownState");
                            InstanceState  shutdownState = terminatingInstance.ShutdownState;
                            if (shutdownState.IsSetCode())
                            {
                                Console.WriteLine("                        Code");
                                Console.WriteLine("                            {0}", shutdownState.Code);
                            }
                            if (shutdownState.IsSetName())
                            {
                                Console.WriteLine("                        Name");
                                Console.WriteLine("                            {0}", shutdownState.Name);
                            }
                        }
                        if (terminatingInstance.IsSetPreviousState())
                        {
                            Console.WriteLine("                    PreviousState");
                            InstanceState  previousState = terminatingInstance.PreviousState;
                            if (previousState.IsSetCode())
                            {
                                Console.WriteLine("                        Code");
                                Console.WriteLine("                            {0}", previousState.Code);
                            }
                            if (previousState.IsSetName())
                            {
                                Console.WriteLine("                        Name");
                                Console.WriteLine("                            {0}", previousState.Name);
                            }
                        }
                    }
                }

            } 
            catch (AmazonEC2Exception ex) 
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
            }
        }