2
2
3
3
## Why?
4
4
5
- Some node modules require a build system because they contain c++ binding. Once deployed, the compiled module may not be
6
- complatible with the Amazon Lambda execution environment.
5
+ Some node and python modules require a build system because they contain c++ binding. Once deployed, the compiled
6
+ module may not be complatible with the Amazon Lambda execution environment.
7
7
8
8
A common solution to this problem is to install the package on an EC2 instance using an Amazon Linux AMI and then to
9
9
deploy it in Amazon Lambda. Building serverless applications, it is ironic to be obliged to use a server to deploy code.
10
10
11
11
This docker image is based on the [ Amazon Linux] ( https://hub.docker.com/_/amazonlinux/ ) image and contains ` gcc ` ,
12
- ` node 4.3.2 ` , ` node 6.10.2 ` and ` npm 4 ` to create packages for Amazon Lambda.
12
+ ` python 2.7 ` , ` python 3.6 ` , ` pip ` , ` node 4.3 ` , ` node 6.10 ` and ` npm 4 ` to create packages for Amazon Lambda.
13
13
14
14
Using the docker image ` myrmex/lambda-packager ` , avoid errors like these during execution in Amazon Lambda:
15
15
@@ -23,37 +23,56 @@ Module version mismatch. Expected 46, got 48.
23
23
24
24
## Usage
25
25
26
- You can use a docker volume to mount the code of the Lambda it in a container. The directory where ` npm install ` is
27
- executed inside the container is ` /data ` . By default, the installation will be performed for node 6.10.2.
26
+ You can use a docker volume to mount the code of the Lambda it in a container. The directory where ` npm install ` or
27
+ ` pip install ` is executed inside the container is ` /data ` . By default, the installation will be performed for node
28
+ 6.10.
28
29
29
30
``` bash
30
31
docker run ` pwd` :/data myrmex/lambda-packager
31
32
```
32
33
33
34
The image does not create the zip archive for your. It only install the dependencies in an environment compatible with
34
- Lambda. You will still have to zip the result and create / update the Lambda function in AWS .
35
+ Lambda. You will still have to zip the result and deploy it in Amazon Lambda.
35
36
36
- Take care that ` node_module ` does not already exist before running the command.
37
+ For a node package, take care that ` node_module ` does not already exist before running the command.
37
38
38
39
### Managing permissions
39
40
40
- The user that performs ` npm install ` inside the container may have a ` uid/gid ` that differs from the ` uid/gid ` of the
41
- host machine and npm may not be able to perform the installation. The image ` myrmex/lambda-packager ` accepts two
42
- environment variables that allows to modify the ` uid/gid ` of the container's user: ` HOST_UID ` and ` HOST_GID ` . If
43
- ` HOST_GID ` is omitted, its value will be set to the value of ` HOST_UID ` .
41
+ The user that performs ` npm install ` or ` pip install ` inside the container may have a ` uid/gid ` that differs from the
42
+ ` uid/gid ` of the host machine and will not be able to perform the installation. The image ` myrmex/lambda-packager `
43
+ accepts two environment variables that allows to modify the ` uid/gid ` of the container's user: ` HOST_UID ` and
44
+ ` HOST_GID ` . If ` HOST_GID ` is omitted, its value will be set to the value of ` HOST_UID ` .
44
45
45
46
``` bash
46
47
docker run -e HOST_UID=` id -u` -e HOST_GID=` id -g` -v ` pwd` :/data myrmex/lambda-packager
47
48
```
48
49
49
- ### Node 4
50
+ ### Selecting the runtime
50
51
51
- The ` RUNTIME ` environment variable allows to perform the installation for node 4.3.2
52
+ The ` RUNTIME ` environment variable allows to choose the runtime.
53
+
54
+ #### Node 6.10
55
+
56
+ Node 6.10 is the default runtime and does not require any special configuration.
57
+
58
+ #### Node 4.3
52
59
53
60
``` bash
54
61
docker run -e RUNTIME=node4 -v ` pwd` :/data myrmex/lambda-packager
55
- # or
56
- docker run -e RUNTIME=node4 -e HOST_UID=` id -u` -e HOST_GID=` id -g` -v ` pwd` :/data myrmex/lambda-packager
62
+ ```
63
+
64
+ #### Python 3.6
65
+
66
+ ``` bash
67
+ docker run -e RUNTIME=python3 -v ` pwd` :/data myrmex/lambda-packager
68
+ ```
69
+
70
+ #### Python 2.7
71
+
72
+ Accepts the values ` python ` or ` python2 ` .
73
+
74
+ ``` bash
75
+ docker run -e RUNTIME=python -v ` pwd` :/data myrmex/lambda-packager
57
76
```
58
77
59
78
### Default command
@@ -62,8 +81,6 @@ To be able to change the user `uid/gid`, the container is executed with the root
62
81
need to use a non root user because it is a good practice and it avoids some [ bad surprises with
63
82
` node-gyp ` ] ( https://github.com/nodejs/node-gyp/issues/454 ) .
64
83
65
- So the default command is ` su myrmex -c "npm install --production" ` , ` myrmex ` beeing the name of the non root user.
66
-
67
- ## What's next?
84
+ So, the default command is ` su myrmex -c "npm install --production" ` , ` myrmex ` beeing the name of the non root user.
68
85
69
- Support for python runtimes
86
+ For python, the command is ` su myrmex -c "pip install --requirement requirements.txt --upgrade --target ." `
0 commit comments