Search in sources :

Example 11 with Region

use of software.amazon.awssdk.services.ec2.model.Region in project aws-doc-sdk-examples by awsdocs.

the class CreateSecurityGroup method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "   <groupName> <groupDesc> <vpcId> \n\n" + "Where:\n" + "   groupName - a group name (for example, TestKeyPair). \n\n" + "   groupDesc - a group description  (for example, TestKeyPair). \n\n" + "   vpcId - a VPC ID that you can obtain from the AWS Management Console (for example, vpc-xxxxxf2f). \n\n";
    if (args.length != 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String groupName = args[0];
    String groupDesc = args[1];
    String vpcId = args[2];
    // snippet-start:[ec2.java2.create_security_group.client]
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    // snippet-end:[ec2.java2.create_security_group.client]
    String id = createEC2SecurityGroup(ec2, groupName, groupDesc, vpcId);
    System.out.printf("Successfully created Security Group with this ID %s", id);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 12 with Region

use of software.amazon.awssdk.services.ec2.model.Region in project aws-doc-sdk-examples by awsdocs.

the class DescribeSecurityGroups method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply a group id\n" + "Ex: DescribeSecurityGroups <groupId>\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String groupId = args[0];
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    describeEC2SecurityGroups(ec2, groupId);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 13 with Region

use of software.amazon.awssdk.services.ec2.model.Region in project aws-doc-sdk-examples by awsdocs.

the class RebootInstance 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();
    rebootEC2Instance(ec2, instanceId);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Example 14 with Region

use of software.amazon.awssdk.services.ec2.model.Region in project photon-model by vmware.

the class AWSReservedInstancePlanService method getRegionAsyncHandler.

private AsyncHandler<DescribeRegionsRequest, DescribeRegionsResult> getRegionAsyncHandler(AWSReservedInstanceContext context) {
    AWSReservedInstancePlanService service = this;
    return new AsyncHandler<DescribeRegionsRequest, DescribeRegionsResult>() {

        @Override
        public void onError(Exception e) {
            log(Level.WARNING, "Error while fetching the regions for compute " + context.computeDesc.documentSelfLink + " " + Utils.toString(e));
        }

        @Override
        public void onSuccess(DescribeRegionsRequest request, DescribeRegionsResult describeRegionsResult) {
            List<Region> regions = describeRegionsResult.getRegions();
            if (CollectionUtils.isEmpty(regions)) {
                log(Level.INFO, "No regions exist for compute" + context.computeDesc.documentSelfLink);
                return;
            }
            AtomicInteger currentStageTaskCount = new AtomicInteger(regions.size());
            /*
                 * Fetch all the regions from AWS and collect reserved instances plans for
                 * only those regions which are supported by SDK.
                 */
            for (Region region : regions) {
                try {
                    Regions r = Regions.fromName(region.getRegionName());
                    if (r == null) {
                        new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context).checkAndPatchReservedInstancesPlans();
                        continue;
                    }
                } catch (Exception e) {
                    log(Level.WARNING, e.getMessage());
                    new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context).checkAndPatchReservedInstancesPlans();
                    continue;
                }
                service.ec2ClientManager.getOrCreateEC2ClientAsync(context.parentAuth, region.getRegionName(), service).whenComplete((ec2Client, t) -> {
                    if (t != null) {
                        getFailureConsumer(context, "Error while creating EC2 client for").accept(t);
                        new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context).checkAndPatchReservedInstancesPlans();
                        logWarning("client is null for region %s for compute %s", region.getRegionName(), context.computeDesc.documentSelfLink);
                        return;
                    }
                    ec2Client.describeReservedInstancesAsync(new AWSReservedInstanceAsyncHandler(service.getHost(), currentStageTaskCount, region, context));
                });
            }
        }
    };
}
Also used : AsyncHandler(com.amazonaws.handlers.AsyncHandler) DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Region(com.amazonaws.services.ec2.model.Region) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) Regions(com.amazonaws.regions.Regions)

Example 15 with Region

use of software.amazon.awssdk.services.ec2.model.Region in project aws-doc-sdk-examples by awsdocs.

the class DescribeInstances method main.

public static void main(String[] args) {
    Region region = Region.US_WEST_2;
    Ec2Client ec2 = Ec2Client.builder().region(region).build();
    describeEC2Instances(ec2);
    ec2.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) Ec2Client(software.amazon.awssdk.services.ec2.Ec2Client)

Aggregations

Region (software.amazon.awssdk.regions.Region)20 Ec2Client (software.amazon.awssdk.services.ec2.Ec2Client)20 AmazonClientException (com.amazonaws.AmazonClientException)3 AmazonServiceException (com.amazonaws.AmazonServiceException)3 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)3 Region (com.amazonaws.services.ec2.model.Region)3 Region (com.amazonaws.services.s3.model.Region)3 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)3 IOException (java.io.IOException)3 Date (java.util.Date)3 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)3 NamedThreadFactory (org.apache.jackrabbit.core.data.util.NamedThreadFactory)3 Regions (com.amazonaws.regions.Regions)2 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 Map (java.util.Map)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)1 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1