Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
akarve authored Sep 5, 2018
1 parent db8c1c9 commit 360a3d0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM amazonlinux:2017.03

RUN yum -y install git \
python36 \
python36-pip \
zip \
&& yum clean all

RUN python3 -m pip install --upgrade pip \
# boto3 is available to lambda processes by default,
# but it's not in the amazonlinux image
&& python3 -m pip install boto3

49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Script AWS Lambda deployment packages with Docker

## Why?

* Logging in to EC2 and
[creating a deployment package by hand](https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html)
is clumsy
* Instead, script package creation around the [`amazonlinux` image](https://hub.docker.com/_/amazonlinux/)
(blessed as an _official repository_ and
linked from [this AWS user guide](https://docs.aws.amazon.com/AmazonECR/latest/userguide/amazon_linux_container_image.html))

## Example: Python 3.6 deployment package

```sh
docker pull quiltdata/lambda

docker run --rm -v $(pwd)/create_table:/io -t \
-e SETUP_DIR -e GIT_REPO quiltdata/lambda \
bash /io/package.sh
```

* Mount `/io` as a docker volume
* `/io` should contain `package.sh` and your lambda code \
* `/io` is where the deployment package, lambda.zip, is written \
* Pass environment variables with `-e`
* `--rm` so that, for example, secure envs aren't written to disk


## Customize
Modify `package.sh` to suit your own purposes.

## Build container

```sh
docker build -t quiltdata/lambda .
```

## Clone private GitHub repo in container
Use a [personal access token](https://github.com/settings/tokens):

```sh
git clone https://${TOKEN}@github.com/USER/REPO
```

## Optimizations to reduce .zip size
Possible but not tried in this repo:
* [Delete *.py](https://github.com/ralienpp/simplipy/blob/master/README.md)
* [Profile code and only retain files that are used](https://medium.com/@mojodna/slimming-down-lambda-deployment-zips-b3f6083a1dff)

21 changes: 21 additions & 0 deletions package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

mkdir tmp411
git clone ${GIT_REPO}
python3 -m pip install ${SETUP_DIR} -t tmp411

# Untested optimization to reduce deployment size
# See https://github.com/ralienpp/simplipy/blob/master/README.md
# echo DELETING *.py `find tmp411 -name "*.py" -type f`
# find tmp411 -name "*.py" -type f -delete

# remove any old .zips
rm -f /io/lambda.zip

# grab existing products
cp -r /io/* tmp411

# zip without any containing folder (or it won't work)
cd tmp411
zip -r /io/lambda.zip *

0 comments on commit 360a3d0

Please sign in to comment.