A Python Lambda that reliably downloads Internet Archive images using the official internetarchive library, then performs the same resize/upload/callback behavior as BiospexImageFetcher.
- Triggered by SQS with the same message schema as
BiospexImageFetcher. - Parses
accessURIinto Internet Archiveidentifier+ IA file path. - Downloads the source image using
internetarchive.download(...)to/tmp. - Validates format (
JPEGorPNG), resizes with Pillow using "inside + no enlargement" behavior, outputs JPEG. - Uploads to S3 with matching metadata keys.
- Sends status updates to
updatesQueueUrl:export: sends success and failure.ocr: sends failure only (silent on success).
{
"taskType": "export",
"accessURI": "https://ia801809.us.archive.org/4/items/.../image.jpg",
"subjectId": "12345",
"s3Bucket": "biospex-images",
"s3Path": "incoming/12345.jpg",
"updatesQueueUrl": "https://sqs.us-east-2.amazonaws.com/.../queue",
"queueId": "12",
"fileId": 34,
"maxWidth": 1500,
"maxHeight": 1500
}JPEG_QUALITY(default80)DEFAULT_MAX_WIDTH(default1500)DEFAULT_MAX_HEIGHT(default1500)IA_RETRIES(default5)AWS_REGION(defaultus-east-2)
- Runtime: Python 3.12
- Handler:
lambda_function.lambda_handler
internetarchivePillowboto3
Use deploy.sh from this folder.
This Lambda includes Pillow, so dependencies should be built in a Lambda-compatible Python 3.12 environment. deploy.sh now uses the AWS Lambda base image public.ecr.aws/lambda/python:3.12 to build the zip.
Start Docker only when you need a build:
sudo service docker start
cd /data/web/InternetArchiveImageFetcher
./deploy.sh
sudo service docker stopThe build output is written locally to function.zip. Docker is only used as a temporary build environment.
sudo service docker start
cd /data/web/InternetArchiveImageFetcher
rm -rf build function.zip
docker run --rm \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-e PIP_NO_CACHE_DIR=1 \
--entrypoint /bin/sh \
-v "$PWD":/var/task \
-w /var/task \
public.ecr.aws/lambda/python:3.12 \
-c "python -m pip install --upgrade pip && pip install -r requirements.txt -t build"
cp lambda_function.py build/
(cd build && zip -qr ../function.zip .)
sudo service docker stopIf you prefer a layer for faster code-only deploys:
mkdir -p layer/python
pip install -r requirements.txt -t layer/python
cd layer && zip -r internetarchive-layer.zip pythonThen attach the layer to InternetArchiveImageFetcher and package only lambda_function.py in the function zip.
- Trigger source: SQS queue used for IA-download jobs.
- Batch size: start with
1-5to limit bursts to archive.org and reduce retries. - Enable partial batch response only if you later add per-record batch item failure reporting.
- Set Lambda timeout to at least
60-120s(IA requests can be slower than direct CDN URLs). - Keep memory at
1024 MBor higher for faster Pillow image decode/encode. - Use reserved concurrency to protect archive.org and your downstream SQS/S3 pipeline.
- Always clean
/tmpafter each record; this handler already removes temp folders. - Monitor throttling/retry patterns in CloudWatch and tune
IA_RETRIESaccordingly.