HsnVahedi
HsnVahedi

Reputation: 1366

Is it possible to use lambda layers with zappa?

I want to deploy my wagtail (which is a CMS based on django) project onto an AWS lambda function. The best option seems to be using zappa.

Wagtail needs opencv installed to support all the features.

As you might know, just running pip install opencv-python is not enough because opencv needs some os level packages to be installed. So before running pip install opencv-python one has to install some packages on the Amazon Linux in which the lambda environment is running. (yum install ...)

The only solution that came to my mind is using lambda layers to properly install opencv.

But I'm not sure whether it's possible to use lambda layers with projects deployed by zappa.

Any kind of help and sharing experiences would be really appreciated!

Upvotes: 1

Views: 1422

Answers (2)

kunal Roy
kunal Roy

Reputation: 1

Create layer.sh file and copy paste following content run this file as sh layer.sh,

  1. This cmd will create layer
  2. Deploy layer to lambda function
  3. Mapp Layer ARN to lambda function
  4. It will also add Layer ARN to your zappa_setting.json file

-----------------------------Shell Script-------------------------------------

mkdir layer
apt install jq
pip install -r requirements.txt -t layer/python/
cd layer
zip -r9 ../layer.zip .
cd ..

# Deploy the Layer
LAYER_ARN=$(aws lambda publish-layer-version --layer-name zappa-layer --zip-file fileb://layer.zip --compatible-runtimes python3.9 --query LayerVersionArn --output text)
echo $LAYER_ARN
# Update Zappa settings with the new Layer ARN
jq --arg LAYER_ARN "$LAYER_ARN" '.dev.layers[0] = $LAYER_ARN' zappa_settings.json > tmp.json && mv tmp.json zappa_settings.json
rm -rf layer.zip layer

Upvotes: 0

Edgar
Edgar

Reputation: 1249

There is an open pull request that is ready to merge, but needs additional user testing.

The older project has a pull request that claims layer support has been merged

Feel free to try it out and let the maintainers know so documentation can be updated.

Upvotes: 2

Related Questions