Skip to content

Instantly share code, notes, and snippets.

@akmalharith
Last active February 24, 2023 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akmalharith/61d7c9d99b9bdeeb7c59353f4e2dc2a5 to your computer and use it in GitHub Desktop.
Save akmalharith/61d7c9d99b9bdeeb7c59353f4e2dc2a5 to your computer and use it in GitHub Desktop.
Install requirements and build a Lambda layer compatible zip
#!/bin/sh
if [[ ! -f package.json ]] ; then
echo "File package.json doesn't exist. Run npm init and npm install first."
exit
fi
npm ci
mkdir -p dist/lambda_layer/nodejs/node_modules
cp -r node_modules dist/lambda_layer/nodejs/
cd dist/lambda_layer && zip -r lambda_layer.zip nodejs
mv lambda_layer.zip ../.
cd .. && rm -fr lambda_layer
#!/bin/sh
mkdir -p build/lambda_layer/python
pip install -r requirements.txt -t build/lambda_layer/python
cd build/lambda_layer && zip -r lambda_layer.zip python
mv lambda_layer.zip ../.

Generate Lambda layer script

The script will generate a Zipped Lambda layer in the support strucutre, and it can be safely uploaded and used as part of your Lambda function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment