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: python/README.md
+24-15Lines changed: 24 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -6,30 +6,31 @@ The Python GeoLambda image is meant to be used as a template for your own Python
6
6
7
7
These instructions show how to use the files in this directory to create your own Python based geospatial Lambda function and get it deployed.
8
8
9
-
### Create docker image
9
+
1. Update requirements
10
10
11
-
First a Docker image will need to be created based on GeoLambda that includes the dependencies needed. Use the [Dockerfile](Dockerfile) can be used to create a new Docker image based on any version of GeoLambda with any version of Python by providing the versions as build arguments to `docker run`. This will install the specified version of Python along with any Python packages provided in [requirements.txt](requirements.txt).
11
+
First a Docker image will need to be created based on GeoLambda that includes the dependencies needed. The first thing is to is update the `requirements-pre.txt` and `requirement.txt` files with the dependencies needed. The `requirements-pre.txt` is a way to specify build dependencies to packages in `requirements.txt`. For instance, rasterio requires numpy is installed before rasterio. This is a well known pip problem that is fixed in [PEP 518](https://www.python.org/dev/peps/pep-0518/) but is not used by all packages so this work-around is needed.
If not provided, `VERSION` (the version of GeoLambda to use) will default to `latest`and `PYVER` (Python version) will default to `3.6.1`.
15
+
An example Lambda handler is located at [lambda/lambda_function.py](lambda/lambda_function.py). Ideally most of the logic in your Lambda should be in packages and the handler should only be responsible for taking in an event, calling relevant functions, and returning some output. Keep the handler code as small as possible. Move more complex code into packages or make them other functions in the [lambda/lambda_function.py](lambda/lambda_function.py) file.
16
16
17
-
### Create handler
17
+
3. Build image
18
18
19
-
An example Lambda handler is located at [lambda/lambda_function.py](lambda/lambda_function.py). Ideally most of the logic in your Lambda should be in packages and the handler should only be responsible for taking in an event, calling relevant functions, and returning some output. Keep the handler code as small as possible. Move more complex code into packages or make them other functions in the [lambda/lambda_function.py](lambda/lambda_function.py) file.
19
+
Now, use the [Dockerfile](Dockerfile) can be used to create a new Docker image based on any version of GeoLambda with any version of Python by providing the versions as build arguments to `docker run`. This will install the specified version of Python along with any Python packages provided in [requirements.txt](requirements.txt).
The lambda/ directory can now be zipped up and deployed as a Lambda function:
27
+
All that's needed to create a deployment package is to install the Python packages into the lambda/ directory using the package-python.sh script. This copies the installed site-packages over the lambda directory, but excluding some libraries since they won't be needed on Lambda. This includes packages that are already pre-installed in Lambda like boto3, as well as files and libraries that wouldn't be used operationally (e.g., testing files).
28
28
29
-
$ cd lambda
30
-
$ zip -ru ../lambda-deploy.zip ./
29
+
$ docker run -v ${PWD}:/home/geolambda -t <myimage>:latest package-python.sh
31
30
32
-
### Testing deployment package
31
+
This will also create a lambda-deployment.zip file in the current directory.
32
+
33
+
5. Testing deployment package
33
34
34
35
You can use the [LambCI Docker images](https://github.com/lambci/docker-lambda) to test out your handler in the Lambda environment by mounting the base GeoLambda Lambda layer (see the [GeoLambda README](../README.md)) and the lambda directory created above.
0 commit comments