use of software.amazon.awssdk.services.ec2.Ec2Client in project aws-doc-sdk-examples by awsdocs.
the class DescribeReservedInstances 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];
Region region = Region.US_WEST_2;
Ec2Client ec2 = Ec2Client.builder().region(region).build();
describeReservedEC2Instances(ec2, instanceId);
ec2.close();
}
use of software.amazon.awssdk.services.ec2.Ec2Client in project aws-doc-sdk-examples by awsdocs.
the class DescribeReservedInstances method describeReservedEC2Instances.
// snippet-start:[ec2.java2.describe_reserved_instances.main]
public static void describeReservedEC2Instances(Ec2Client ec2, String instanceID) {
try {
DescribeReservedInstancesRequest request = DescribeReservedInstancesRequest.builder().reservedInstancesIds(instanceID).build();
DescribeReservedInstancesResponse response = ec2.describeReservedInstances(request);
for (ReservedInstances instance : response.reservedInstances()) {
System.out.printf("Found a Reserved Instance with id %s, " + "in AZ %s, " + "type %s, " + "state %s " + "and monitoring state %s", instance.reservedInstancesId(), instance.availabilityZone(), instance.instanceType(), instance.state().name());
}
} 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 DescribeVPCs method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <vpcId>\n\n" + "Where:\n" + " vpcId - a VPC ID that you can obtain from the AWS Management Console (for example, vpc-xxxxxf2f). \n\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String vpcId = args[0];
Region region = Region.US_WEST_2;
Ec2Client ec2 = Ec2Client.builder().region(region).build();
describeEC2Vpcs(ec2, vpcId);
ec2.close();
}
use of software.amazon.awssdk.services.ec2.Ec2Client in project aws-doc-sdk-examples by awsdocs.
the class DescribeVPCs method describeEC2Vpcs.
// snippet-start:[ec2.java2.describe_vpc.main]
public static void describeEC2Vpcs(Ec2Client ec2, String vpcId) {
try {
DescribeVpcsRequest request = DescribeVpcsRequest.builder().vpcIds(vpcId).build();
DescribeVpcsResponse response = ec2.describeVpcs(request);
for (Vpc vpc : response.vpcs()) {
System.out.printf("Found VPC with id %s, " + "vpc state %s " + "and tennancy %s", vpc.vpcId(), vpc.stateAsString(), vpc.instanceTenancyAsString());
}
} 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 MonitorInstance method unmonitorInstance.
// snippet-end:[ec2.java2.monitor_instance.main]
// snippet-start:[ec2.java2.monitor_instance.stop]
public static void unmonitorInstance(Ec2Client ec2, String instanceId) {
UnmonitorInstancesRequest request = UnmonitorInstancesRequest.builder().instanceIds(instanceId).build();
ec2.unmonitorInstances(request);
System.out.printf("Successfully disabled monitoring for instance %s", instanceId);
}
Aggregations