protected override void ProcessRecord() { AmazonEC2 client = base.GetClient(); Amazon.EC2.Model.DeleteSnapshotRequest request = new Amazon.EC2.Model.DeleteSnapshotRequest(); request.SnapshotId = this._SnapshotId; Amazon.EC2.Model.DeleteSnapshotResponse response = client.DeleteSnapshot(request); }
// delete older snapshots to keep the list clean void PruneSnapShots(string volume_id) { try { DescribeSnapshotsRequest dsr = new DescribeSnapshotsRequest(); Filter f = new Filter(); f.Name = "volume-id"; f.Value.Add(volume_id); dsr.Filter.Add(f); dsr.Owner = "self"; var resp = aec.DescribeSnapshots(dsr); var list = resp.DescribeSnapshotsResult.Snapshot; list.Sort((Snapshot s1, Snapshot s2) => { return s2.StartTime.CompareTo(s1.StartTime); }); if (list.Count > snaps2keep) { for (int i = snaps2keep; i < list.Count; i++) { DeleteSnapshotRequest del_req = new DeleteSnapshotRequest(); del_req.SnapshotId = list[i].SnapshotId; aec.DeleteSnapshot(del_req); } } } catch (Exception e) { Console.WriteLine("Caught exception while pruning snapshots: " + e.Message); Console.WriteLine("Stacktrace: " + e.StackTrace); } }
public override void Execute() { Amazon.EC2.AmazonEC2Client client = new Amazon.EC2.AmazonEC2Client(AWSAuthConnection.OUR_ACCESS_KEY_ID, AWSAuthConnection.OUR_SECRET_ACCESS_KEY); List<string> snapshotsToDelete = new List<string>(); if (isVolumeId) { // delete snapshots belonging to this volume DescribeSnapshotsRequest request = new DescribeSnapshotsRequest(); DescribeSnapshotsResponse response = client.DescribeSnapshots(request); foreach (Amazon.EC2.Model.Snapshot s in response.DescribeSnapshotsResult.Snapshot) { if (string.Equals(s.VolumeId, id, StringComparison.InvariantCultureIgnoreCase)) { DateTime snapshotDate = DateTime.Parse(s.StartTime); if (snapshotDate.AddDays(days) < DateTime.Now) snapshotsToDelete.Add(s.SnapshotId); } } } else { snapshotsToDelete.Add(id); } foreach (string snapshotId in snapshotsToDelete) { Console.WriteLine("Deleting snapshot ID {0}", snapshotId); Amazon.EC2.Model.DeleteSnapshotRequest request = new Amazon.EC2.Model.DeleteSnapshotRequest(); request.SnapshotId = snapshotId; Amazon.EC2.Model.DeleteSnapshotResponse response = client.DeleteSnapshot(request); } }
/// <summary> /// Deletes the snapshot identitied by snapshotId. /// /// </summary> /// <param name="service">Instance of AmazonEC2 service</param> /// <param name="request">DeleteSnapshotRequest request</param> public static void InvokeDeleteSnapshot(AmazonEC2 service, DeleteSnapshotRequest request) { try { DeleteSnapshotResponse response = service.DeleteSnapshot(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" DeleteSnapshotResponse"); 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); } }
/// <summary> /// Delete the snapshop with the given ID from EBS /// </summary> /// <param name="p"></param> public static void DeleteSnapsot(string snapshotid) { AmazonEC2Client ec2 = CreateClient(); DeleteSnapshotRequest rq = new DeleteSnapshotRequest(); rq.SnapshotId = snapshotid; DeleteSnapshotResponse rs = ec2.DeleteSnapshot(rq); }
public void DeleteSnapshot(Ec2Key ec2Key, string snapshotId) { _logger.Debug("DeleteSnapshot Start."); AmazonEC2 ec2 = CreateAmazonEc2Client(ec2Key); var request = new DeleteSnapshotRequest {SnapshotId = snapshotId}; ec2.DeleteSnapshot(request); _logger.Debug("DeleteSnapshot End."); }
public override void Execute() { Amazon.EC2.AmazonEC2Client client = new Amazon.EC2.AmazonEC2Client(AWSAuthConnection.OUR_ACCESS_KEY_ID, AWSAuthConnection.OUR_SECRET_ACCESS_KEY); List <string> snapshotsToDelete = new List <string>(); if (isVolumeId) { // delete snapshots belonging to this volume DescribeSnapshotsRequest request = new DescribeSnapshotsRequest(); DescribeSnapshotsResponse response = client.DescribeSnapshots(request); foreach (Amazon.EC2.Model.Snapshot s in response.DescribeSnapshotsResult.Snapshot) { if (string.Equals(s.VolumeId, id, StringComparison.InvariantCultureIgnoreCase)) { DateTime snapshotDate = DateTime.Parse(s.StartTime); if (snapshotDate.AddDays(days) < DateTime.Now) { snapshotsToDelete.Add(s.SnapshotId); } } } } else { snapshotsToDelete.Add(id); } foreach (string snapshotId in snapshotsToDelete) { Console.WriteLine("Deleting snapshot ID {0}", snapshotId); Amazon.EC2.Model.DeleteSnapshotRequest request = new Amazon.EC2.Model.DeleteSnapshotRequest(); request.SnapshotId = snapshotId; //Amazon.EC2.Model.DeleteSnapshotResponse response = client.DeleteSnapshot(request); } }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.EC2.Model.DeleteSnapshotRequest(); if (cmdletContext.SnapshotId != null) { request.SnapshotId = cmdletContext.SnapshotId; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }
public void TerminateSnapshots(IEnumerable<string> volumeIds) { Logger.WithLogSection("Terminating snapshots", () => { foreach (var volumeId in volumeIds) { var describe = new DescribeSnapshotsRequest { Filters = new List<Filter> { new Filter { Name = "volume-id", Values = new[]{volumeId}.ToList() } } }; var snapshots = _client.DescribeSnapshots(describe); foreach (var snapshot in snapshots.Snapshots) { var request = new DeleteSnapshotRequest { SnapshotId = snapshot.SnapshotId }; _client.DeleteSnapshot(request); Logger.Info("Snapshot {0} deleted.", snapshot.SnapshotId); } } }); }
/// <summary> /// Initiates the asynchronous execution of the DeleteSnapshot operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSnapshot operation on AmazonEC2Client.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDeleteSnapshot /// operation.</returns> public IAsyncResult BeginDeleteSnapshot(DeleteSnapshotRequest request, AsyncCallback callback, object state) { var marshaller = new DeleteSnapshotRequestMarshaller(); var unmarshaller = DeleteSnapshotResponseUnmarshaller.Instance; return BeginInvoke<DeleteSnapshotRequest>(request, marshaller, unmarshaller, callback, state); }
IAsyncResult invokeDeleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new DeleteSnapshotRequestMarshaller().Marshall(deleteSnapshotRequest); var unmarshaller = DeleteSnapshotResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the DeleteSnapshot operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.DeleteSnapshot"/> /// </summary> /// /// <param name="deleteSnapshotRequest">Container for the necessary parameters to execute the DeleteSnapshot operation on AmazonEC2.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public IAsyncResult BeginDeleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest, AsyncCallback callback, object state) { return invokeDeleteSnapshot(deleteSnapshotRequest, callback, state, false); }
/// <summary> /// <para>Deletes the specified snapshot.</para> <para>When you make periodic snapshots of a volume, the snapshots are incremental, and only the /// blocks on the device that have changed since your last snapshot are saved in the new snapshot. When you delete a snapshot, only the data not /// needed for any other snapshot is removed. So regardless of which prior snapshots have been deleted, all active snapshots will have access to /// all the information needed to restore the volume.</para> <para>You cannot delete a snapshot of the root device of an Amazon EBS volume used /// by a registered AMI. You must first de-register the AMI before you can delete the snapshot.</para> <para>For more information, see <a /// href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-deleting-snapshot.html" >Deleting an Amazon EBS Snapshot</a> in the <i>Amazon /// Elastic Compute Cloud User Guide</i> .</para> /// </summary> /// /// <param name="deleteSnapshotRequest">Container for the necessary parameters to execute the DeleteSnapshot service method on /// AmazonEC2.</param> /// public DeleteSnapshotResponse DeleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest) { IAsyncResult asyncResult = invokeDeleteSnapshot(deleteSnapshotRequest, null, null, true); return EndDeleteSnapshot(asyncResult); }
private Amazon.EC2.Model.DeleteSnapshotResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.DeleteSnapshotRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "DeleteSnapshot"); try { #if DESKTOP return(client.DeleteSnapshot(request)); #elif CORECLR return(client.DeleteSnapshotAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
/// <summary> /// <para>Deletes the specified snapshot.</para> <para>When you make periodic snapshots of a volume, the snapshots are incremental, and only the /// blocks on the device that have changed since your last snapshot are saved in the new snapshot. When you delete a snapshot, only the data not /// needed for any other snapshot is removed. So regardless of which prior snapshots have been deleted, all active snapshots will have access to /// all the information needed to restore the volume.</para> <para>You cannot delete a snapshot of the root device of an Amazon EBS volume used /// by a registered AMI. You must first de-register the AMI before you can delete the snapshot.</para> <para>For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-deleting-snapshot.html">Deleting an Amazon EBS Snapshot</a> in the <i>Amazon /// Elastic Compute Cloud User Guide</i> .</para> /// </summary> /// /// <param name="deleteSnapshotRequest">Container for the necessary parameters to execute the DeleteSnapshot service method on /// AmazonEC2.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<DeleteSnapshotResponse> DeleteSnapshotAsync(DeleteSnapshotRequest deleteSnapshotRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteSnapshotRequestMarshaller(); var unmarshaller = DeleteSnapshotResponseUnmarshaller.GetInstance(); return Invoke<IRequest, DeleteSnapshotRequest, DeleteSnapshotResponse>(deleteSnapshotRequest, marshaller, unmarshaller, signer, cancellationToken); }
/// <summary> /// Deletes a snapshot /// </summary> /// <param name="snapShotId"></param> public void DeleteSnapShot(string snapShotId) { var request = new DeleteSnapshotRequest { SnapshotId = snapShotId }; Client.DeleteSnapshot(request); }
/// <summary> /// Deletes the specified snapshot. /// /// /// <para> /// When you make periodic snapshots of a volume, the snapshots are incremental, and only /// the blocks on the device that have changed since your last snapshot are saved in the /// new snapshot. When you delete a snapshot, only the data not needed for any other snapshot /// is removed. So regardless of which prior snapshots have been deleted, all active snapshots /// will have access to all the information needed to restore the volume. /// </para> /// /// <para> /// You cannot delete a snapshot of the root device of an EBS volume used by a registered /// AMI. You must first de-register the AMI before you can delete the snapshot. /// </para> /// /// <para> /// For more information, see <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-deleting-snapshot.html">Deleting /// an Amazon EBS Snapshot</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the DeleteSnapshot service method.</param> /// /// <returns>The response from the DeleteSnapshot service method, as returned by EC2.</returns> public DeleteSnapshotResponse DeleteSnapshot(DeleteSnapshotRequest request) { var marshaller = new DeleteSnapshotRequestMarshaller(); var unmarshaller = DeleteSnapshotResponseUnmarshaller.Instance; return Invoke<DeleteSnapshotRequest,DeleteSnapshotResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the DeleteSnapshot operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.DeleteSnapshot"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSnapshot operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public async Task<DeleteSnapshotResponse> DeleteSnapshotAsync(DeleteSnapshotRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteSnapshotRequestMarshaller(); var unmarshaller = DeleteSnapshotResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, DeleteSnapshotRequest, DeleteSnapshotResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// <para> Deletes the snapshot identified by <c>snapshotId</c> . /// </para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSnapshot service method on /// AmazonEC2.</param> public DeleteSnapshotResponse DeleteSnapshot(DeleteSnapshotRequest request) { var task = DeleteSnapshotAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
static void DeleteSnapshot(string SnapshotID) { AmazonEC2 ec2 = GetEC2Client(); var request = new DeleteSnapshotRequest().WithSnapshotId(SnapshotID); var response = ec2.DeleteSnapshot(request); Console.WriteLine(SnapshotID + "was Deleted"); }
/// <summary> /// Initiates the asynchronous execution of the DeleteSnapshot operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSnapshot operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<DeleteSnapshotResponse> DeleteSnapshotAsync(DeleteSnapshotRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteSnapshotRequestMarshaller(); var unmarshaller = DeleteSnapshotResponseUnmarshaller.Instance; return InvokeAsync<DeleteSnapshotRequest,DeleteSnapshotResponse>(request, marshaller, unmarshaller, cancellationToken); }
internal DeleteSnapshotResponse DeleteSnapshot(DeleteSnapshotRequest request) { var task = DeleteSnapshotAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }