Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
albertovara committed Jul 20, 2017
2 parents deea79c + 5a2b321 commit 3a5b650
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 40 deletions.
2 changes: 1 addition & 1 deletion ardy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

__author__ = "Alberto Vara"
__email__ = "a.vara.1986@gmail.com"
__version__ = "0.0.2"
__version__ = "0.0.3"
11 changes: 5 additions & 6 deletions ardy/core/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def set_src_path(self, src_folder):
def get_src_path(self):
return self.src_path

def run(self, src_folder, requirements=False, local_package=None):
def run(self, src_folder, requirements="requirements.txt", local_package=None):
"""Builds the file bundle.
:param str src:
The path to your Lambda ready project (folder must contain a valid
Expand Down Expand Up @@ -189,13 +189,12 @@ def pip_install_to_target(self, path, requirements="", local_package=None):
pass
else:
requirements_path = os.path.join(self.get_src_path(), requirements)
logger.debug('Gathering requirement packages {}'.format(requirements_path))
if os.path.exists(requirements_path):
logger.debug('Gathering packages from requirements: {}'.format(requirements_path))
if os.path.isfile(requirements_path):
data = self.read(requirements_path)
packages.extend(data.splitlines())

if not packages:
logger.debug('No dependency packages installed!')
else:
logger.debug('No requirements file in {}'.format(requirements_path))

if local_package is not None:
if not isinstance(local_package, (list, tuple)):
Expand Down
34 changes: 29 additions & 5 deletions ardy/core/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ardy.config import GlobalConfig
from ardy.core.build import Build
from ardy.core.deploy import Deploy

from ardy.utils.log import logger

class Command(object):
config = None
Expand Down Expand Up @@ -45,7 +45,14 @@ def __init__(self, *args, **kwargs):
help='Create an artefact and Upload to S3 if S3 is configured (See config)')
parser_build.add_argument("-r", "--requirements", help="Path and filename of the python project")
self.args = self.parser.parse_args(arguments)
self.parse_commandline()
try:
result = self.parse_commandline()
if result:
self.exit_ok("OK")
except Exception as e:
logger.error(e)

self.exit_with_error("ERROR")

@property
def parser_base(self):
Expand Down Expand Up @@ -74,7 +81,7 @@ def init_config(self, arguments):
def parse_commandline(self):
params = {}
run_params = {}

result = False
if self.args.command_name == "deploy":
if self.args.lambdafunctions and self.args.lambdafunctions is not "_ALL_":
params["lambdas_to_deploy"] = self.args.lambdafunctions
Expand All @@ -84,17 +91,34 @@ def parse_commandline(self):
run_params["path_to_zip_file"] = self.args.zipfile

deploy = Deploy(config=self.config, **params)
deploy.run(**run_params)
result = deploy.run(**run_params)

elif self.args.command_name == "invoke":
pass
elif self.args.command_name == "build":
if getattr(self.args, "requirements", False):
run_params["requirements"] = self.args.requirements
build = Build(config=self.config)
build.run(**params)
result = build.run(**params)
else:
self.parser.print_help()
return result

def exit_with_error(self, msg=""):
self.print_error(msg)
sys.exit(2)

def exit_ok(self, msg=""):
self.print_ok(msg)
sys.exit(0)

@staticmethod
def print_ok(msg=""):
print('\033[92m\033[1m ' + msg + ' \033[0m\033[0m')

@staticmethod
def print_error(msg=""):
print('\033[91m\033[1m ' + msg + ' \033[0m\033[0m')


if __name__ == '__main__':
Expand Down
2 changes: 0 additions & 2 deletions ardy/core/deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ def build_artefact(self, src_project=None):
code = {'S3Bucket': deploy_bucket, 'S3Key': s3_keyfile, }

elif deploy_method == "FILE":
print("DEPLOY FILE:")
print(self.config["deploy"]["deploy_file"])
code = {'ZipFile': self.build.read(self.config["deploy"]["deploy_file"])}
else:
raise Exception("No deploy_method in config")
Expand Down
2 changes: 1 addition & 1 deletion docs/awsdocs.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Code Examples
=============

To start working with AWS lambda I recommend you read this pages or do some lab:
To start working with AWS Lambda I recommend reading these pages or doing some labs:


Documentation
Expand Down
8 changes: 3 additions & 5 deletions docs/commandline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ optional arguments:

Commands:
- *deploy:* Upload functions to AWS Lambda
- *invoke:* Invoke a functions from AWS Lambda
- *invoke:* Invoke functions from AWS Lambda
- *build:* Create an artefact

If you want to deploy *all your AWS Lambdas* defined in your *config.json* file
Expand All @@ -22,15 +22,13 @@ If you want to deploy *all your AWS Lambdas* defined in your *config.json* file
ardy deploy
Or if you want to deploy a specific list of function, you can deploy the AWS Lambdas with:
Or if you want to deploy a specific list of functions, you can deploy the AWS Lambdas with:

.. code-block:: bash
ardy deploy MyLambda MyOtherLambda
You can deploy only a environment:

Or if you want to deploy a specific list of function, you can deploy the AWS Lambdas with:
You can deploy only an environment:

.. code-block:: bash
Expand Down
7 changes: 3 additions & 4 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ You can set the same keys as in Global Configuration, and it will be overridden.

* **lambdas:** [REQUIRED] List of dictionaries. You can define the key value pair defined below for each AWS Lambda you want to deploy.
* **FunctionName:** [REQUIRED] String. The name you want to assign to the function you are uploading
* **Handler:** [REQUIRED] String. The function within your code that Lambda calls to begin execution
* **Handler:** [REQUIRED] String. The function within your code that Lambda calls to start the execution
* **Description:** A short, user-defined function description
* **deploy_environments:** If `use_alias` is False, You can set the same keys as in Global Configuration and Lambda configuration, and it will be overridden.
If `use_alias` is True, one AWS Lambda is deployed and `Ardy` create an alias pinted to the Lambda Version. :doc:`more details about the alias </configuration.alias>`.
* **triggers:** :doc:`more details about events and triggers </configuration.triggers>`.
* **deploy_environments:** If `use_alias` is False, You can set the same keys as in Global Configuration and Lambda configuration, and it will be overridden. If use_alias is True, one AWS Lambda is deployed and Ardy create an alias pointed to the Lambda Version. Learn :doc:`more details about the alias </configuration.alias>`.
* **triggers:** :doc:`more details about events and triggers </configuration.triggers>`.

.. tip::
`Learn more about Versions and Alias here <http://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html>`_
Expand Down
2 changes: 1 addition & 1 deletion docs/deploy.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Deploy
======

To deploy your project, you can create a script or as a command in a shell (See :doc:`more details about the command line </commandline>`)
To deploy your project, you can create a script or add a command in a shell (See :doc:`more details about the command line </commandline>`)


.. code-block:: python
Expand Down
3 changes: 1 addition & 2 deletions docs/howtocontrib.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
How to contrib
==============
This project is build with `Git Flow <https://danielkummer.github.io/git-flow-cheatsheet/>`_. If you want to commit some
code use this pattern please:
This project is built with `Git Flow <https://danielkummer.github.io/git-flow-cheatsheet/>`_. If you want to commit some code, please use this pattern:

.. image:: http://nvie.com/img/git-model@2x.png
14 changes: 8 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
Ardy (Arthur Hendy)
===================

Ardy is a toolkit to work with AWS Lambas and implement Continuous Integration.
AWS Lambda is a serverless compute service that runs your code in response to events and automatically manages the underlying compute resources for you. Alas,
AWS Lambda has a very bad GUI interfaces, especially if you work with teams and releases. You can't see at a glance
the triggers you have active, the resources of your AWS Lambda or have a version control.
Ardy is a toolkit to work with AWS Lambda implementing Continuous Integration.
AWS Lambda is a serverless compute service that runs your code in response to events and automatically manages the
underlying compute resources for you. Alas, AWS Lambda has a very bad GUI interface, especially if you work with teams
and releases. You can’t easily see at a glance the active triggers you have, the resources of your AWS Lambda or have a
version control.

With `Ardy` you can manage your AWS Lambda with a JSON config file stored in your VCS.



.. warning::
If you want to work with AWS Lambda, it's recommended read about it. `Ardy` helps and support you to manage your environments but doesn't performs "The black magic" for you.
You can learn more about AWS Lambda in :doc:`this page </awsdocs>`
If you want to work with AWS Lambda, it’s recommended to read about it. `Ardy` helps and supports you to manage
environments but doesn’t performs "The black magic" for you. You can learn more about AWS Lambda in
:doc:`this page </awsdocs>`

Content
-------
Expand Down
19 changes: 18 additions & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,21 @@ You may also install a specific version:

.. code-block:: bash
pip install ardy==0.0.1
pip install ardy==0.0.1
Credentials
-----------

Before you can deploy an application, be sure you have credentials configured. If you have previously configured your machine to run boto3 (the AWS SDK for Python) or the AWS CLI then you can skip this section.

If this is your first time configuring credentials for AWS you can follow these steps to quickly get started:


.. code-block:: bash
$ mkdir ~/.aws
$ cat >> ~/.aws/credentials
[default]
aws_access_key_id=YOUR_ACCESS_KEY_HERE
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
region=YOUR_REGION (such as us-west-2, us-west-1, etc)
8 changes: 4 additions & 4 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Quickstart
==========

After start to work with `Ardy` or AWS Lambda, if you don't know anything about AWS Lambda I recommend you the :doc:`AWS documentation </awsdocs>`.
Before start working with Ardy or AWS Lambda, if you dont know anything about AWS Lambda I recommend you the :doc:`AWS documentation </awsdocs>`.

Suppose you have a project whith multiple lambas with the following structure:
Suppose you have a project with multiple lambas with the following structure:

.. code-block:: bash
Expand Down Expand Up @@ -69,10 +69,10 @@ If you want to deploy your AWS Lambdas, you just must run this command in a shel
ardy deploy
Or if you want to deploy a specific list of function, you can deploy the AWS Lambdas with:
Or if you want to deploy a specific list of functions, you can deploy the AWS Lambdas with:

.. code-block:: bash
ardy deploy MyLambda MyOtherLambda
See :doc:`more details about deploy </deploy>`
See :doc:`more details about how to deploy </deploy>`
12 changes: 11 additions & 1 deletion examples/simple/myexamplelambdaproject/lambda1/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import arrow

def my_handler(event, context):
message = 'Hello world lambda1! This is a new version 3'

utc = arrow.utcnow()
local = utc.to('US/Pacific')
date_to_print = local.humanize()

message = 'Hello world lambda1! at {}'.format(date_to_print)
return {
'message': message
}
1 change: 1 addition & 0 deletions examples/simple/myexamplelambdaproject/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
arrow==0.10.0
1 change: 0 additions & 1 deletion tests/test_deploy_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def test_run_with_trigger_sns(self, create_artefact_mock, copytree_mock, pip_ins
response = client.create_topic(
Name='TestLambdas'
)
print(response)

self.deploy = Deploy(path=os.path.dirname(os.path.abspath(__file__)), filename="config_with_triggers.json",
lambdas_to_deploy=["LambdaExample_SNS_8", ])
Expand Down

0 comments on commit 3a5b650

Please sign in to comment.