Welcome to the awsfabrictasks documentation!

Fabric (http://fabfile.org) tasks for Amazon Web Services with some extra utilities for Ubuntu.

Getting started

Fabric

Learn how to use Fabric.

The awsfab command

Fabric is great for remote execution because it allows you to run a task on any SSH-server with the following syntax:

$ fab -H server1,server2,server3 task1 task2

The problem with Fabric on AWS EC2 is that we do not have a static dns address to give to -H. awsfab wraps fab and allows us to use:

$ awsfab -E <Name-tag of an EC2 instance>,<Name-tag of another....> task1 task2

If your instance is not tagged with a name (the tag must be capitalized: Name), you can use --ec2ids instead.

Required settings

See awsfab_settings.py — Settings.

Making a fabfile.py and use awsfabrictasks

Example fabfile.py

Create a fabfile.py just as you would with Fabric, and import tasks from awsfabrictasks:

from fabric.api import task, run
from awsfabrictasks.decorators import ec2instance


###########################
# Add some of our own tasks
###########################

@task
def uname():
    """
    Run ``uname -a``
    """
    run('uname -a')


@task
@ec2instance(nametag='tst')
def example_nametag_specific_task():
    """
    Example of using ``@ec2instance``.
    Enables us to run::

        awsfab example_nametag_specific_task``

    and have it automatically use the EC2 instance tagged with ``Name="tst"``.
    """
    run('uname -a')


#####################
# Import awsfab tasks
#####################
from awsfabrictasks.ec2.tasks import *
from awsfabrictasks.regions import *
from awsfabrictasks.conf import *

Using the example

List basic information about your instances with:

$ bin/awsfab ec2_list_instances

Start one of your existing EC2 instances (the example assumes it is tagged with Name="mytest"):

$ bin/awsfab -E mytest ec2_start_instance

Login (SSH) to the instance we just started:

$ bin/awsfab -E mytest ec2_login

See:

$ bin/awsfab -l

or Tasks for more tasks.

Launch/create new EC2 instances

See Example awsfab_settings.py for and example of how to setup your EC2 launch configurations. After you have added EC2_LAUNCH_CONFIGS to your awsfab_settings.py, simply run:

$ awsfab ec2_launch_instance:<nametag>

where <nametag> is the name you want to tag your new instance with. You will be asked to choose a config from EC2_LAUNCH_CONFIGS, and to confirm all your choices before the instance in created.

More task-examples

The best examples are the provided tasks. Just browse the source, or use the [source] links in the tasks docs (tasks).

Indices and tables