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
+33-21Lines changed: 33 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,15 +22,35 @@ In order to use this, you will have your project derive its own Dockerfile based
22
22
23
23
## Usage
24
24
25
-
An example of a usable project can be found in the [example/](./example/) directory. This lambda function in [service.py](./example/service.py) takes a JSON input file like the one provided in [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 at the path _/lambda_, then installs dependencies from the [requirements.txt](./example/requirements.txt) file.
25
+
An example of a usable project can be found in the [example/](./example/) directory. The lambda function in [service.py](./example/service.py) takes a JSON input file like the one provided in [event.json](./example/event.json) and returns an ASCII-art version of the text described in it. The [Dockerfile](./example/Dockerfile) derives from python-lambda as a base image, and loading the example directory contents into the image at the path _/lambda_, then installs dependencies from the [requirements.txt](./example/requirements.txt) file.
26
26
27
-
To build a docker image called _example-lambda-image_ with the example lambda function in it, run:
27
+
### Building a Derived Docker Image
28
+
29
+
To build a docker image from the provided [exmaple/](./exmaple) called _example-lambda-image_ with the ASCII-art lambda function in it, run:
28
30
29
31
```
30
32
$ cd example/
31
33
$ docker build --tag example-lambda-image .
32
34
```
33
35
36
+
Any time you make changes to the example project, you'll need to re-run the `docker build` command above, or you can investigate using docker volumes to sync local filesystem changes into the container.
37
+
38
+
#### Switching Python Versions
39
+
40
+
The example [Dockerfile](./example/Dockerfile) uses a _:latest_ docker tag in the FROM line, which is currently the same as _:3.6_, but if you wish to use a different Python version you can change this. Supported Python versions are 2.7, 3.3, 3.4, 3.5, 3.6. To use Python version 2.7 change the first line of the example [Dockerfile](./example/Dockerfile) to:
41
+
42
+
```
43
+
FROM kilna/python-lambda:2.7
44
+
```
45
+
46
+
You will also need to change the following line in [config.yaml](./example/config.yaml)
47
+
48
+
```
49
+
runtime: python2.7
50
+
```
51
+
52
+
### Executing the Lambda Function
53
+
34
54
If you want to execute the lambda function against the [event.json](./example/event.json) input file:
35
55
36
56
```
@@ -42,15 +62,17 @@ $ docker run example-lambda-image lambda invoke
42
62
|/
43
63
```
44
64
45
-
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:
65
+
### Building and Testing the Lambda Function
66
+
67
+
If you would like to builf the lambda function (which will package the function and all its dependencies), run:
46
68
47
69
```
48
70
$ docker run example-lambda-image lambda build
49
71
```
50
72
51
-
### Build and Test
73
+
The result will be a zip file created in the /lambda/dist directory inside the container.
52
74
53
-
If you would like to build and test the lambda function and gather up the results, you can run:
75
+
If you would like to build and _test_ the lambda function and gather up the results, you can run:
54
76
55
77
```
56
78
$ docker run example-lambda-image lambda_build_tar | tar -x -v
@@ -60,26 +82,16 @@ dist/
60
82
dist/2017-09-01-003647-example-lambda.zip
61
83
```
62
84
63
-
Behind the scenes, what this script does is:
85
+
Behind the scenes, what this does is:
64
86
65
87
* Removes any log and dist files from prior runs
66
-
*Runs 'lambda build' and stores the log in _/lambda/build.log_ in the container
67
-
* If present and executable, run_/lambda/run_tests_ and stores the log in /lambda/test.log in the container
88
+
*Executes 'lambda build' and stores the log in _/lambda/build.log_ in the container
89
+
* If present and executable, runs_/lambda/run_tests_ and stores the log in /lambda/test.log in the container
68
90
* Tars the log files, and the contents of the dist directory in /lambda on the container and pipes it to standard output
69
-
* Untars the contents bundled up within the container, and extracts them into your current directory
70
-
71
-
### Python Version
72
-
73
-
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.
91
+
* Untars the contents bundled up within the container, and extracts them into your current directory
74
92
75
-
For instance, if you want to use Python version 2.7 change the first line of your Dockerfile from:
93
+
### Deploying the Lambda Function
76
94
77
-
```
78
-
FROM kilna/python-lambda:latest
79
-
```
95
+
You can deploy your lambda function to Amazon's infrastructure... firstly you'll want to add values to the
0 commit comments