Search in sources :

Example 6 with Ec2Client

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);
    }
}
Also used : Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) TerminateInstancesResponse(software.amazon.awssdk.services.ec2.model.TerminateInstancesResponse) TerminateInstancesRequest(software.amazon.awssdk.services.ec2.model.TerminateInstancesRequest) InstanceStateChange(software.amazon.awssdk.services.ec2.model.InstanceStateChange)

Example 7 with Ec2Client

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();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 8 with Ec2Client

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);
    }
}
Also used : Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) CreateKeyPairRequest(software.amazon.awssdk.services.ec2.model.CreateKeyPairRequest)

Example 9 with Ec2Client

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();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 10 with Ec2Client

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);
    }
}
Also used : AccountAttribute(software.amazon.awssdk.services.ec2.model.AccountAttribute) DescribeAccountAttributesResponse(software.amazon.awssdk.services.ec2.model.DescribeAccountAttributesResponse) AccountAttributeValue(software.amazon.awssdk.services.ec2.model.AccountAttributeValue) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) ListIterator(java.util.ListIterator)

Aggregations

Ec2Client (software.amazon.awssdk.services.ec2.Ec2Client)21 Region (software.amazon.awssdk.regions.Region)20 Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)16 Test (org.junit.Test)5 EC2Client (software.amazon.awssdk.services.ec2.EC2Client)5 Injector (com.google.inject.Injector)2 DescribeInstancesRequest (software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest)2 DescribeInstancesResponse (software.amazon.awssdk.services.ec2.model.DescribeInstancesResponse)2 Instance (software.amazon.awssdk.services.ec2.model.Instance)2 Reservation (software.amazon.awssdk.services.ec2.model.Reservation)2 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 ListIterator (java.util.ListIterator)1 EC2Client (org.jclouds.aws.ec2.EC2Client)1 EC2AsyncClient (org.jclouds.ec2.EC2AsyncClient)1 EC2Client (org.jclouds.ec2.EC2Client)1 KeyPair (org.jclouds.ec2.domain.KeyPair)1 RunningInstance (org.jclouds.ec2.domain.RunningInstance)1 AccountAttribute (software.amazon.awssdk.services.ec2.model.AccountAttribute)1 AccountAttributeValue (software.amazon.awssdk.services.ec2.model.AccountAttributeValue)1