aws-ec2-assign-elastic-ip
aws-ec2-assign-elastic-ip copied to clipboard
Assign from a pool of EIP
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
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.