Example usage for com.amazonaws.services.ec2.model AllocateAddressResult getAllocationId

List of usage examples for com.amazonaws.services.ec2.model AllocateAddressResult getAllocationId

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model AllocateAddressResult getAllocationId.

Prototype


public String getAllocationId() 

Source Link

Document

[EC2-VPC] The ID that AWS assigns to represent the allocation of the Elastic IP address for use with instances in a VPC.

Usage

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);//from   ww  w  .j  a  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.hpcloud.daas.ec2.AwsConsoleApp.java

License:Open Source License

public static String assignPublicIp(String instanceId) {
    AllocateAddressResult result = ec2.allocateAddress();

    AssociateAddressRequest assRequest = new AssociateAddressRequest();
    assRequest.setAllocationId(result.getAllocationId());
    assRequest.setPublicIp(result.getPublicIp());
    assRequest.setInstanceId(instanceId);

    AssociateAddressResult resp = ec2.associateAddress(assRequest);
    System.out.println(resp);// w w  w  .j a  va  2 s. c o m

    return (result.getPublicIp());
}

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 a  2  s.  co  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);//  w ww. ja va  2  s .co  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);
}