Created
July 17, 2014 19:19
-
-
Save KensoDev/82c3ff22a0dd2fd42f0c to your computer and use it in GitHub Desktop.
create new web server using the ec2-tools
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 | |
region=us-west-2 | |
ami=ami-927613a2 | |
# http://cloud-images.ubuntu.com/locator/ec2/ | |
echo "Input server name: " | |
read server_name | |
USERDATA=$(cat <<-EOF | |
#cloud-config | |
runcmd: | |
- curl -L https://www.opscode.com/chef/install.sh | bash | |
bootcmd: | |
- echo 127.0.1.1 ${server_name}.www.gogobot.com ${server_name} www.gogobot.com >> /etc/hosts | |
- echo ${server_name} > /etc/hostname | |
- hostname ${server_name} | |
- [ cloud-init-per, once, data-store, mkfs.ext4, /dev/xvdb ] | |
mounts: | |
- [ xvdb, /mnt, ext4 ] | |
- [ ephemeral0, /eph0, auto, "defaults,noexec" ] | |
- [ ephemeral1, none, swap ] | |
preserve_hostname: true | |
EOF) | |
ec2-run-instances --region $region \ | |
-b "/dev/sdb=:100:true" \ | |
-b "/dev/sdj=ephemeral0" -b "/dev/sdk=ephemeral1" \ | |
--user-data "${USERDATA}" \ | |
--group GROUP_ID \ | |
--key KEY_NAME \ | |
--instance-type c3.2xlarge \ | |
--availability-zone "${region}b" \ | |
$ami | |
echo "Input the instance id: " | |
read instance_id | |
ec2-create-tags ${instance_id} --tag "Name=${server_name}" | |
ec2-allocate-address | |
echo "Input the ip address: " | |
read ip_address | |
ec2-associate-address -i ${instance_id} ${ip_address} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment