-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * | ||
|