Skip to content

Instantly share code, notes, and snippets.

@hatan4ik
Forked from kntyskw/Assign me a VIP
Created January 24, 2019 20:33
Show Gist options
  • Save hatan4ik/4da913b347cf8731813bec3aafb58b4c to your computer and use it in GitHub Desktop.
Save hatan4ik/4da913b347cf8731813bec3aafb58b4c to your computer and use it in GitHub Desktop.
#!/bin/sh
VIP=$1
IF=$2
# Determine the interface's MAC address
MAC=`ip link show $IF | awk '/ether/ {print $2}'`
# Determine ENI ID of the interface
ENI_ID=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/interface-id`
# Set the current region as default
export AWS_DEFAULT_REGION=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone | rev | cut -c 2- | rev`
aws ec2 assign-private-ip-addresses\
--network-interface-id $ENI_ID\
--private-ip-addresses $VIP\
--allow-reassignment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment