Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #7 from mozilla-services/feat/issue-4
Browse files Browse the repository at this point in the history
feat: add lambda bundling and config
  • Loading branch information
bbangert committed Mar 30, 2016
2 parents 8ae973f + 1daadc5 commit 617662c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /bin/sh
APPNAME = push_messages
HERE = $(shell pwd)

.PHONY: all travis $(HERE)/ddb
.PHONY: all travis lambda-package

all: travis

Expand All @@ -12,3 +12,15 @@ travis: $(HERE)/ddb
$(HERE)/ddb:
mkdir $@
curl -sSL http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz | tar xzvC $@

$(HERE)/lenv:
virtualenv lenv
$(HERE)/lenv/bin/pip install -r lambda-requirements.txt
echo "#" > lenv/lib/python2.7/site-packages/zope/__init__.py
echo "#" > lenv/lib/python2.7/site-packages/repoze/__init__.py
echo "#" > lenv/lib/python2.7/site-packages/google/__init__.py
$(HERE)/lenv/bin/python setup.py develop

lambda-package: $(HERE)/lenv
pip install lambda-uploader
$(HERE)/ppenv/bin/lambda-uploader --virtualenv=lenv --no-upload
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,40 @@ Then:
$ source ppenv/bin/activate
$ pip install -r requirements.txt
$ python setup.py develop

## Creating an AWS Lambda Zipfile

After modifying ``push_processor/settings.js`` for your appropriate settings, a
Lambda-ready zipfile can be created with make:

$ make lambda-package

All files in the work directory are included except files listed in the
``ignore`` section of ``lambda.json``. Remove any other files that should not
be included in the zipfile from the work directory.

The AWS handler you should set is: ``lambda.handler``, which will then call
the Push Processor.

### Lambda VPC Access

The Push Processor needs access to both Redis and AWS DynamoDB. It will
likely be necessary to run the Lambda function in a VPC that has access to the
Elasticache Redis instance. Lambda requires the subnet(s) it runs in to have
NAT Gateway access to the Internet. A rough overview of what this looks like:

![NAT Gateway](assets/NAT-access-to-Internet.png)

1. Define one or more 'private' subnets, these are where your Lambda
function will run.
2. Define one or more 'public' subnets, these are where the NAT Gateway(s) will
be.
3. Create the NAT Gateway(s) in the 'public' subnets.
4. Create a route table for the 'public' subnet(s), and route '0.0.0.0/0' to the
VPC Internet Gateway. The public subnets should then be explicitly associated
with the new route table.
5. Create a route table for the 'private' subnet(s), and route '0.0.0.0/0' to a
NAT Gateway that you defined.

The Push Processor Lambda function should then be able to access both DynamoDB
and machines in the same 'private' subnet(s).
Binary file added assets/NAT-access-to-Internet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions lambda-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
git+https://github.com/mozilla-services/push-messages.git@7cf9ea53141f124d8131d65ff7a1a7b32afef8e0#egg=push-messages
boto3==1.2.6
gzip_reader==0.1
protobuf==2.6.1
redis==2.10.5
twisted==16.0.0
20 changes: 20 additions & 0 deletions lambda.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "PushProcessor",
"description": "Process Push Messages",
"region": "us-east-1",
"handler": "push_processor.handler.handler",
"role": "arn:aws:iam::00000000000:role/lambda_basic_execution",
"ignore": [
"circle.yml",
".git",
"/*.pyc",
".tox",
"ddb",
"ppenv",
"lenv",
"/*.txt",
"/*.json"
],
"timeout": 30,
"memory": 128
}
3 changes: 3 additions & 0 deletions lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from push_processor.handler import Lambda

handler = Lambda.handler

0 comments on commit 617662c

Please sign in to comment.