Skip to content

Instantly share code, notes, and snippets.

@zakkg3
Last active June 27, 2018 14:28
Show Gist options
  • Save zakkg3/5dab1b86b099f37ad74d2308ffad173d to your computer and use it in GitHub Desktop.
Save zakkg3/5dab1b86b099f37ad74d2308ffad173d to your computer and use it in GitHub Desktop.
Assign private ip address to local ec2 instance
#!/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
@zakkg3
Copy link
Author

zakkg3 commented Jun 27, 2018

@zakkg3
Copy link
Author

zakkg3 commented Jun 27, 2018

dependencies: Docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment