Joon
Joon

Reputation: 150

How to use gdal(geodjango) in aws lambda?

No matter how hard I looked, I couldn't find a good way.
How to install gdal in aws lambda?
If my question is not enough, please correct me. sorry for my english.

Upvotes: 2

Views: 3162

Answers (1)

Val
Val

Reputation: 7033

A good option IMO is to use a lambda layer. You can either create one yourself or use one which has been compiled and made available publicly (availability depends on your region).

Here are two options:

https://github.com/lambgeo/docker-lambda
https://github.com/developmentseed/geolambda

For instance, if you want to use the layer from lambgeo in us-east-1, you can just add one of these arns to your function:

"layers": [
            {
                "name": "gdal24",
                "arn": "arn:aws:lambda:us-east-1:524387336408:layer:gdal24:1",
                "version": 1
            },
            {
                "name": "gdal30",
                "arn": "arn:aws:lambda:us-east-1:524387336408:layer:gdal30:1",
                "version": 1
            },
            {
                "name": "gdal31",
                "arn": "arn:aws:lambda:us-east-1:524387336408:layer:gdal31:1",
                "version": 1
            }

For a full list of regions and arns, see this link.


Additional information

After add layer, should add environment variables to lambda below informations
Here is an example using docker-lambda.

"GDAL_DATA": "/opt/share/gdal",
"PROJ_LIB": "/opt/share/proj",
"GDAL_LIBRARY_PATH": "/opt/lib/libgdal.so.2.x.x",    // Enter correct version
"GEOS_LIBRARY_PATH": "/opt/lib/libgeos_c.so.1.xx.x"  // Enter correct version

For django, edit your django settings.py

GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH')
GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')

Upvotes: 2

Related Questions