Last active
November 16, 2015 02:48
-
-
Save takuma-saito/f11adce046402fd5b777 to your computer and use it in GitHub Desktop.
create-instance-by-eip
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/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