Skip to content

Instantly share code, notes, and snippets.

@takuma-saito
Last active November 16, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuma-saito/f11adce046402fd5b777 to your computer and use it in GitHub Desktop.
Save takuma-saito/f11adce046402fd5b777 to your computer and use it in GitHub Desktop.
create-instance-by-eip
#!/bin/zsh
AMI="ami-xxxxxxx" # Official CentOS 7.0 AMI in ap-northeast-1 region
ALOCID="eipalloc-xxxxxxx" # Allocating ip address
SIZE="m3.large"
KEYNAME="jobfind"
SEC_GROUP="default"
InstanceId=$(aws ec2 run-instances \
--count 1 \
--image-id $AMI \
--instance-type $SIZE \
--key-name $KEYNAME \
--security-groups $SEC_GROUP |
jq -r '.Instances[].InstanceId')
# We have to wait until instance state changes running
aws ec2 wait instance-running --instance-ids $InstanceId
aws ec2 associate-address \
--instance-id $InstanceId \
--allocation-id $ALOCID
IP=$(aws ec2 describe-addresses |
jq -r '.Addresses[] | select(.AllocationId == "'$ALOCID'") | .PublicIp')
# ssh-keygen -R $IP
# ssh-keygen -R \[$IP\]:7822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment