Overview

I created a Docker image that uses AWS Lambda and pyvips to generate Pyramid Tiled TIFF files from images stored in S3.

The Amazon ECR Public Gallery is available here:

https://gallery.ecr.aws/nakamura196/lambda-docker-vips-python

The source code is available here:

https://github.com/ldasjp8/lambda-docker-vips-python

Below, I will explain how to use it.

Creating an Amazon ECR Repository

First, create an ECR repository.

Next, check the commands from “View push commands” and push the image.

Here is an example of the commands.

gcadddidwoootsccclkkkcaeeeelmcrrrobrndbtpeaguau-eigshdtlhto-dltclaXpko-mXsegtbX:ridX/-nla./v-a-dgipmdkipabortssdc.h-sakeupw-ecbyodrr.tro-.chdcvuookismnep-/-rselr--adevpsagiytsipt-josh1pn-o.8pna/uy:mlstlaa-hazmeotobanendssaat.tw--sd1X.oXcc|XokXmed./rodl-ckavkrmie.bpredsca-lr-po.dyguotischn-koeenar.-s-gutvis-ite1pr.sna-ampmayeztohAnoWanSw:sl.a-ctpoeamss/tslwaomrbdd-as-tddoicnkeXrX-XvXi.pdsk-rp.yetchro.nu:sl-aetaesstt-1.amazonaws.com

As a result, the image will appear in the ECR repository as shown below.

Then, copy the “Image URI” shown below.

Creating the Lambda Function

Next, create a Lambda function. In this case, I named the function my-lambda-docker-vips-python. Enter the URI you copied earlier in the “Container image URI” field.

Then, press the “Create function” button to create the function.

S3

Creating Buckets

For this setup, we need two buckets: one for uploading images and another for storing the converted images. I created two buckets named my-lambda-docker-vips-python-input and my-lambda-docker-vips-python-output.

Event Notification Configuration

From the my-lambda-docker-vips-python-input bucket’s “Properties” > “Event notifications”, create an event notification. This ensures that the function is triggered when an image is uploaded to S3.

I set the “Event name” to my-lambda-docker-vips-python-input-event, the “Event type” to All object create events, and the “Destination” “Lambda function” to my-lambda-docker-vips-python.

Lambda Function Configuration

Setting Environment Variables

Return to the Lambda function and set the environment variables as shown below.

Specifically, set the key name to iiif_bucket_name and the value to the S3 bucket name created earlier: my-lambda-docker-vips-python-output.

Access Permissions

Next, grant access permissions. Navigate to IAM from the link below and add permissions.

Since this is a test, I granted AmazonS3FullAccess.

Basic Settings

Finally, edit the “Basic settings”. As an example, I set the memory to 1024 MB and the timeout to 1 minute 0 seconds.

Testing

The setup is now complete.

As shown in the video below, try uploading an image to the my-lambda-docker-vips-python-input bucket. You can confirm that a TIF file is created in my-lambda-docker-vips-python-output.

https://youtu.be/qVM0yjX2BnY

Summary

I was able to create Pyramid Tiled TIFF files using a Lambda function.

As an extension, by combining this with the article “Building an IIIF Image Server with AWS Serverless Applications” below, you can automatically deliver images via the IIIF Image API simply by uploading images to S3.

Specifically, this can be achieved by specifying the output bucket my-lambda-docker-vips-python-output created in this article as the SourceBucket described in the article above.

This article serves as a personal reference, but I hope it is helpful to others as well.