sebdah / aws-ec2-assign-elastic-ip

Automatically assign Elastic IPs to AWS EC2 Auto Scaling Group instances
Apache License 2.0
175 stars 58 forks source link

Assign from a pool of EIP #31

Open flickerfly opened 5 years ago

flickerfly commented 5 years ago

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
sebdah commented 5 years ago

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.