aws-ec2-assign-elastic-ip icon indicating copy to clipboard operation
aws-ec2-assign-elastic-ip copied to clipboard

Assign from a pool of EIP

Open flickerfly opened this issue 6 years ago • 1 comments

I'd like to be able to grab an IP from a pool of IPs. For now this in userdata does the trick for me, but this seems like useful thing for this script to support.

ALLOCATION_ID=`aws ec2 describe-addresses --filters="Name=tag:Name,Values=mail" | jq -r '.Addresses[] | "\(.InstanceId) \(.AllocationId)"' | grep null | awk '{print $2}' | xargs shuf -n1 -e`

if [ ! -z $ALLOCATION_ID ]; then
  aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $ALLOCATION_ID --allow-reassociation
fi

flickerfly avatar Dec 27 '18 18:12 flickerfly

Is what you want to do to get a pool of IPs based on some filter? Currently the script only allows for a pool/list of IPs to be entered on the command line.

What I have done is to populate the command line argument dynamically using CloudFormation. But that of course requires you to use CloudFormation.

sebdah avatar Jan 04 '19 09:01 sebdah