Created
December 20, 2012 04:23
-
-
Save v64/4342956 to your computer and use it in GitHub Desktop.
Scripted setup of an AWS micro instance webserver, takes a subdomain for a cname as an argument
This file contains hidden or 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 | |
| if [ ! $1 ] | |
| then | |
| echo "Subdomain argument is required" | |
| exit | |
| fi | |
| export EC2_HOME="/your/path/to/ec2/tools" | |
| export JAVA_HOME=$(/usr/libexec/java_home) | |
| export AWS_ACCESS_KEY="your_access_key" | |
| export AWS_SECRET_KEY="your_secret_key" | |
| DOMAIN="yourdomain.com" | |
| DNS_ACCESS_KEY_ID="your_access_key" | |
| DNS_SECRET_ACCESS_KEY="your_secret_key" | |
| UPDATE_ROUTE53_DNS="http://yourdomain.com/update-route53-dns" | |
| MYSQL_SETUP="http://yourdomain.com/mysql-setup" | |
| PORT=64064 | |
| KEY_PAIR="your_keypair" | |
| SECURITY_GROUP="your_security_group" | |
| REGION="us-east-1" | |
| INSTANCE_TYPE="t1.micro" | |
| AMI="ami-1624987f" | |
| cat > /tmp/user-data << EOF | |
| #!/bin/bash | |
| curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python | |
| pip install cli53 | |
| mkdir /etc/route53 | |
| chmod 700 /etc/route53 | |
| touch /etc/route53/config | |
| chmod 600 /etc/route53/config | |
| echo "AWS_ACCESS_KEY_ID=\"$DNS_ACCESS_KEY_ID\"" >> /etc/route53/config | |
| echo "AWS_SECRET_ACCESS_KEY=\"$DNS_SECRET_ACCESS_KEY\"" >> /etc/route53/config | |
| echo "DOMAIN=\"$DOMAIN\"" >> /etc/route53/config | |
| echo "SUBDOMAIN=\"$1\"" >> /etc/route53/config | |
| echo "TTL=\"300\"" >> /etc/route53/config | |
| curl $UPDATE_ROUTE53_DNS | bash | |
| yum -y install httpd php php-mysql mysql-server expect git | |
| service httpd start | |
| service mysqld start | |
| curl $MYSQL_SETUP | bash | |
| perl -i -pe 's/#Port 22/Port $PORT/' /etc/ssh/sshd_config | |
| service sshd restart | |
| EOF | |
| EC2_RUN_RESULT=$(ec2-run-instances --instance-type $INSTANCE_TYPE --group $SECURITY_GROUP --region $REGION --key $KEY_PAIR --block-device-mapping "/dev/sda1=:8:true" --instance-initiated-shutdown-behavior stop --user-data-file /tmp/user-data $AMI) | |
| INSTANCE_ID=$(echo ${EC2_RUN_RESULT} | sed 's/RESERVATION.*INSTANCE //' | sed 's/ .*//') | |
| ec2-create-tags $INSTANCE_ID --tag Name=$1.$DOMAIN | |
| rm /tmp/user-data | |
| echo Successfully created $1.$DOMAIN with instance id $INSTANCE_ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scripts for UPDATE_ROUTE53_DNS and MYSQL_SETUP can be found at:
http://jahnvea.ch/update-route53-dns
http://jahnvea.ch/mysql-setup