Skip to content

Commit 1da07d5

Browse files
committed
update Python GeoLambda readme
1 parent 9beebf0 commit 1da07d5

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

python/README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@ The Python GeoLambda image is meant to be used as a template for your own Python
66

77
These instructions show how to use the files in this directory to create your own Python based geospatial Lambda function and get it deployed.
88

9-
### Create docker image
9+
1. Update requirements
1010

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.
1212

13-
$ docker build . --build-arg VERSION=1.1.0 --build-arg PYVER=3.6.1 -t <myimage>:latest
13+
2. Create handler
1414

15-
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.
1616

17-
### Create handler
17+
3. Build image
1818

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).
2020

21-
### Create deployment package
21+
$ docker build . --build-arg VERSION=1.1.0 --build-arg PYVERSION=3.6.1 -t <myimage>:latest
2222

23-
All that's needed to create a deployment package is to install the Python packages into the lambda/ directory.
23+
If not provided, `VERSION` (the version of GeoLambda to use) will default to `latest` and `PYVERSION` (Python version) will default to `3.6.1`.
2424

25-
$ docker run -v ${PWD}:/home/geolambda -t <myimage>:latest pip install -r requirements -t lambda/
25+
4. Create deployment package
2626

27-
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).
2828

29-
$ cd lambda
30-
$ zip -ru ../lambda-deploy.zip ./
29+
$ docker run -v ${PWD}:/home/geolambda -t <myimage>:latest package-python.sh
3130

32-
### Testing deployment package
31+
This will also create a lambda-deployment.zip file in the current directory.
32+
33+
5. Testing deployment package
3334

3435
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.
3536

@@ -40,11 +41,19 @@ $ docker run --rm -v ${PWD}/lambda:/var/task -v ${PWD}/../lambda:/opt \
4041

4142
The last argument is a JSON string that will be passed as the event payload to the handler function.
4243

44+
6. Deploy
45+
46+
Deploy the Lambda function now by zipping up the lambda directory and using the AWS CLI.
47+
48+
```
49+
$ aws lambda update-function-code --function-name <mylambda> --zip-file fileb://lambda-deploy.zip
50+
```
51+
4352
### Pre-built images
4453

4554
Builds of this default Python image are also available on Docker Hub as tags in the `developmentseed/geolambda` repository.
4655

47-
$ docker pull developmentseed/geolambda:1.1.0-python36
56+
$ docker pull developmentseed/geolambda:${VERSION}-python36
4857

4958
To run the image interactively:
5059

@@ -64,7 +73,7 @@ $ VERSION=${cat ../VERSION}
6473
$ docker build . --build-arg VERSION=${VERSION} -t developmentseed/geolambda:${VERSION}-python36
6574
```
6675

67-
Provide `--build-arg PYVER=X.Y.Z` to build other Python versions and change the tag to be `${VERSION}-pythonX.Y`
76+
Provide `--build-arg PYVERSION=X.Y.Z` to build other Python versions and change the tag to be `${VERSION}-pythonX.Y`
6877

6978

7079

0 commit comments

Comments
 (0)