awsfab_settings.py — Settings¶
Required setup¶
awsfabrictasks uses a settings system similar to the Django settings
module. You add your settings to awsfab_settings.py
.
Required configuration¶
Create a file named awsfab_settings.py
, and add your AWS Security credentials:
AUTH = {'aws_access_key_id': 'Access Key ID',
'aws_secret_access_key': 'Secret Access Key'}
You find these under My account -> Security Credentials
on
http://aws.amazon.com/.
.pem-key¶
The .pem
-keys (key pairs) for you instances (the ones used for SSH login)
must be added to ~/.ssh/
or the current directory. You can change these directories
with the awsfab_settings.KEYPAIR_PATH
variable (see Default settings).
Local override¶
You may override settings in awsfab_settings_local.py
, which is typically
used to store authentication credentials outside your version control system
(i.e: with git you would add awsfab_settings_local.py to .gitignore).
Override name of settings module¶
awsfab_settings.py
defines the awsfab_settings
python module. Importing
the module works because awsfab adds the current working directory to your
PYTHONPATH
. You can override the name of this module using
--awsfab-settings <modulename>
. When you override the settings module, you
also override the name of the corresponding local override. The local override
is always <settings-module-name>_local
.
To sum this up, you do the following to create a custom settings file named
my_awsfab_settings.py
with a local override:
Create
my_awsfab_settings.py
.Create
my_awsfab_settings_local.py
(optional).Run with:
$ awsfab --awsfab-settings my_awsfab_settings
Warning
The --awsfab-settings
module can NOT be a dotted path (it can be my_test_module
, but NOT my.test.module
).
Example awsfab_settings.py¶
# Config file for awsfabrictasks.
#
# This is a Python module, and it is imported just as a regular Python module.
# Every variable with an uppercase-only name is a setting.
AUTH = {'aws_access_key_id': 'XXXXXXXXXXXXXXXXXXXXXX',
'aws_secret_access_key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
DEFAULT_REGION = 'eu-west-1'
##################################################################
# Self documenting map of AMIs
# - You are not required to use this, but it makes it easier to read
# EC2_LAUNCH_CONFIGS.
##################################################################
ami = {
'ubuntu-10.04-lts': 'ami-fb665f8f'
}
##################################################################
# Example user_data
# This script will be passed to the new instance at boot
# time and run late in the boot sequence.
# It can be used to do arbitrarily complex setup tasks.
# info: http://ubuntu-smoser.blogspot.co.uk/2010/03/introducing-cloud-inits-cloud-config.html
##################################################################
user_data_example = """#!/bin/sh
echo ========== Hello World: $(date) ==========
echo "I have been up for $(cut -d\ -f 1 < /proc/uptime) sec"
"""
###########################################################
# Configuration for ec2_launch_instance
###########################################################
EC2_LAUNCH_CONFIGS = {
'ubuntu-10.04-lts-micro': {
'description': 'Ubuntu 10.04 on the least expensive instance type.',
# Ami ID (E.g.: ami-fb665f8f)
'ami': ami['ubuntu-10.04-lts'],
# One of: m1.small, m1.large, m1.xlarge, c1.medium, c1.xlarge, m2.xlarge, m2.2xlarge, m2.4xlarge, cc1.4xlarge, t1.micro
'instance_type': 't1.micro',
# List of security groups
'security_groups': ['allowssh'],
# Use the ``list_regions`` task to see all available regions
'region': DEFAULT_REGION,
# The name of the key pair to use for instances (See http://console.aws.amazon.com -> EC2 -> Key Pairs)
'key_name': 'awstestkey',
# The availability zone in which to launch the instances. This is
# automatically prefixed by ``region``.
'availability_zone': 'b',
# Tags to add to the instances. You can use the ``ec2_*_tag`` tasks or
# the management interface to manage tags. Special tags:
# - Name: Should not be in this dict. It is specified when launching
# an instance (needs to be unique for each instance).
# - awsfab-ssh-user: The ``awsfab`` tasks use this user to log into your instance.
'tags': {
'awsfab-ssh-user': 'ubuntu'
},
'user_data': user_data_example
}
}
######################################################
# Add your own settings here
######################################################
MYCOOLSTUFF_REMOTE_DIR = '/var/www/stuff'
Default settings¶
-
awsfabrictasks.default_settings.
AUTH
= {}¶ The AWS access key. Should look something like this:
AUTH = {'aws_access_key_id': 'XXXXXXXXXXXXXXXXX', 'aws_secret_access_key': 'aaaaaaaaaaaa\BBBBBBBBB\dsaddad'}
-
awsfabrictasks.default_settings.
DEFAULT_REGION
= 'eu-west-1'¶ The default AWS region to use with the commands where REGION is supported.
-
awsfabrictasks.default_settings.
EC2_INSTANCE_DEFAULT_SSHUSER
= 'root'¶ Default ssh user if the
awsfab-ssh-user
tag is not set
-
awsfabrictasks.default_settings.
EC2_LAUNCH_CONFIGS
= {}¶ Configuration for ec2_launch_instance (see the docs)
-
awsfabrictasks.default_settings.
EXTRA_SSH_ARGS
= '-o StrictHostKeyChecking=no'¶ Extra SSH arguments. Used with
ssh
andrsync
.
-
awsfabrictasks.default_settings.
KEYPAIR_PATH
= ['.', '~/.ssh/']¶ Directories to search for “<key_name>.pem”. These paths are filtered through os.path.expanduser, so paths like
~/.ssh/
works.
-
awsfabrictasks.default_settings.
S3_BUCKET_PATTERN
= '{bucketname}'¶ S3 bucket suffix. This is used for all tasks taking bucketname as parameter. The actual bucketname used become:
S3_BUCKET_PATTERN.format(bucketname=bucketname)
This is typically used to add your domain name or company name to all bucket names, but avoid having to type the entire name for each task. Examples:
S3_BUCKET_PATTERN = '{bucketname}.example.com' S3_BUCKET_PATTERN = 'example.com.{bucketname}'
The default,
"{bucketname}"
, uses the bucket name as provided by the user without any changes.