use of software.amazon.awssdk.services.ec2.model.Region 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.model.Region 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.model.Region in project aws-doc-sdk-examples by awsdocs.
the class StartStopInstance method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <instanceId>\n\n" + "Where:\n" + " instanceId - an instance id value that you can obtain from the AWS Console. \n\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String instanceId = args[0];
boolean start;
Region region = Region.US_WEST_2;
Ec2Client ec2 = Ec2Client.builder().region(region).build();
if (args[1].equals("start")) {
start = true;
} else {
start = false;
}
if (start) {
startInstance(ec2, instanceId);
} else {
stopInstance(ec2, instanceId);
}
ec2.close();
}
use of software.amazon.awssdk.services.ec2.model.Region in project aws-doc-sdk-examples by awsdocs.
the class CreateInstance method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <name> <amiId>\n\n" + "Where:\n" + " name - an instance name value that you can obtain from the AWS Console (for example, ami-xxxxxx5c8b987b1a0). \n\n" + " amiId - an Amazon Machine Image (AMI) value that you can obtain from the AWS Console (for example, i-xxxxxx2734106d0ab). \n\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String name = args[0];
String amiId = args[1];
Region region = Region.US_WEST_2;
Ec2Client ec2 = Ec2Client.builder().region(region).build();
String instanceId = createEC2Instance(ec2, name, amiId);
System.out.println("The Amazon EC2 Instance ID is " + instanceId);
ec2.close();
}
use of software.amazon.awssdk.services.ec2.model.Region 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();
}
Aggregations