public void bind() throws MalformedURLException {
        InstanceInfo myInfo = ApplicationInfoManager.getInstance().getInfo();
        String myInstanceId = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.instanceId);
        String myZone = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.availabilityZone);

        final List<String> ips = getCandidateIps();
        Ordering<NetworkInterface> ipsOrder = Ordering.natural().onResultOf(new Function<NetworkInterface, Integer>() {
            public Integer apply(NetworkInterface networkInterface) {
                return ips.indexOf(networkInterface.getPrivateIpAddress());
            }
        });

        AmazonEC2 ec2Service = getEC2Service();
        String subnetId = instanceData(myInstanceId, ec2Service).getSubnetId();

        DescribeNetworkInterfacesResult result = ec2Service
                .describeNetworkInterfaces(new DescribeNetworkInterfacesRequest()
                                .withFilters(new Filter("private-ip-address", ips))
                                .withFilters(new Filter("status", Lists.newArrayList("available")))
                                .withFilters(new Filter("subnet-id", Lists.newArrayList(subnetId)))
                );

        if (result.getNetworkInterfaces().isEmpty()) {
            logger.info("No ip is free to be associated with this instance. Candidate ips are: {} for zone: {}", ips, myZone);
        } else {
            NetworkInterface selected = ipsOrder.min(result.getNetworkInterfaces());
            ec2Service.attachNetworkInterface(
                    new AttachNetworkInterfaceRequest()
                            .withNetworkInterfaceId(selected.getNetworkInterfaceId())
                            .withDeviceIndex(1)
                            .withInstanceId(myInstanceId)
            );
        }
    }
public void bind ( ) throws MalformedURLException { InstanceInfo myInfo = ApplicationInfoManager . getInstance ( ) . getInfo ( ) ; String myInstanceId = ( ( AmazonInfo ) myInfo . getDataCenterInfo ( ) ) . get ( AmazonInfo . MetaDataKey . instanceId ) ; String myZone = ( ( AmazonInfo ) myInfo . getDataCenterInfo ( ) ) . get ( AmazonInfo . MetaDataKey . availabilityZone ) ; final List < String > ips = getCandidateIps ( ) ; Ordering < NetworkInterface > ipsOrder = Ordering . natural ( ) . onResultOf ( new Function < NetworkInterface , Integer > ( ) { public Integer apply ( NetworkInterface networkInterface ) { return ips . indexOf ( networkInterface . getPrivateIpAddress ( ) ) ; } } ) ; AmazonEC2 ec2Service = getEC2Service ( ) ; String subnetId = instanceData ( myInstanceId , ec2Service ) . getSubnetId ( ) ; DescribeNetworkInterfacesResult result = ec2Service . describeNetworkInterfaces ( new DescribeNetworkInterfacesRequest ( ) . withFilters ( new Filter ( "private-ip-address" , ips ) ) . withFilters ( new Filter ( "status" , Lists . newArrayList ( "available" ) ) ) . withFilters ( new Filter ( "subnet-id" , Lists . newArrayList ( subnetId ) ) ) ) ; if ( result . getNetworkInterfaces ( ) . isEmpty ( ) ) { logger . info ( "No ip is free to be associated with this instance. Candidate ips are: {} for zone: {}" , ips , myZone ) ; } else { NetworkInterface selected = ipsOrder . min ( result . getNetworkInterfaces ( ) ) ; ec2Service . attachNetworkInterface ( new AttachNetworkInterfaceRequest ( ) . withNetworkInterfaceId ( selected . getNetworkInterfaceId ( ) ) . withDeviceIndex ( 1 ) . withInstanceId ( myInstanceId ) ) ; } }
Binds an ENI to the instance.

The candidate ENI's are deduced in the same wa the EIP binder works: Via dns records or via service urls,
depending on configuration.

It will try to attach the first ENI that is:
Available
For this subnet
In the list of candidate ENI's

@throws MalformedURLException