diff --git a/LICENSE b/LICENSE index 6169ac0..447bd42 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Robert Peteuil +Copyright (c) 2020 Robert Peteuil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ac0899a..9acaa09 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ # Build AWS Lambda Layer zip file for Python Dependancies -Creates an AWS Lambda Layers **optimized** zip file using the [Lambda Layer directory structure](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path), ensures compiled libraries are compatible with Lambda environment, and optimized to reduce file size. +Creates an AWS Lambda Layers zip file that is **optimized** for: [Lambda Layer directory structure](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path), compiled library compatibility, and minimal file size. This function was created to address these issues: -- Many methods of creating Lambda zip files for Python functions don't work for Lambda Layers because Lambda Layers require specific library paths within the zip -- Some dependancies required compiled components, which requires that the zip is created in an environment that matches the Lambda runtime environment -- Minimize the zip size by removing unnecessary items +- Many methods of creating Lambda zip files for Python functions don't work for Lambda Layers + - This is due to the fact Lambda Layers require specific library paths within the zip, unlike regular Lambda zip files +- Compiled dependancies must be created in an environment that matches the Lambda runtime +- Reduce size of zip file by removing unnecessary libraries and files **Note: This script requires Docker and uses a container to mimic the Lambda environment.** @@ -15,7 +16,7 @@ This function was created to address these issues: - Builds zip file containing Python dependancies and places the libraries into the proper directory structure for lambda layers - Ensures compiled libraries are compatible with Lambda environment by using [docker container](https://hub.docker.com/r/lambci/lambda) that mimics the lambda runtime environment - Optimized the zip size by removing `.pyc` files and unnecessary libraries -- allows specifying lambda supported python versions: 2.7, 3.6 and 3.7 +- allows specifying lambda supported python versions: 2.7, 3.6, 3.7 and 3.8 - Automatically searches for requirements.txt file in several locations: - same directory as script - parent directory or script (useful when used as submodule) @@ -35,9 +36,7 @@ git clone --depth 1 https://github.com/robertpeteuil/build-lambda-layer-python _ Alternatively, add as a submodule: ``` bash -# PUBLIC USE HTTPS cd {repo root} -# eventual public repo will use http git submodule add https://github.com/robertpeteuil/build-lambda-layer-python _build_layer # Update submodule git submodule update --init --recursive --remote @@ -46,16 +45,17 @@ git submodule update --init --recursive --remote ## Use - Run the builder with the command `./build_layer.sh` -- Optionally specify Python Version - - `-p PYTHON_VER` - specifies the Python version: 2.7, 3.6, 3.7 (default 3.6) + - or `_build_layer/build_layer.sh` if installed in sub-dir - It uses the first requirements.txt file found in these locations (in order): - same directory as script - parent directory of script (useful when used as submodule) - function sub-directory of the parent directory (useful when used as submodule) +- Optionally specify Python Version + - `-p PYTHON_VER` - specifies the Python version: 2.7, 3.6, 3.7, 3.8 (default 3.7) ## Reference - remove submodule -If installed as submodule and want to remove +If installed as submodule and need to remove ``` bash # Remove the submodule entry from .git/config diff --git a/_make_zip.sh b/_make_zip.sh index aed6deb..8427ed1 100755 --- a/_make_zip.sh +++ b/_make_zip.sh @@ -8,8 +8,8 @@ set -e # /python/lib/pythonX.X/site-packages scriptname=$(basename "$0") -scriptbuildnum="1.0.0" -scriptbuilddate="2019-03-30" +scriptbuildnum="1.0.1" +scriptbuilddate="2020-05-08" ### VARS CURRENT_DIR=$(reldir=$(dirname -- "$0"; echo x); reldir=${reldir%?x}; cd -- "$reldir" && pwd && echo x); CURRENT_DIR=${CURRENT_DIR%?x} diff --git a/build_layer.sh b/build_layer.sh index 8e767fe..2e32d1c 100755 --- a/build_layer.sh +++ b/build_layer.sh @@ -11,8 +11,8 @@ set -e # Zip filename includes python version used in its creation scriptname=$(basename "$0") -scriptbuildnum="1.0.0" -scriptbuilddate="2019-03-30" +scriptbuildnum="1.0.1" +scriptbuilddate="2020-05-08" # used to set destination of zip SUBDIR_MODE="" @@ -24,7 +24,7 @@ displayVer() { usage() { [[ "$1" ]] && echo -e "AWS Lambda Layer Zip Builder for Python Libraries\n" echo -e "usage: ${scriptname} [-p PYTHON_VER] [-s] [-r REQUIREMENTS-DIR] [-h] [-v]" - echo -e " -p PYTHON_VER\t: Python version to use: 2.7, 3.6, 3.7 (default 3.6)" + echo -e " -p PYTHON_VER\t: Python version to use: 2.7, 3.6, 3.7, 3.8 (default 3.7)" echo -e " -h\t\t\t: help" echo -e " -v\t\t\t: display ${scriptname} version" } @@ -40,8 +40,8 @@ while getopts ":p:hv" arg; do done shift $((OPTIND-1)) -# default Python to 3.6 if not set by CLI params -PYTHON_VER="${PYTHON_VER:-3.6}" +# default Python to 3.7 if not set by CLI params +PYTHON_VER="${PYTHON_VER:-3.7}" CURRENT_DIR=$(reldir=$(dirname -- "$0"; echo x); reldir=${reldir%?x}; cd -- "$reldir" && pwd && echo x); CURRENT_DIR=${CURRENT_DIR%?x} BASE_DIR=$(basename $CURRENT_DIR)