#!/usr/bin/env bash set -xeo pipefail WORKDIR=$(dirname "$0") WORKDIR=$(readlink -f "${WORKDIR}") DIR_NAME=$(basename "$WORKDIR") cd "$WORKDIR" # Do not deploy the lambda to AWS DRY_RUN=${DRY_RUN:-} # Python runtime to install dependencies PY_VERSION=${PY_VERSION:-3.10} PY_EXEC="python${PY_VERSION}" # Image to build the lambda zip package DOCKER_IMAGE="public.ecr.aws/lambda/python:${PY_VERSION}" # Rename the_lambda_name directory to the-lambda-name lambda in AWS LAMBDA_NAME=${DIR_NAME//_/-} # The name of directory with lambda code PACKAGE=lambda-package # Do not rebuild and deploy the archive if it's newer than sources if [ -e "$PACKAGE.zip" ] && [ -z "$FORCE" ]; then REBUILD="" for src in app.py build_and_deploy_archive.sh requirements.txt lambda_shared/*; do if [ "$src" -nt "$PACKAGE.zip" ]; then REBUILD=1 fi done [ -n "$REBUILD" ] || exit 0 fi docker_cmd=( docker run -i --net=host --rm --user="${UID}" -e HOME=/tmp --entrypoint=/bin/bash --volume="${WORKDIR}/..:/ci" --workdir="/ci/${DIR_NAME}" "${DOCKER_IMAGE}" ) rm -rf "$PACKAGE" "$PACKAGE".zip mkdir "$PACKAGE" cp app.py "$PACKAGE" if [ -f requirements.txt ]; then VENV=lambda-venv rm -rf "$VENV" "${docker_cmd[@]}" -ex <