JClouds: How Do You Ask For an AWS-EC2 Public IP Address

45 Views Asked by At

When using Apache JClouds, how do you get launch a compute instance with a public IP? This is different from an elastic IP. Using the official AWS API you can do something like:

//create network information
InstanceNetworkInterfaceSpecification networkWithPublicIp = new InstanceNetworkInterfaceSpecification()
            .withSubnetId(subnetId)
            .withAssociatePublicIpAddress(true)
            .withGroups( securityGroupIds )
            .withDeviceIndex(0);

Once the node is launched, it will have a randomly assigned public IP (not elastic). Is there a way to do this with Jclouds and AWSEC2TemplateOptions?

1

There are 1 best solutions below

3
Andrea Turli On

There is an example in the doc at http://jclouds.apache.org/guides/aws/

// ex. to get an ip and associate it with a node
String ip = ec2Client.getElasticIPAddressServices().allocateAddressInRegion(node.getLocation().getId());
ec2Client.getElasticIPAddressServices().associateAddressInRegion(node.getLocation().getId(),ip, node.getProviderId());