List of usage examples for com.amazonaws.services.ec2 AmazonEC2 allocateAddress
AllocateAddressResult allocateAddress(AllocateAddressRequest allocateAddressRequest);
Allocates an Elastic IP address to your AWS account.
From source file:aws.example.ec2.AllocateAddress.java
License:Open Source License
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);// www. ja v a2 s. c o m } 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); }
From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java
License:Apache License
/** * This will request a new elastic IP from Amazon and return the AllocationId * associated with that new elasticIp.// w w w . j av a2 s. c o m * * @param ec2Client * @return allocationId */ public String requestElasticIp(AmazonEC2 ec2Client) { String result = null; ; AllocateAddressRequest allReq = new AllocateAddressRequest().withDomain(DomainType.Vpc); AllocateAddressResult allRes = ec2Client.allocateAddress(allReq); result = allRes.getAllocationId(); log.info("Elastic Ip allocated: " + allRes.getPublicIp()); log.info("Allocation Id: " + result); return result; }
From source file:ec2.AllocateAddress.java
License:Open Source License
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);//from w ww .j a v a2s . c o m } String instanceId = args[0]; final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); AllocateAddressRequest allocateAddressRequest = new AllocateAddressRequest().withDomain(DomainType.Vpc); AllocateAddressResult allocateAddressResponsee = ec2.allocateAddress(allocateAddressRequest); String allocationId = allocateAddressResponsee.getAllocationId(); AssociateAddressRequest request = new AssociateAddressRequest().withInstanceId(instanceId) .withAllocationId(allocationId); AssociateAddressResult response = ec2.associateAddress(request); System.out.printf("Successfully associated elastic ip address %s with instance %s", response.getAssociationId(), instanceId); }