Skip to content

fix(raster): strip shared libraries from the bundle - #705

Open
chuckwondo wants to merge 1 commit into
developfrom
fix/strip-raster-libraries
Open

chuckwondo wants to merge 1 commit into
developfrom
fix/strip-raster-libraries

Conversation

@chuckwondo

Copy link
Copy Markdown
Contributor

Closes #703

This PR strips every shared library in the raster bundle of symbols it does not need at run time, which shrinks the bundle from 245,733,512 bytes to 187,139,237. It also adds a last build step that fails when the bundle exceeds Lambda's 262,144,000-byte limit. The predeploy job builds this image, so a dependency bump that pushes the bundle over the limit will fail its PR rather than the deploy.

Unlike titiler's strip step, which #703 proposed copying, this one also strips numpy's OpenBLAS (numpy.libs), which brings the bundle 0.9MB below #703's figure of 188,041,799 bytes. Titiler added that exclusion without giving a reason, and numpy's linear algebra still works with the library stripped.

Testing

Build the image, then measure the bundle with the command from #703:

docker build --platform linux/amd64 -f raster_api/runtime/Dockerfile -t veda-raster .
docker run --rm --platform linux/amd64 --entrypoint sh veda-raster -c \
  'find /asset -type f -printf "%s\n" | awk "{s += \$1} END {print s}"'

On 2026-11-26:

187139237

Then check that the stripped libraries still work: GDAL writes, reads, and reprojects a GeoTIFF, numpy inverts a matrix, and shapely buffers a point.

docker run -i --rm --platform linux/amd64 --entrypoint python veda-raster - <<'EOF'
from handler import handler
import numpy as np, rasterio, shapely
from rasterio.io import MemoryFile
from rasterio.transform import from_origin
from rasterio.warp import reproject
a = np.random.default_rng(0).random((300, 300))
out = np.zeros((300, 300))
with MemoryFile() as mem:
    with mem.open(driver="GTiff", width=300, height=300, count=1, dtype="float64",
                  crs="EPSG:4326", transform=from_origin(-100, 40, 0.01, 0.01)) as ds:
        ds.write(a @ a.T, 1)
    with mem.open() as ds:
        reproject(rasterio.band(ds, 1), out, dst_crs="EPSG:3857",
                  dst_transform=from_origin(-11131949, 4865942, 1113, 1113))
print("inverse:", np.allclose(a @ np.linalg.inv(a), np.eye(300)))
print("reprojected:", out.max() > 0)
print("buffer area:", round(shapely.Point(0, 0).buffer(1).area, 2))
EOF
inverse: True
reprojected: True
buffer area: 3.14

Fail the build when the bundle exceeds Lambda's unzipped size limit.

Closes #703

This branch was successfully deployed

1 active deployment
dev — a52f1139 Deployed Nov 26, 2026 by chuckwondo via predeploy #1386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raster API's Lambda bundle is close to the 250MiB limit that fails deploys

1 participant