Skip to content

Commit

Permalink
Merge 48ed024 into daf41c6
Browse files Browse the repository at this point in the history
  • Loading branch information
javimuu committed Oct 27, 2016
2 parents daf41c6 + 48ed024 commit 85c35d2
Show file tree
Hide file tree
Showing 1,493 changed files with 19,024 additions and 22,930 deletions.
9 changes: 9 additions & 0 deletions .gitignore
@@ -1,3 +1,6 @@
*~
*.zip

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -64,3 +67,9 @@ target/

# Apple OS X specific files are put into the .DS_Store file
.DS_Store

# Vim stuff:
*.swp
*.swo
*~
tests/zappa_settings.json
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ python:
- "2.7"
# command to install dependencies
install:
- "pip install setuptools --upgrade; pip install -r test_requirements.txt; python setup.py install"
- "pip install setuptools --upgrade; pip install -r test_requirements.txt; python setup.py install"
# command to run tests
script: nosetests --with-coverage --cover-package=zappa
after_success:
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,25 @@
# Zappa Changelog

## 0.24.2

* Fix a problem from trying to `update` old-style API routes using new Tropo code. Ensures `touch` works as intended again. Fix by @mathom.

## 0.24.1

* Add a helpful failure warning for users without permissions to automatically manage execution roles.
* Fix potential div by zero error in new Tropo code.

## 0.24.0

* Use Troposphere/CloudFormation to create API Gateway routes
- Thanks, @mathom!
* `zappa update` now updates changes to API Gateway routes
* Redirect HTML content injection is fixed
* Redirect HTML content injection now only happens for 'text/html' content types. This is a partial solution to #303.
* Added CHANGELOG.md

## 0.0.1 - 0.23.2

* Didn't keep a changelog
* Sorry!
* Read the commit log :)
499 changes: 454 additions & 45 deletions README.md

Large diffs are not rendered by default.

Binary file added docs/_static/zappa_demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 170 additions & 0 deletions docs/advanced.rst
@@ -0,0 +1,170 @@
==============
Advanced Usage
==============

Rollback
========

You can also rollback the deployed code to a previous version by supplying the number of revisions to return to. For instance, to rollback to the version deployed 3 versions ago:

$ zappa rollback production -n 3

Scheduling
==========

Zappa can be used to easily schedule functions to occur on regular intervals. Just list your functions and the expression to schedule them using `cron or rate syntax <http://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html>`_ in your *zappa_settings.json* file:

::

{
"production": {
...
"events": [{
"function": "your_module.your_function", // The function to execute
"expression": "rate(1 minute)" // When to execute it (in cron or rate format)
}],
...
}

And then:
::

$ zappa schedule production

And now your function will execute every minute!

If you want to cancel these, you can simply use the 'unschedule' command:
::

$ zappa unschedule production

And now your scheduled event rules are deleted.

Executing in Response to AWS Events
===================================

Similarly, you can have your functions execute in response to events that happen in the AWS ecosystem, such as S3 uploads, DynamoDB entries, Kinesis streams, and SNS messages.

In your *zappa_settings.json* file, define your `event sources <http://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html>`_ and the function you wish to execute. For instance, this will execute *your_module.your_function* in response to new objects in your *my-bucket* S3 bucket. Note that *your_function* must accept *event* and *context* paramaters.

::

{
"production": {
...
"events": [{
"function": "your_module.your_function",
"event_source": {
"arn": "arn:aws:s3:::my-bucket",
"events": [
"s3:ObjectCreated:*"
]
}
}],
...
}
}

And then:
::

$ zappa schedule production

And now your function will execute every time a new upload appears in your bucket!

Undeploy
========

If you need to remove the API Gateway and Lambda function that you have previously published, you can simply:
::

$ zappa undeploy production

You will be asked for confirmation before it executes.

Tailing Logs
============

You can watch the logs of a deployment by calling the ``tail`` management command.
::

$ zappa tail production

Remote Function Invocation
==========================

You can execute any function in your application directly at any time by using the ``invoke`` command.

For instance, suppose you have a basic application in a file called "my_app.py", and you want to invoke a function in it called "my_function". Once your application is deployed, you can invoke that function at any time by calling:
::

$ zappa invoke production 'my_app.my_function'

Any remote print statements made and the value the function returned will then be printed to your local console. **Nifty!**

Django Management Commands
==========================

As a convenience, Zappa can also invoke remote Django 'manage.py' commands with the ``manage`` command. For instance, to perform the basic Django status check:
::

$ zappa manage production check

Obviously, this only works for Django projects which have their settings properly defined. (*Please note that commands which take over 30 seconds to execute may time-out. See* `this related issue <https://github.com/Miserlou/Zappa/issues/205#issuecomment-236391248>`_ *for a work-around.)*

Keeping The Server Warm
=======================

Zappa will automatically set up a regularly occuring execution of your application in order to keep the Lambda function warm. This can be disabled via the 'keep_warm' setting.

Enabling CORS
=============

To enable Cross-Origin Resource Sharing (CORS) for your application, follow the `AWS "How to CORS" Guide <https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html>`_ to enable CORS via the API Gateway Console. Don't forget to enable CORS per parameter and re-deploy your API after making the changes!

Enabling Secure Endpoints on API Gateway
========================================

You can use the ``api_key_required`` setting to generate and assign an API key to all the routes of your API Gateway. After redeployment, you can then pass the provided key as a header called ``x-api-key`` to access the restricted endpoints. Without the ``x-api-key`` header, you will receive a 403. See `more information on API keys in the API Gateway <http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-api-keys.html>`_.

You can enable IAM-based (v4 signing) authorization on an API by setting the ``authorization_type`` setting to ``AWS_IAM``. Your API will then require signed requests and access can be controlled via `IAM policy <https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-iam-policy-examples.html>`. Unsigned requests will receive a 403 response, as will requesters who are not authorized to access the API.

Deploying to a Domain With a Let's Encrypt Certificate
======================================================

If you want to use Zappa on a domain with a free Let's Encrypt certificate, you can follow `this guide <https://github.com/Miserlou/Zappa/blob/master/docs/domain_with_free_ssl.md>`_.

Setting Environment Variables
=============================

If you want to use environment variables to configure your application (which is especially useful for things like sensitive credentials), you can create a file and place it in an S3 bucket to which your Zappa application has access to. To do this, add the ``remote_env_bucket`` and ``remote_env_file`` keys to zappa_settings pointing to a file containing a flat JSON object, so that each key-value pair on the object will be set as an environment variable and value whenever a new lambda instance spins up.

For example, to ensure your application has access to the database credentials without storing them in your version control, you can add a file to S3 with the connection string and load it into the lambda environment using the ``remote_env_bucket`` and ``remote_env_file`` configuration settings.

super-secret-config.json (uploaded to my-config-bucket):

::

{
"DB_CONNECTION_STRING": "super-secret:database"
}

zappa_settings.json:

::

{
"dev": {
...
"remote_env_bucket": "my-config-bucket",
"remote_env_file": "super-secret-config.json"
},
...
}

Now in your application you can use:

::

import os
db_string = os.environ.get('DB_CONNECTION_STRING')
16 changes: 9 additions & 7 deletions docs/conf.py
Expand Up @@ -12,6 +12,7 @@
# serve to show the default.

import sys, os
import sphinx_rtd_theme

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -40,8 +41,9 @@
master_doc = 'index'

# General information about the project.
project = u'sample'
copyright = u'2012, Kenneth Reitz'
project = u'Zappa'
# copyright = u'2012, Kenneth Reitz'
copyright = u'2016'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -91,15 +93,15 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
Expand Down Expand Up @@ -184,7 +186,7 @@
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'sample.tex', u'sample Documentation',
u'Kenneth Reitz', 'manual'),
u'Development', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -214,7 +216,7 @@
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'sample', u'sample Documentation',
[u'Kenneth Reitz'], 1)
[u'Development'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -228,7 +230,7 @@
# dir menu entry, description, category)
texinfo_documents = [
('index', 'sample', u'sample Documentation',
u'Kenneth Reitz', 'sample', 'One line description of project.',
u'Developmnet', 'sample', 'One line description of project.',
'Miscellaneous'),
]

Expand Down

0 comments on commit 85c35d2

Please sign in to comment.