Search in sources :

Example 1 with AllocateAddressRequest

use of com.amazonaws.services.ec2.model.AllocateAddressRequest in project photon-model by vmware.

the class AWSNetworkClient method allocateElasticIPAddress.

/**
 * Allocate an elastic IP address
 */
public DeferredResult<String> allocateElasticIPAddress() {
    AllocateAddressRequest req = new AllocateAddressRequest().withDomain(DomainType.Vpc);
    String message = "Allocate AWS Elastic IP Address for use with instances in a VPC.";
    AWSDeferredResultAsyncHandler<AllocateAddressRequest, AllocateAddressResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
    this.client.allocateAddressAsync(req, handler);
    return handler.toDeferredResult().thenApply(AllocateAddressResult::getAllocationId);
}
Also used : AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult)

Example 2 with AllocateAddressRequest

use of com.amazonaws.services.ec2.model.AllocateAddressRequest in project aws-doc-sdk-examples by awsdocs.

the class AllocateAddress method getAllocateAddress.

// snippet-start:[ec2.java2.allocate_address.main]
public static String getAllocateAddress(Ec2Client ec2, String instanceId) {
    try {
        AllocateAddressRequest allocateRequest = AllocateAddressRequest.builder().domain(DomainType.VPC).build();
        AllocateAddressResponse allocateResponse = ec2.allocateAddress(allocateRequest);
        String allocationId = allocateResponse.allocationId();
        AssociateAddressRequest associateRequest = AssociateAddressRequest.builder().instanceId(instanceId).allocationId(allocationId).build();
        AssociateAddressResponse associateResponse = ec2.associateAddress(associateRequest);
        return associateResponse.associationId();
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : AssociateAddressRequest(software.amazon.awssdk.services.ec2.model.AssociateAddressRequest) AssociateAddressResponse(software.amazon.awssdk.services.ec2.model.AssociateAddressResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) AllocateAddressResponse(software.amazon.awssdk.services.ec2.model.AllocateAddressResponse) AllocateAddressRequest(software.amazon.awssdk.services.ec2.model.AllocateAddressRequest)

Example 3 with AllocateAddressRequest

use of com.amazonaws.services.ec2.model.AllocateAddressRequest 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);
}
Also used : AssociateAddressResult(com.amazonaws.services.ec2.model.AssociateAddressResult) AssociateAddressRequest(com.amazonaws.services.ec2.model.AssociateAddressRequest) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult)

Aggregations

AllocateAddressRequest (com.amazonaws.services.ec2.model.AllocateAddressRequest)2 AllocateAddressResult (com.amazonaws.services.ec2.model.AllocateAddressResult)2 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 AssociateAddressRequest (com.amazonaws.services.ec2.model.AssociateAddressRequest)1 AssociateAddressResult (com.amazonaws.services.ec2.model.AssociateAddressResult)1 AllocateAddressRequest (software.amazon.awssdk.services.ec2.model.AllocateAddressRequest)1 AllocateAddressResponse (software.amazon.awssdk.services.ec2.model.AllocateAddressResponse)1 AssociateAddressRequest (software.amazon.awssdk.services.ec2.model.AssociateAddressRequest)1 AssociateAddressResponse (software.amazon.awssdk.services.ec2.model.AssociateAddressResponse)1 Ec2Exception (software.amazon.awssdk.services.ec2.model.Ec2Exception)1