|
1 | 1 | # alpine-aws-python-lambda |
2 | | -Lightweight docker image for running and packaging python-lambda code |
| 2 | +Lightweight docker image for running and packaging python-lambda code. |
| 3 | + |
| 4 | +This is based on the super useful python-lambda library: |
| 5 | + |
| 6 | +<https://github.com/nficano/python-lambda/> |
| 7 | + |
| 8 | +# Usage |
| 9 | + |
| 10 | +An example of a usable project can be found in the <example/> directory. This example lambda function |
| 11 | +takes a JSON input file like event.json and returns an ASCII-art version of the text. |
| 12 | + |
| 13 | +```$ cd example/ |
| 14 | +``` |
| 15 | + |
| 16 | +The Dockerfile in the example directory loads the current workspace into the image and installs |
| 17 | +dependencies from the requirements.txt file: |
| 18 | + |
| 19 | +```FROM kilna/alpine-aws-python-lambda |
| 20 | +COPY . /workspace |
| 21 | +RUN pip install -r requirements.txt |
| 22 | +``` |
| 23 | + |
| 24 | +To build a docker image called 'example-lambda-image' with the lambda function in it, run: |
| 25 | + |
| 26 | +```$ docker build --tag example-lambda-image . |
| 27 | +``` |
| 28 | + |
| 29 | +If you want to execute the lambda function against an event.json input file: |
| 30 | + |
| 31 | +```$ docker run example-lambda-image lambda invoke |
| 32 | + _ _ _ _ _ _ _ |
| 33 | + | || | ___ | | | | ___ __ __ __ ___ _ _ | | __| | | | |
| 34 | + | __ | / -_) | | | | / _ \ _ \ V V / / _ \ | '_| | | / _` | |_| |
| 35 | + |_||_| \___| |_| |_| \___/ ( ) \_/\_/ \___/ |_| |_| \__,_| (_) |
| 36 | + |/ |
| 37 | +
|
| 38 | +``` |
| 39 | + |
| 40 | +If you would like to see if your lambda function builds properly, run: |
| 41 | + |
| 42 | +```$ docker run example-lambda-image lambda build |
| 43 | +``` |
| 44 | + |
| 45 | +If you would like to get a ZIP file of the lambda function suitable for uploading to Amazon: |
| 46 | + |
| 47 | +```$ docker run example-lambda-image sh -c 'rm -rf dist* && lambda build 2&>1 >/dev/null && tar -c dist/*.zip' | tar -x -v |
| 48 | +dist/2017-08-31-212523-example-lambda.zip |
| 49 | +``` |
| 50 | + |
| 51 | + |
0 commit comments