You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-3Lines changed: 37 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,15 @@ Lightweight docker image for running and packaging python-based AWS lambda code.
4
4
*[alpine-aws-python-lambda on docker hub](https://hub.docker.com/r/kilna/alpine-aws-python-lambda/)
5
5
*[alpine-aws-python-lambda on github](https://github.com/kilna/alpine-aws-python-lambda)
6
6
7
+
# Purpose
8
+
9
+
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 sytem, so it was the obvious choice.
10
+
11
+
In order to use this, you will have your project derive its own Dockerfile based on a base alpine-aws-python-lambda image corresponding to which version of Python you wish to run.
12
+
7
13
# Usage
8
14
9
-
An example of a usable project can be found in the [example/](./example/) directory. This lambda function takes a JSON input file like the provided [event.json](./example/event.json) and returns an ASCII-art version of the text described in it. The provided [Dockerfile](./example/Dockerfile) derives from this image and loads the current workspace into the image, then installs dependencies from the [requirements.txt](./example/requirements.txt) file.
15
+
An example of a usable project can be found in the [example/](./example/) directory. This lambda function takes a JSON input file like the provided [event.json](./example/event.json) and returns an ASCII-art version of the text described in it. The provided [Dockerfile](./example/Dockerfile) derives from this image and loads the current workspace into the image, then installs dependencies from the [requirements.txt](./example/requirements.txt) file.
10
16
11
17
To build a docker image called _example-lambda-image_ with the example lambda function in it, run:
12
18
@@ -33,11 +39,39 @@ If you would like to see if your lambda function builds properly, run:
33
39
$ docker run example-lambda-image lambda build
34
40
```
35
41
36
-
If you would like to get a ZIP file of the lambda function suitable for uploading to Amazon, and the build log in one command:
42
+
## Build and Test
43
+
44
+
If you would like to build and test the lambda function and gather up the results, you can run:
37
45
38
46
```
39
-
$ docker run example-lambda-image sh -c 'rm -rf build.log dist || true && lambda build &>build.log && tar -c build.log dist' | tar -x -v
47
+
$ docker run example-lambda-image lambda_build_tar | tar -x -v
40
48
build.log
49
+
test.log
41
50
dist/
42
51
dist/2017-09-01-003647-example-lambda.zip
43
52
```
53
+
54
+
Behind the scenes, what this script does is:
55
+
56
+
* Removes any log and dist files from prior runs
57
+
* Runs 'lambda build' and store the log in _/lambda/build.log_ in the container
58
+
* If present and executable, run _/lambda/run_tests_ and store the log in /lambda/test.log in the container
59
+
* Tars the log files, and the contents of the dist directory in /lambda on the container and pipes it to standard output
60
+
* Untars the contents bundled up within the container, and extracts them into your current directory
61
+
62
+
## Python Version
63
+
64
+
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.
65
+
66
+
For instance, if you want to use Python version 2.7 change the first line of your Dockerfile from:
0 commit comments