protected override void ProcessRecord() { AmazonEC2 client = base.GetClient(); Amazon.EC2.Model.DeleteSecurityGroupRequest request = new Amazon.EC2.Model.DeleteSecurityGroupRequest(); request.GroupName = this._GroupName; Amazon.EC2.Model.DeleteSecurityGroupResponse response = client.DeleteSecurityGroup(request); }
/// <summary> /// The DeleteSecurityGroup operation deletes a security group. /// Note: /// If you attempt to delete a security group that contains instances, a fault is /// returned. /// If you attempt to delete a security group that is referenced by another /// security group, a fault is returned. For example, if security group B has a /// rule that allows access from security group A, security group A cannot be /// deleted until the allow rule is removed. /// /// </summary> /// <param name="service">Instance of AmazonEC2 service</param> /// <param name="request">DeleteSecurityGroupRequest request</param> public static void InvokeDeleteSecurityGroup(AmazonEC2 service, DeleteSecurityGroupRequest request) { try { DeleteSecurityGroupResponse response = service.DeleteSecurityGroup(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" DeleteSecurityGroupResponse"); 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); } }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.EC2.Model.DeleteSecurityGroupRequest(); if (cmdletContext.GroupId != null) { request.GroupId = cmdletContext.GroupId; } if (cmdletContext.GroupName != null) { request.GroupName = cmdletContext.GroupName; } 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); }
/// <summary> /// Initiates the asynchronous execution of the DeleteSecurityGroup operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSecurityGroup 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<DeleteSecurityGroupResponse> DeleteSecurityGroupAsync(DeleteSecurityGroupRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteSecurityGroupRequestMarshaller(); var unmarshaller = DeleteSecurityGroupResponseUnmarshaller.Instance; return InvokeAsync<DeleteSecurityGroupRequest,DeleteSecurityGroupResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Deletes a security group. /// /// /// <para> /// If you attempt to delete a security group that is associated with an instance, or /// is referenced by another security group, the operation fails with <code>InvalidGroup.InUse</code> /// in EC2-Classic or <code>DependencyViolation</code> in EC2-VPC. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the DeleteSecurityGroup service method.</param> /// /// <returns>The response from the DeleteSecurityGroup service method, as returned by EC2.</returns> public DeleteSecurityGroupResponse DeleteSecurityGroup(DeleteSecurityGroupRequest request) { var marshaller = new DeleteSecurityGroupRequestMarshaller(); var unmarshaller = DeleteSecurityGroupResponseUnmarshaller.Instance; return Invoke<DeleteSecurityGroupRequest,DeleteSecurityGroupResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the DeleteSecurityGroup operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSecurityGroup 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 EndDeleteSecurityGroup /// operation.</returns> public IAsyncResult BeginDeleteSecurityGroup(DeleteSecurityGroupRequest request, AsyncCallback callback, object state) { var marshaller = new DeleteSecurityGroupRequestMarshaller(); var unmarshaller = DeleteSecurityGroupResponseUnmarshaller.Instance; return BeginInvoke<DeleteSecurityGroupRequest>(request, marshaller, unmarshaller, callback, state); }
IAsyncResult invokeDeleteSecurityGroup(DeleteSecurityGroupRequest deleteSecurityGroupRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new DeleteSecurityGroupRequestMarshaller().Marshall(deleteSecurityGroupRequest); var unmarshaller = DeleteSecurityGroupResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the DeleteSecurityGroup operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.DeleteSecurityGroup"/> /// </summary> /// /// <param name="deleteSecurityGroupRequest">Container for the necessary parameters to execute the DeleteSecurityGroup 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 BeginDeleteSecurityGroup(DeleteSecurityGroupRequest deleteSecurityGroupRequest, AsyncCallback callback, object state) { return invokeDeleteSecurityGroup(deleteSecurityGroupRequest, callback, state, false); }
/// <summary> /// <para>Deletes a security group.</para> <para>If you attempt to delete a security group that is associated with an instance, or is referenced /// by another security group, the operation fails with <c>InvalidGroup.InUse</c> in EC2-Classic or <c>DependencyViolation</c> in /// EC2-VPC.</para> /// </summary> /// /// <param name="deleteSecurityGroupRequest">Container for the necessary parameters to execute the DeleteSecurityGroup service method on /// AmazonEC2.</param> /// public DeleteSecurityGroupResponse DeleteSecurityGroup(DeleteSecurityGroupRequest deleteSecurityGroupRequest) { IAsyncResult asyncResult = invokeDeleteSecurityGroup(deleteSecurityGroupRequest, null, null, true); return EndDeleteSecurityGroup(asyncResult); }
/// <summary> /// <para>Deletes a security group.</para> <para>If you attempt to delete a security group that is associated with an instance, or is referenced /// by another security group, the operation fails with <c>InvalidGroup.InUse</c> in EC2-Classic or <c>DependencyViolation</c> in /// EC2-VPC.</para> /// </summary> /// /// <param name="deleteSecurityGroupRequest">Container for the necessary parameters to execute the DeleteSecurityGroup 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<DeleteSecurityGroupResponse> DeleteSecurityGroupAsync(DeleteSecurityGroupRequest deleteSecurityGroupRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteSecurityGroupRequestMarshaller(); var unmarshaller = DeleteSecurityGroupResponseUnmarshaller.GetInstance(); return Invoke<IRequest, DeleteSecurityGroupRequest, DeleteSecurityGroupResponse>(deleteSecurityGroupRequest, marshaller, unmarshaller, signer, cancellationToken); }
internal DeleteSecurityGroupResponse DeleteSecurityGroup(DeleteSecurityGroupRequest request) { var task = DeleteSecurityGroupAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Initiates the asynchronous execution of the DeleteSecurityGroup operation. /// <seealso cref="Amazon.EC2.IAmazonEC2.DeleteSecurityGroup"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSecurityGroup 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<DeleteSecurityGroupResponse> DeleteSecurityGroupAsync(DeleteSecurityGroupRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new DeleteSecurityGroupRequestMarshaller(); var unmarshaller = DeleteSecurityGroupResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, DeleteSecurityGroupRequest, DeleteSecurityGroupResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// <para> The DeleteSecurityGroup operation deletes a security group. </para> <para><b>NOTE:</b> If you attempt to delete a security group that /// contains instances, a fault is returned. If you attempt to delete a security group that is referenced by another security group, a fault is /// returned. For example, if security group B has a rule that allows access from security group A, security group A cannot be deleted until the /// allow rule is removed. </para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the DeleteSecurityGroup service method on /// AmazonEC2.</param> public DeleteSecurityGroupResponse DeleteSecurityGroup(DeleteSecurityGroupRequest request) { var task = DeleteSecurityGroupAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
public void DeleteSecurityGroup(string bootstrapId) { var secGroupName = SEC_GROUP_PREFIX + bootstrapId; Logger.Info("Deleting security group {0}", secGroupName); var id = GetSecurityGroupId(secGroupName); var deleteRequest = new DeleteSecurityGroupRequest { GroupId = id }; try { _client.DeleteSecurityGroup(deleteRequest); } catch (AmazonEC2Exception) { Logger.Warn("Failed to delete security group {0}", secGroupName); Logger.Info("Waiting 10 seconds before retry..."); Thread.Sleep(10000); DeleteSecurityGroup(bootstrapId); } }
private async Task DeleteSecurityGroup(string id) { _context.Logger.WriteLine("DeleteSecurityGroup"); var request = new DeleteSecurityGroupRequest { GroupId = id }; await _client.DeleteSecurityGroupAsync(request); }
private Amazon.EC2.Model.DeleteSecurityGroupResponse CallAWSServiceOperation(IAmazonEC2 client, Amazon.EC2.Model.DeleteSecurityGroupRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Elastic Compute Cloud (EC2)", "DeleteSecurityGroup"); try { #if DESKTOP return(client.DeleteSecurityGroup(request)); #elif CORECLR return(client.DeleteSecurityGroupAsync(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; } }