use of software.amazon.awssdk.services.ec2.model.AllocateAddressResponse 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 "";
}
Aggregations