Query COGs with Lambda
TL;DR
Use Lambda with rasterio (and/or rio-tiler) to read Cloud Optimized GeoTIFFs (COGs) in S3 via HTTP range requests and return clipped/warped subsets or tiles on demand.
Flow: Client → API Gateway → Lambda → S3 (COG) → Lambda returns PNG/WEBP/JSON.
Cache headers (or API Gateway/Lambda@Edge/CloudFront in front) can reduce repeated reads.
Overview
This pattern serves on-demand reads from large rasters stored as COGs in S3. A client requests a window/tile/stat; API Gateway invokes Lambda, which uses rasterio (or rio-tiler) to read only the needed byte ranges from the COG and returns the result (PNG/WEBP/COG tile, or JSON stats).
When to Use
- You need dynamic subsets (windows, tiles, reprojected extracts) without pre-generating tiles.
- You want to access pixel data, without tiling for visualisation
- Pay-per-use access to large rasters; low/irregular traffic.
- You want to keep data in S3 and avoid maintaining tile servers.
Trade-offs
- Cold starts and Lambda timeout/memory limits for heavy reads.
- Throughput/concurrency can be constrained for very hot workloads.
- Per-request CPU is limited; heavy reprojection/warps can be slow.
- Requires creation of a Docker image Lambda for rasterio and GDAL support.
References
- Blog post: https://www.addresscloud.com/blog/serverless-flood
- Example code (archived): https://github.com/addresscloud/aws-lambda-docker-rasterio
For Tiling from COGs check out TiTiler (note: this should probably be it's own pattern).