Mitch Garnaat

Merge pull request #2 from nonspecialist/develop

Support for environment variable credentials; handle stack creation failure
......@@ -40,6 +40,9 @@ Where ``command`` is one of:
The ``config file`` is a YAML format file containing all of the information
about your Lambda function.
If you use environment variables for your AWS credentials (as normally supported by boto),
simply exclude the ``profile`` element from the YAML file.
An example project based on a Kinesis stream can be found in
[samples/kinesis](https://github.com/garnaat/kappa/tree/develop/samples/kinesis).
......@@ -56,4 +59,4 @@ The basic workflow is:
* Run ``kappa --config <path-to-config> tail`` to see more output
If you have to make changes in your function or in your IAM roles, simply run
``kappa deploy`` again and the changes will be uploaded as necessary.
\ No newline at end of file
``kappa deploy`` again and the changes will be uploaded as necessary.
......
......@@ -25,11 +25,16 @@ LOG = logging.getLogger(__name__)
class Kappa(object):
completed_states = ('CREATE_COMPLETE', 'UPDATE_COMPLETE')
failed_states = ('ROLLBACK_COMPLETE')
def __init__(self, config):
self.config = config
self.session = botocore.session.get_session()
self.session.profile = config['profile']
# otherwise, assume we'll use environment variables
if 'profile' in config:
self.session.profile = config['profile']
else:
self.session.profile = None
self.region = config['region']
def create_update_roles(self, stack_name, roles_path):
......@@ -63,6 +68,8 @@ class Kappa(object):
LOG.debug('Stack status is: %s', status)
if status in self.completed_states:
done = True
if status in self.failed_states:
raise ValueError('Could not create stack %s: %s' % (stack_name, status))
def get_role_arn(self, role_name):
role_arn = None
......@@ -231,6 +238,7 @@ class Kappa(object):
self.config['lambda']['zipfile_name'],
self.config['lambda']['path'])
self.upload_lambda_function(self.config['lambda']['zipfile_name'])
self.add_event_source()
def test(self):
self._invoke_asynch(self.config['lambda']['test_data'])
......