Last active
June 10, 2025 22:48
-
-
Save recalde/5f3dab915014823d3e6e15b5e20a1744 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
LAYER_NAME="pyarrow-layer" | |
PYTHON_VERSION="3.11" | |
TARGET_DIR="$(pwd)/layer_build" | |
OUTPUT_ZIP="pyarrow-layer.zip" | |
IMAGE_TAG="${LAYER_NAME}-builder" | |
echo "π§Ή Cleaning previous build artifacts..." | |
rm -rf "$TARGET_DIR" "$OUTPUT_ZIP" Dockerfile | |
mkdir -p "$TARGET_DIR" | |
# Safety: Remove any cached ECR image reference | |
echo "π§Ό Removing any broken ECR-based images..." | |
podman image rm public.ecr.aws/lambda/python:3.11 2>/dev/null || true | |
# Warn about Podman DNS issues | |
if [[ "$(uname)" == "Darwin" ]] && command -v podman &>/dev/null; then | |
echo "β οΈ macOS + Podman detected β if you hit DNS issues, run:" | |
echo " podman machine stop && podman machine start" | |
echo " and ensure /etc/resolv.conf in the Podman VM has nameserver 8.8.8.8" | |
fi | |
echo "π Writing Dockerfile..." | |
cat > Dockerfile <<EOF | |
FROM amazonlinux:2023 | |
RUN dnf install -y gcc-c++ cmake make python3-devel python3-pip unzip zip ca-certificates && \ | |
update-ca-trust && \ | |
python3 -m pip install --upgrade pip setuptools wheel | |
ENV PYTHON_VERSION=${PYTHON_VERSION} | |
WORKDIR /opt | |
# Install pyarrow into Lambda layer structure | |
RUN python3 -m pip install pyarrow -t python/lib/python\${PYTHON_VERSION}/site-packages | |
# Strip shared libs | |
RUN find python/lib/python\${PYTHON_VERSION}/site-packages/pyarrow -name "*.so" -exec strip --strip-unneeded {} \; || true | |
# Cleanup | |
RUN rm -rf python/lib/python\${PYTHON_VERSION}/site-packages/pyarrow/tests \\ | |
python/lib/python\${PYTHON_VERSION}/site-packages/pyarrow/include \\ | |
python/lib/python\${PYTHON_VERSION}/site-packages/pyarrow/*.pyd \\ | |
python/lib/python\${PYTHON_VERSION}/site-packages/pyarrow/*.cmake \\ | |
python/lib/python\${PYTHON_VERSION}/site-packages/pyarrow/__pycache__ | |
# Create layer ZIP | |
RUN cd python && zip -r9 /${OUTPUT_ZIP} . | |
EOF | |
echo "π³ Building image..." | |
podman build -t "$IMAGE_TAG" . | |
echo "π¦ Extracting layer ZIP from image..." | |
podman run --rm -v "$TARGET_DIR":/out:z "$IMAGE_TAG" cp "/${OUTPUT_ZIP}" /out/ | |
echo "π Moving output..." | |
mv "$TARGET_DIR/${OUTPUT_ZIP}" . | |
echo "β Done! Lambda layer created: ${OUTPUT_ZIP}" | |
echo "" | |
echo "π To publish the layer, run:" | |
echo "aws lambda publish-layer-version --layer-name pyarrow --zip-file fileb://${OUTPUT_ZIP} --compatible-runtimes python3.11" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment