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();
}
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();
}
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();
}
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));
});
}
}
};
}
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();
}
Aggregations