use of software.amazon.awssdk.services.ec2.EC2Client 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.EC2Client in project aws-doc-sdk-examples by awsdocs.
the class CreateKeyPair method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <keyName> \n\n" + "Where:\n" + " keyName - a key pair name (for example, TestKeyPair). \n\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String keyName = args[0];
Region region = Region.US_WEST_2;
Ec2Client ec2 = Ec2Client.builder().region(region).build();
createEC2KeyPair(ec2, keyName);
ec2.close();
}
use of software.amazon.awssdk.services.ec2.EC2Client 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.EC2Client in project aws-doc-sdk-examples by awsdocs.
the class DeleteKeyPair method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <keyPair> \n\n" + "Where:\n" + " keyPair - a key pair name (for example, TestKeyPair).";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String keyPair = args[0];
Region region = Region.US_WEST_2;
Ec2Client ec2 = Ec2Client.builder().region(region).build();
deleteKeys(ec2, keyPair);
ec2.close();
}
use of software.amazon.awssdk.services.ec2.EC2Client 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);
}
}
Aggregations