Last active
June 27, 2018 14:28
-
-
Save zakkg3/5dab1b86b099f37ad74d2308ffad173d to your computer and use it in GitHub Desktop.
Assign private ip address to local ec2 instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
shopt -s expand_aliases | |
alias aws='docker run --rm -t $(tty &>/dev/null && echo "-i") -e "AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}" -v "$(pwd):/project" mesosphere/aws-cli' | |
PRIVATE_IP=$1 | |
INSTANCE_ID=`wget -q -O- http://169.254.169.254/latest/meta-data/instance-id` | |
ENI_ID=`aws ec2 describe-instances --filters "Name=instance-id,Values=$INSTANCE_ID" | grep "NetworkInterfaceId" | grep -oe 'eni\-[^"]*'` | |
aws ec2 assign-private-ip-addresses --network-interface-id $ENI_ID --private-ip-addresses $PRIVATE_IP --allow-reassignment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wget -q https://gist.githubusercontent.com/zakkg3/5dab1b86b099f37ad74d2308ffad173d/raw/22b061cf505734ba8205967ccc1be8c9288a4ff5/assign-private-ip.sh && chmod +x assign-private-ip.sh && ./assign-private-ip.sh 10.0.16.230