Content-Length: 295641 | pFad | http://github.com/kilna/python-lambda-docker/tree/bdc8a73c18b6ce5bbf2ac4e4fe20ce10ca7f421a

0B GitHub - kilna/python-lambda-docker at bdc8a73c18b6ce5bbf2ac4e4fe20ce10ca7f421a
Skip to content

Lightweight docker image for running, testing, packaging and deploying python-based AWS lambda functions

License

Notifications You must be signed in to change notification settings

kilna/python-lambda-docker

Repository files navigation

python-lambda-docker

Lightweight docker image for running and packaging python-based AWS lambda code

Links

Purpose

I needed a Docker-based environment in which to host AWS python lambda functions for the purpose of testing and building them... python-lambda works well under virtualenv for development, but build and deployment automation require a clean and reproducible environment to operate in. Our CI system already supported Docker as a containerization system, so it was the obvious choice.

In order to use this, you will have your project derive its own Dockerfile based on a base python-lambda image corresponding to which version of Python you wish to run.

Usage

An example of a usable project can be found in the example/ directory. This lambda function in service.py takes a JSON input file like the one provided in event.json and returns an ASCII-art version of the text described in it. The provided Dockerfile derives from this image and loads the current workspace into the image at the path /lambda, then installs dependencies from the requirements.txt file.

To build a docker image called example-lambda-image with the example lambda function in it, run:

$ cd example/
$ docker build --tag example-lambda-image .

If you want to execute the lambda function against the event.json input file:

$ docker run example-lambda-image lambda invoke
 _  _     _ _                        _    _ _
| || |___| | |___    __ __ _____ _ _| |__| | |
| __ / -_) | / _ \_  \ V  V / _ \ '_| / _` |_|
|_||_\___|_|_\___( )  \_/\_/\___/_| |_\__,_(_)
                 |/

If you would like to see if your lambda function build (which will package the lambda and all dependencies within the container into a zip file), run:

$ docker run example-lambda-image lambda build

Build and Test

If you would like to build and test the lambda function and gather up the results, you can run:

$ docker run example-lambda-image lambda_build_tar | tar -x -v
build.log
test.log
dist/
dist/2017-09-01-003647-example-lambda.zip

Behind the scenes, what this script does is:

  • Removes any log and dist files from prior runs
  • Runs 'lambda build' and stores the log in /lambda/build.log in the container
  • If present and executable, run /lambda/run_tests and stores the log in /lambda/test.log in the container
  • Tars the log files, and the contents of the dist directory in /lambda on the container and pipes it to standard output
  • Untars the contents bundled up within the container, and extracts them into your current directory

Python Version

The example Dockerfile uses :latest in the FROM line, which is currently the same as :python-3.6, but if you wish to use different python versions you can change this.

For instance, if you want to use Python version 2.7 change the first line of your Dockerfile from:

FROM kilna/python-lambda:latest

To:

FROM kilna/python-lambda:2.7

About

Lightweight docker image for running, testing, packaging and deploying python-based AWS lambda functions

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/kilna/python-lambda-docker/tree/bdc8a73c18b6ce5bbf2ac4e4fe20ce10ca7f421a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy