Search in sources :

Example 36 with EC2Client

use of software.amazon.awssdk.services.ec2.EC2Client in project aws-doc-sdk-examples by awsdocs.

the class DeleteSecurityGroup method deleteEC2SecGroup.

// snippet-start:[ec2.java2.delete_security_group.main]
public static void deleteEC2SecGroup(Ec2Client ec2, String groupId) {
    try {
        DeleteSecurityGroupRequest request = DeleteSecurityGroupRequest.builder().groupId(groupId).build();
        ec2.deleteSecurityGroup(request);
        System.out.printf("Successfully deleted Security Group with id %s", groupId);
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DeleteSecurityGroupRequest(software.amazon.awssdk.services.ec2.model.DeleteSecurityGroupRequest) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception)

Example 37 with EC2Client

use of software.amazon.awssdk.services.ec2.EC2Client in project aws-doc-sdk-examples by awsdocs.

the class DeleteSecurityGroup method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "   <groupId> \n\n" + "Where:\n" + "   groupId - a security group id that you can obtain from the AWS Console (for example, sg-xxxxxx1c0b65785c3).";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String groupId = args[0];
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    deleteEC2SecGroup(ec2, groupId);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 38 with EC2Client

use of software.amazon.awssdk.services.ec2.EC2Client in project aws-doc-sdk-examples by awsdocs.

the class DescribeAddresses method main.

public static void main(String[] args) {
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    describeEC2Address(ec2);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 39 with EC2Client

use of software.amazon.awssdk.services.ec2.EC2Client in project aws-doc-sdk-examples by awsdocs.

the class ReleaseAddress method releaseEC2Address.

// snippet-start:[ec2.java2.release_instance.main]
public static void releaseEC2Address(Ec2Client ec2, String allocId) {
    try {
        ReleaseAddressRequest request = ReleaseAddressRequest.builder().allocationId(allocId).build();
        ReleaseAddressResponse response = ec2.releaseAddress(request);
        System.out.printf("Successfully released elastic IP address %s", allocId);
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ReleaseAddressResponse(software.amazon.awssdk.services.ec2.model.ReleaseAddressResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) ReleaseAddressRequest(software.amazon.awssdk.services.ec2.model.ReleaseAddressRequest)

Example 40 with EC2Client

use of software.amazon.awssdk.services.ec2.EC2Client in project aws-doc-sdk-examples by awsdocs.

the class DeleteKeyPair method deleteKeys.

// snippet-start:[ec2.java2.delete_key_pair.main]
public static void deleteKeys(Ec2Client ec2, String keyPair) {
    try {
        DeleteKeyPairRequest request = DeleteKeyPairRequest.builder().keyName(keyPair).build();
        DeleteKeyPairResponse response = ec2.deleteKeyPair(request);
        System.out.printf("Successfully deleted key pair named %s", keyPair);
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DeleteKeyPairResponse(software.amazon.awssdk.services.ec2.model.DeleteKeyPairResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) DeleteKeyPairRequest(software.amazon.awssdk.services.ec2.model.DeleteKeyPairRequest)

Aggregations

Ec2Client (software.amazon.awssdk.services.ec2.Ec2Client)21 Region (software.amazon.awssdk.regions.Region)20 Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)16 Test (org.junit.Test)5 EC2Client (software.amazon.awssdk.services.ec2.EC2Client)5 Injector (com.google.inject.Injector)2 DescribeInstancesRequest (software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest)2 DescribeInstancesResponse (software.amazon.awssdk.services.ec2.model.DescribeInstancesResponse)2 Instance (software.amazon.awssdk.services.ec2.model.Instance)2 Reservation (software.amazon.awssdk.services.ec2.model.Reservation)2 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 ListIterator (java.util.ListIterator)1 EC2Client (org.jclouds.aws.ec2.EC2Client)1 EC2AsyncClient (org.jclouds.ec2.EC2AsyncClient)1 EC2Client (org.jclouds.ec2.EC2Client)1 KeyPair (org.jclouds.ec2.domain.KeyPair)1 RunningInstance (org.jclouds.ec2.domain.RunningInstance)1 AccountAttribute (software.amazon.awssdk.services.ec2.model.AccountAttribute)1 AccountAttributeValue (software.amazon.awssdk.services.ec2.model.AccountAttributeValue)1