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); }
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); }
/** * 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; }