Skip to content

Instantly share code, notes, and snippets.

@leetrout
Created October 7, 2025 03:14
Show Gist options
  • Select an option

  • Save leetrout/0cc60f74a6df81b1e5c1b452533f4005 to your computer and use it in GitHub Desktop.

Select an option

Save leetrout/0cc60f74a6df81b1e5c1b452533f4005 to your computer and use it in GitHub Desktop.
Building a lambda with uv
#!/usr/bin/env bash
# Build a .zip compatible with AWS Lambda
set -euo pipefail
# operate from the same directory as this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# By default create lambda.zip for Python 3.13 on amd64
OUTPUT_ZIP="${OUTPUT_ZIP:-lambda.zip}"
PYTHON_VERSION="${PYTHON_VERSION:-3.13}"
PLATFORM_TAG="${PLATFORM_TAG:-x86_64-manylinux2014}"
if ! command -v uv >/dev/null 2>&1; then
echo "uv is required but not found. Install from https://docs.astral.sh/uv/." >&2
exit 1
fi
# By default build in ./build
BUILD_DIR="build"
PIP_DIR="${BUILD_DIR}/packages"
REQ_FILE="${BUILD_DIR}/requirements.txt"
uv export --frozen --no-dev --no-editable -o "${REQ_FILE}"
uv pip install \
--no-installer-metadata \
--no-compile-bytecode \
--python-platform "${PLATFORM_TAG}" \
--python "${PYTHON_VERSION}" \
--target "${PIP_DIR}" \
-r "${REQ_FILE}"
# Zip it all up
pushd "${PIP_DIR}"
zip -r ../"${OUTPUT_ZIP}" .
popd
# Add your python files here
zip -r "${BUILD_DIR}/${OUTPUT_ZIP}" main.py
# Add your additional packages
zip -r "${BUILD_DIR}/${OUTPUT_ZIP}" lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment