Search in sources :

Example 11 with Ec2Client

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

Example 12 with Ec2Client

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

Example 13 with Ec2Client

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

Example 14 with Ec2Client

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

Example 15 with Ec2Client

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

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