I am trying to deploy a Lambda function on AWS, through Serverless, that requires Tensorflow 2, Pandas and Numpy;
I would like to remove from the serverless.yml file, the Tensorflow libraries not required for inference as briefly done in the following sections:
(...)
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: true
zip: true
slim: true
useDownloadCache: true
slimPatterns:
- "**/tensorboard*"
- "**/markdown*"
- "**/werkzeug*"
- "**/grpc*"
- "**/tensorflow/contrib*"
- "**/tensorflow/include*"
- "**/external/*"
noDeploy:
- boto3
- botocore
- docutils
- jmespath
- pip
- python-dateutil
- s3transfer
- setuptools
- six
Within my handler.py script, the only Tensorflow-based lines are the following:
# Import a model with Dense layers only
tf.keras.models.load_model(model_name)
# Run inference
predictions = model.predict(my_array)
However, whenever I try to deploy the service using "sls deploy", it raises an error due to file size:
Uploading service tensorflow-lambda-demo-1234.zip file to S3 (336.22 MB)...
(...)
An error occurred: HelloLambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: Lambda, Status Code: 400, Request ID: 3805f9b4-eb32-4d11-b54a-3437bf2b6d6b, Extended Request ID: null).
Which sub-libraries ("slimPatterns") and whole packages ("noDeploy") can I further exclude from the deployment package to reduce its size?