Last active
August 29, 2015 14:05
-
-
Save objectified/78f2f16066ea8327c9e1 to your computer and use it in GitHub Desktop.
Minimal Fabric script to setup an AWS Ubuntu instance and run some commands on it
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
import time | |
from fabric.api import run, execute, task, settings, sudo | |
import boto.ec2 | |
@task | |
def create_aws_server(): | |
conn = boto.ec2.connect_to_region('eu-west-1') | |
reservation = conn.run_instances('ami-blabla', | |
instance_type='t2.micro', | |
security_group_ids=['sg-bladiebla'], | |
key_name='nameofkey-given-inconsole' | |
) | |
instance = reservation.instances[0] | |
while instance.state != 'running': | |
time.sleep(3) | |
instance.update() | |
print '\nNow the state of the instance is: %s' % instance.state | |
print 'Its IP address is: %s' % instance.ip_address | |
with(settings(host_string=instance.public_dns_name, key_filename='/path/to/ssh/keys.pem', user='ubuntu', connection_attempts=10)): | |
execute(install_apache) | |
execute(install_apache) | |
def install_apache(): | |
sudo('apt-get update') | |
sudo('apt-get install -y apache2 libapache2-mod-php5') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment