Search code examples
aws-lambdagdal

Calling gdal2tiles.py in AWS LAMBDA function


I'm trying to call gdal2tiles.py in AWS Lambda function using GeoLambda layer. I can't figure out how to call this script form the lambda function.

My lambda function looks like this so far:

    import json
    import os
    from osgeo import gdal
    def lambda_handler(event, context):
       
         os.system("gdal2tiles.py -p -z [0-6] test.jpg")

In the log I have this error: sh: gdal2tiles.py: command not found

Any idea how to solve this? Thank you.


Solution

  • one way to do it is to import gdal2tiles utilities from the GeoLambda layer that you added to your lambda function.

    For example:

    gdal2tiles.generate_tiles('/path/to/input_file', '/path/to/output_dir/'), nb_processes=2, zoom='0-6')
    

    Read more about in gdal2tiles

    Edit: Ok i made it to work with these set of layer attached to the lambda. The first 2 layers were straight from the Github

    • arn:aws:lambda:us-east-1:552188055668:layer:geolambda-python:3
    • arn:aws:lambda:us-east-1:552188055668:layer:geolambda:4

    The 3rd layer is our gdal2tiles which is created locally and attached to lambda fucntion

    • arn:aws:lambda:us-east-1:246990787935:layer:gdaltiles:1

    you can download the zip from here

    enter image description here

    And i hope you added the below Environment vairable to your lambda function configuration

    • GDAL_DATA=/opt/share/gdal
    • PROJ_LIB=/opt/share/proj (only needed for GeoLambda 2.0.0+)