use of com.amazonaws.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.
the class AllocateAddress method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply an instance id\n" + "Ex: AllocateAddress <instance_id>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String instance_id = args[0];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
AllocateAddressRequest allocate_request = new AllocateAddressRequest().withDomain(DomainType.Vpc);
AllocateAddressResult allocate_response = ec2.allocateAddress(allocate_request);
String allocation_id = allocate_response.getAllocationId();
AssociateAddressRequest associate_request = new AssociateAddressRequest().withInstanceId(instance_id).withAllocationId(allocation_id);
AssociateAddressResult associate_response = ec2.associateAddress(associate_request);
System.out.printf("Successfully associated Elastic IP address %s " + "with instance %s", associate_response.getAssociationId(), instance_id);
}
use of com.amazonaws.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.
the class StartStopInstance method stopInstance.
public static void stopInstance(String instance_id) {
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DryRunSupportedRequest<StopInstancesRequest> dry_request = () -> {
StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);
return request.getDryRunRequest();
};
DryRunResult dry_response = ec2.dryRun(dry_request);
if (!dry_response.isSuccessful()) {
System.out.printf("Failed dry run to stop instance %s", instance_id);
throw dry_response.getDryRunResponse();
}
StopInstancesRequest request = new StopInstancesRequest().withInstanceIds(instance_id);
ec2.stopInstances(request);
System.out.printf("Successfully stop instance %s", instance_id);
}
use of com.amazonaws.services.ec2.model.Instance in project aws-doc-sdk-examples by awsdocs.
the class MonitorInstance method monitorInstance.
public static void monitorInstance(String instance_id) {
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DryRunSupportedRequest<MonitorInstancesRequest> dry_request = () -> {
MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id);
return request.getDryRunRequest();
};
DryRunResult dry_response = ec2.dryRun(dry_request);
if (!dry_response.isSuccessful()) {
System.out.printf("Failed dry run to enable monitoring on instance %s", instance_id);
throw dry_response.getDryRunResponse();
}
MonitorInstancesRequest request = new MonitorInstancesRequest().withInstanceIds(instance_id);
ec2.monitorInstances(request);
System.out.printf("Successfully enabled monitoring for instance %s", instance_id);
}
Aggregations