2022-06-27 12:00:32 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -xeo pipefail
|
|
|
|
|
2022-07-28 12:23:59 +00:00
|
|
|
WORKDIR=$(dirname "$0")
|
2022-11-23 14:00:15 +00:00
|
|
|
WORKDIR=$(readlink -f "${WORKDIR}")
|
2022-07-28 12:23:59 +00:00
|
|
|
cd "$WORKDIR"
|
|
|
|
|
2022-11-23 14:00:15 +00:00
|
|
|
PY_VERSION=3.9
|
|
|
|
PY_EXEC="python${PY_VERSION}"
|
|
|
|
DOCKER_IMAGE="python:${PY_VERSION}-slim"
|
|
|
|
LAMBDA_NAME=$(basename "$WORKDIR")
|
2022-07-28 12:23:59 +00:00
|
|
|
LAMBDA_NAME=${LAMBDA_NAME//_/-}
|
|
|
|
PACKAGE=lambda-package
|
|
|
|
rm -rf "$PACKAGE" "$PACKAGE".zip
|
2022-08-10 12:37:06 +00:00
|
|
|
mkdir "$PACKAGE"
|
2022-07-28 12:23:59 +00:00
|
|
|
cp app.py "$PACKAGE"
|
2022-08-10 12:37:06 +00:00
|
|
|
if [ -f requirements.txt ]; then
|
|
|
|
VENV=lambda-venv
|
|
|
|
rm -rf "$VENV" lambda-package.zip
|
2022-11-23 14:00:15 +00:00
|
|
|
docker run --rm --user="${UID}" --volume="${WORKDIR}:/lambda" --workdir="/lambda" "${DOCKER_IMAGE}" \
|
|
|
|
/bin/bash -c "
|
|
|
|
'$PY_EXEC' -m venv '$VENV' &&
|
|
|
|
source '$VENV/bin/activate' &&
|
|
|
|
pip install -r requirements.txt
|
|
|
|
"
|
2022-08-10 12:37:06 +00:00
|
|
|
cp -rT "$VENV/lib/$PY_EXEC/site-packages/" "$PACKAGE"
|
|
|
|
rm -r "$PACKAGE"/{pip,pip-*,setuptools,setuptools-*}
|
|
|
|
fi
|
|
|
|
( cd "$PACKAGE" && zip -9 -r ../"$PACKAGE".zip . )
|
2022-06-27 12:00:32 +00:00
|
|
|
|
2022-07-28 12:23:59 +00:00
|
|
|
aws lambda update-function-code --function-name "$LAMBDA_NAME" --zip-file fileb://"$PACKAGE".zip
|