ML model deployment in AWS Lambda: EFS update

Pascal Niville
Ixor
Published in
2 min readMay 7, 2021

Update: This approach is outdated, a better approach is discussed in this blog

Out of memory errors are a nightmare if you try to fit several large packages into AWS lambda functions. This is typically what you do when you want to deploy a machine learning model into the AWS lambda ecosystem. To cope with this, some tips and tricks were listed in our previous blog. Unfortunately, the process still required some hacking and careful package pruning.

Luckily we can safely say that the days of frustrating memory errors and package nitpicking are over! This thanks to a recent update by AWS. A new option has been introduced to link your lambda function with an elastic file system (EFS). The EFS has practically no size limit and can be mounted as an external drive on the lambda function.

[1]

How to add the EFS to your lambda function

To enable the EFS, some configuration is required. The following steps will guide you through the process:

step 1: Setup the EFS and mount it to EC2 by following this guide.

step 2: Copy the python libraries to the EFS over EC2.

On your EC2 instance you should do something like:
sudo yum install -y amazon-efs-utils unzip
sudo mount -t efs fs-12ab34cd:/ /mnt
#copy the pythonpackages from s3 to the EC2 instance
aws s3 cp s3://bucket/AllYourPypackages.zip /tmp/pythonpackages.zip
#when EFS is mounted on /mnt
sudo mkdir /mnt/python/v0.0.1
cd /mnt/python/v0.0.1
sudo unzip /tmp/pythonpackages.zip

3. Configure the lambda functions to enable the EFS

4. Add the EFS to the sys path in your lambda function

# the "local mount" path of the lambda file system configuration:
# /mnt/pylibs
import sys
sys.path.append('/mnt/pylibs/python/v0.0.1')

And that’s it! Now you should be able to enjoy the EFS.

Throughput

As a final note, you should know that the available capacity (burst credits) your EFS can consume is limited. If all burst credits are consumed, timeout errors can arise in your lambda functions. This page describes how AWS regulates your amount of burst credits. The available amount of burst credits can easily be increased by creating large dummy files on the EFS.

At IxorThink, the machine learning practice of Ixor, we are constantly trying to improve our methods to create state-of-the-art solutions. As a software company, we can provide stable products from proof-of-concept to deployment. Feel free to contact us for more information.

--

--