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();
}
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);
}
}
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);
}
}
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();
}
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);
}
}
Aggregations