/// <summary> /// Attach a previously created volume to a running instance. /// /// </summary> /// <param name="service">Instance of AmazonEC2 service</param> /// <param name="request">AttachVolumeRequest request</param> public static void InvokeAttachVolume(AmazonEC2 service, AttachVolumeRequest request) { try { AttachVolumeResponse response = service.AttachVolume(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" AttachVolumeResponse"); if (response.IsSetAttachVolumeResult()) { Console.WriteLine(" AttachVolumeResult"); AttachVolumeResult attachVolumeResult = response.AttachVolumeResult; if (attachVolumeResult.IsSetAttachment()) { Console.WriteLine(" Attachment"); Attachment attachment = attachVolumeResult.Attachment; if (attachment.IsSetVolumeId()) { Console.WriteLine(" VolumeId"); Console.WriteLine(" {0}", attachment.VolumeId); } if (attachment.IsSetInstanceId()) { Console.WriteLine(" InstanceId"); Console.WriteLine(" {0}", attachment.InstanceId); } if (attachment.IsSetDevice()) { Console.WriteLine(" Device"); Console.WriteLine(" {0}", attachment.Device); } if (attachment.IsSetStatus()) { Console.WriteLine(" Status"); Console.WriteLine(" {0}", attachment.Status); } if (attachment.IsSetAttachTime()) { Console.WriteLine(" AttachTime"); Console.WriteLine(" {0}", attachment.AttachTime); } } } if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Console.WriteLine(" RequestId"); Console.WriteLine(" {0}", responseMetadata.RequestId); } } } 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); } }