use of software.amazon.awssdk.services.ec2.model.DeleteSecurityGroupRequest in project photon-model by vmware.
the class AWSRemoteCleanup method deleteSecurityGroups.
private void deleteSecurityGroups(String vpcId, AmazonEC2 usEastEc2Client) {
DescribeSecurityGroupsRequest securityGroupsRequest = new DescribeSecurityGroupsRequest().withFilters(new Filter(VPC_KEY, Collections.singletonList(vpcId)));
DescribeSecurityGroupsResult securityGroupsResult = usEastEc2Client.describeSecurityGroups(securityGroupsRequest);
securityGroupsResult.getSecurityGroups().forEach(securityGroup -> {
if (!(securityGroup.getGroupName().equalsIgnoreCase(DEFAULT_TAG))) {
DeleteSecurityGroupRequest deleteSecurityGroupRequest = new DeleteSecurityGroupRequest().withGroupId(securityGroup.getGroupId());
this.host.log("Terminating stale security group: %s", securityGroup.getGroupId());
usEastEc2Client.deleteSecurityGroup(deleteSecurityGroupRequest);
}
});
}
use of software.amazon.awssdk.services.ec2.model.DeleteSecurityGroupRequest in project photon-model by vmware.
the class AWSSecurityGroupClient method deleteSecurityGroup.
public void deleteSecurityGroup(String securityGroupId) {
DeleteSecurityGroupRequest req = new DeleteSecurityGroupRequest().withGroupId(securityGroupId);
this.client.deleteSecurityGroup(req);
}
use of software.amazon.awssdk.services.ec2.model.DeleteSecurityGroupRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteSecurityGroup method main.
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);
}
use of software.amazon.awssdk.services.ec2.model.DeleteSecurityGroupRequest in project Synapse-Stack-Builder by Sage-Bionetworks.
the class EC2SecuritySetupTest method testTeardownResources.
@Test
public void testTeardownResources() {
resources.setElasticBeanstalkEC2SecurityGroup(new SecurityGroup().withGroupName(config.getElasticSecurityGroupName()));
DeleteSecurityGroupRequest req = new DeleteSecurityGroupRequest().withGroupName(resources.getElasticBeanstalkEC2SecurityGroup().getGroupName());
ec2SecuritySetup.teardownResources();
assertNotNull(resources.getElasticBeanstalkEC2SecurityGroup());
}
use of software.amazon.awssdk.services.ec2.model.DeleteSecurityGroupRequest in project photon-model by vmware.
the class TestAWSSetupUtils method deleteSecurityGroupUsingEC2Client.
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;
}
}
}
Aggregations