Search in sources :

Example 26 with EC2Client

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

the class DescribeRegionsAndZones method main.

public static void main(String[] args) {
    // snippet-start:[ec2.java2.describe_region_and_zones.client]
    Ec2Client ec2 = Ec2Client.create();
    // snippet-end:[ec2.java2.describe_region_and_zones.client]
    describeEC2RegionsAndZones(ec2);
    ec2.close();
}
Also used : Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 27 with EC2Client

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

the class DescribeRegionsAndZones method describeEC2RegionsAndZones.

// snippet-start:[ec2.java2.describe_region_and_zones.main]
public static void describeEC2RegionsAndZones(Ec2Client ec2) {
    // snippet-start:[ec2.java2.describe_region_and_zones.region]
    try {
        DescribeRegionsResponse regionsResponse = ec2.describeRegions();
        for (Region region : regionsResponse.regions()) {
            System.out.printf("Found Region %s " + "with endpoint %s", region.regionName(), region.endpoint());
            System.out.println();
        // snippet-end:[ec2.java2.describe_region_and_zones.region]
        }
        // snippet-start:[ec2.java2.describe_region_and_zones.avail_zone]
        DescribeAvailabilityZonesResponse zonesResponse = ec2.describeAvailabilityZones();
        for (AvailabilityZone zone : zonesResponse.availabilityZones()) {
            System.out.printf("Found Availability Zone %s " + "with status %s " + "in region %s", zone.zoneName(), zone.state(), zone.regionName());
            System.out.println();
        // snippet-end:[ec2.java2.describe_region_and_zones.avail_zone]
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DescribeAvailabilityZonesResponse(software.amazon.awssdk.services.ec2.model.DescribeAvailabilityZonesResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) Region(software.amazon.awssdk.services.ec2.model.Region) AvailabilityZone(software.amazon.awssdk.services.ec2.model.AvailabilityZone) DescribeRegionsResponse(software.amazon.awssdk.services.ec2.model.DescribeRegionsResponse)

Example 28 with EC2Client

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

the class DescribeSecurityGroups method describeEC2SecurityGroups.

// snippet-start:[ec2.java2.describe_security_groups.main]
public static void describeEC2SecurityGroups(Ec2Client ec2, String groupId) {
    try {
        DescribeSecurityGroupsRequest request = DescribeSecurityGroupsRequest.builder().groupIds(groupId).build();
        DescribeSecurityGroupsResponse response = ec2.describeSecurityGroups(request);
        for (SecurityGroup group : response.securityGroups()) {
            System.out.printf("Found Security Group with id %s, " + "vpc id %s " + "and description %s", group.groupId(), group.vpcId(), group.description());
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DescribeSecurityGroupsRequest(software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest) DescribeSecurityGroupsResponse(software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) SecurityGroup(software.amazon.awssdk.services.ec2.model.SecurityGroup)

Example 29 with EC2Client

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

the class FindRunningInstances method main.

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

Example 30 with EC2Client

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

the class RebootInstance method rebootEC2Instance.

// snippet-start:[ec2.java2.reboot_instance.main]
public static void rebootEC2Instance(Ec2Client ec2, String instanceId) {
    try {
        RebootInstancesRequest request = RebootInstancesRequest.builder().instanceIds(instanceId).build();
        ec2.rebootInstances(request);
        System.out.printf("Successfully rebooted instance %s", instanceId);
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : RebootInstancesRequest(software.amazon.awssdk.services.ec2.model.RebootInstancesRequest) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception)

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