Search in sources :

Example 1 with AssociateAddressResponse

use of software.amazon.awssdk.services.ec2.model.AssociateAddressResponse 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)

Aggregations

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