use of software.amazon.awssdk.services.ec2.model.Ec2Exception in project aws-doc-sdk-examples by awsdocs.
the class TerminateInstance method terminateEC2.
// snippet-start:[ec2.java2.terminate_instance]
public static void terminateEC2(Ec2Client ec2, String instanceID) {
try {
TerminateInstancesRequest ti = TerminateInstancesRequest.builder().instanceIds(instanceID).build();
TerminateInstancesResponse response = ec2.terminateInstances(ti);
List<InstanceStateChange> list = response.terminatingInstances();
for (int i = 0; i < list.size(); i++) {
InstanceStateChange sc = (list.get(i));
System.out.println("The ID of the terminated instance is " + sc.instanceId());
}
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.ec2.model.Ec2Exception in project aws-doc-sdk-examples by awsdocs.
the class CreateKeyPair method createEC2KeyPair.
// snippet-start:[ec2.java2.create_key_pair.main]
public static void createEC2KeyPair(Ec2Client ec2, String keyName) {
try {
CreateKeyPairRequest request = CreateKeyPairRequest.builder().keyName(keyName).build();
ec2.createKeyPair(request);
System.out.printf("Successfully created key pair named %s", keyName);
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.ec2.model.Ec2Exception in project aws-doc-sdk-examples by awsdocs.
the class DescribeAccount method describeEC2Account.
// snippet-start:[ec2.java2.describe_account.main]
public static void describeEC2Account(Ec2Client ec2) {
try {
DescribeAccountAttributesResponse accountResults = ec2.describeAccountAttributes();
List<AccountAttribute> accountList = accountResults.accountAttributes();
for (ListIterator iter = accountList.listIterator(); iter.hasNext(); ) {
AccountAttribute attribute = (AccountAttribute) iter.next();
System.out.print("\n The name of the attribute is " + attribute.attributeName());
List<AccountAttributeValue> values = attribute.attributeValues();
for (ListIterator iterVals = values.listIterator(); iterVals.hasNext(); ) {
AccountAttributeValue myValue = (AccountAttributeValue) iterVals.next();
System.out.print("\n The value of the attribute is " + myValue.attributeValue());
}
}
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.ec2.model.Ec2Exception 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.model.Ec2Exception 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);
}
}
Aggregations