public static void main(String[] args) { final String USAGE = "To run this example, supply a security group id\n" + "Ex: DeleteSecurityGroup <security-group-id>\n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String group_id = args[0]; final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); DeleteSecurityGroupRequest request = new DeleteSecurityGroupRequest() .withGroupId(group_id); DeleteSecurityGroupResult response = ec2.deleteSecurityGroup(request); System.out.printf( "Successfully deleted security group with id %s", group_id); }
@Override public void execute(AmazonEC2 client, Pool pool, DelegateExecution execution) { final String groupName = SecurityGroups.formatNameFromBusinessKey(execution.getProcessBusinessKey()); try { LOG.info(">> Deleting Security Group {}", groupName); client.deleteSecurityGroup(new DeleteSecurityGroupRequest().withGroupName(groupName)); } catch (AmazonServiceException e) { if (e.getErrorCode().equals(ErrorCodes.SECURITY_GROUP_NOT_FOUND)) { LOG.info("<< Security Group {} not found. Ignoring this error.", groupName); } else { throw Throwables.propagate(e); } } }
public DeferredResult<Void> deleteSecurityGroupAsync(String securityGroupId) { DeleteSecurityGroupRequest req = new DeleteSecurityGroupRequest() .withGroupId(securityGroupId); String message = "Delete AWS Security Group with id [" + securityGroupId + "]."; AWSDeferredResultAsyncHandler<DeleteSecurityGroupRequest, DeleteSecurityGroupResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message); this.client.deleteSecurityGroupAsync(req, handler); return handler.toDeferredResult() .thenApply(result -> (Void) null); }
public static void deleteSecurityGroupUsingEC2Client(AmazonEC2AsyncClient client, VerificationHost host, String awsGroupId) { host.log(Level.INFO, "Starting to delete aws Security group with id %s", awsGroupId); if (awsGroupId == null) { return; } try { DeleteSecurityGroupRequest deleteSecurityGroupRequest = new DeleteSecurityGroupRequest() .withGroupId(awsGroupId); client.deleteSecurityGroup(deleteSecurityGroupRequest); host.waitFor( "Timeout waiting for AWS to delete a SecurityGroup with name " + awsGroupId, () -> { // Check if the SG is actually not present on AWS after the delete operation SecurityGroup discoveredSGOnAWS = getSecurityGroupsIdUsingEC2Client(client, awsGroupId); if (discoveredSGOnAWS != null) { // Requested SG was not deleted from AWS return false; } host.log("Deleted SG with id: %s", awsGroupId); return true; }); } catch (Exception e) { String message = e.getMessage(); if (!message.contains("The security group '" + awsGroupId + "' already exists")) { throw e; } } }
protected void quietlyDeleteSecurityGroupIfExists(String groupName) { try { client.deleteSecurityGroup(new DeleteSecurityGroupRequest().withGroupName(groupName)); } catch (AmazonServiceException e) { if (!e.getErrorCode().equals("InvalidGroup.NotFound")) { throw Throwables.propagate(e); } } }
private static void deleteGroupIfPresent() { try { DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest().withGroupNames(GROUP_NAME); DescribeSecurityGroupsResult existing = ec2Client.describeSecurityGroups(describeSecurityGroupsRequest); if (existing.getSecurityGroups().size()>0) { DeleteSecurityGroupRequest deleteGroup = new DeleteSecurityGroupRequest().withGroupName(GROUP_NAME); ec2Client.deleteSecurityGroup(deleteGroup); } } catch (AmazonServiceException exception) { // no op } }
@Override public boolean deleteRuleSet( final String name ) { try { DeleteSecurityGroupRequest request = new DeleteSecurityGroupRequest().withGroupName( name ); client.deleteSecurityGroup( request ); return true; } catch ( AmazonServiceException e ) { LOG.warn( "Error while trying to delete security group", e ); return false; } }
/** * Delete SecurityGroup. * * @param groupId the group id * @return true if deleted, otherwise false. */ protected final boolean deleteSecurityGroup(final String groupId) { DeleteSecurityGroupRequest req = new DeleteSecurityGroupRequest(); req.setGroupId(groupId); DeleteSecurityGroupResult result = amazonEC2Client.deleteSecurityGroup(req); if (result != null) { return true; } /*CreateSecurityGroupRequest createSecurityGroupRequest = new CreateSecurityGroupRequest(); AuthorizeSecurityGroupEgressRequest authorizeSecurityGroupEgressRequest = new AuthorizeSecurityGroupEgressRequest(); authorizeSecurityGroupEgressRequest.setIpProtocol(ipProtocol); CreateSecurityGroupResult result = amazonEC2Client.authorizeSecurityGroupEgress(authorizeSecurityGroupEgressRequest);*/ return false; }
@Override public void deleteSecurityGroup(DeleteSecurityGroupRequest deleteSecurityGroupRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
public void deleteSecurityGroup(String securityGroupId) { DeleteSecurityGroupRequest req = new DeleteSecurityGroupRequest() .withGroupId(securityGroupId); this.client.deleteSecurityGroup(req); }
public void deleteSecurityGroup(String securityGroupId) { logger.info("delete security group, securityGroupId={}", securityGroupId); ec2.deleteSecurityGroup(new DeleteSecurityGroupRequest().withGroupId(securityGroupId)); }
@Override public void delete(DeleteSecurityGroupRequest request) { delete(request, null); }
@Override public void delete(DeleteSecurityGroupRequest request, ResultCapture<Void> extractor) { resource.performAction("Delete", request, extractor); }
/** * Performs the <code>Delete</code> action. * * <p> * The following request parameters will be populated from the data of this * <code>SecurityGroup</code> resource, and any conflicting parameter value * set in the request will be overridden: * <ul> * <li> * <b><code>GroupId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see DeleteSecurityGroupRequest */ void delete(DeleteSecurityGroupRequest request);
/** * Performs the <code>Delete</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>SecurityGroup</code> resource, and any conflicting parameter value * set in the request will be overridden: * <ul> * <li> * <b><code>GroupId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see DeleteSecurityGroupRequest */ void delete(DeleteSecurityGroupRequest request, ResultCapture<Void> extractor);