You can now mount ** EFS ** on ** Lambda **. This allows you to import Python libraries set up in EFS into Lambda.
Until now, if you wanted to import a library other than the Python standard to Lambda, the only way was to upload it to the Lambda layer. However, this method has a size limit of compressed to 50MB or less and decompressed to 250MB or less
. For this reason, it was not possible to use multiple large libraries. Therefore, if the system is a little large, it is necessary to take measures such as going out some processing to docker, and Lambda alone was not complete.
However, now that you can mount EFS on Lambda, this issue goes away. ʻYou can now import libraries installed on EFS into Lambda. ``
how to
Create an EFS access point (client access)
Owner User ID: 1001
Owner group ID: 1001
Permissions: 777
The path (directory) is set here to / lambda
Mount EFS on working EC2
sudo yum install -y amazon-efs-utils
cd /mnt
sudo mkdir efs
sudo mount -t efs fs-xxxxx:/ efs
Install Python and libraries on EFS Install Python3.8.1 and pandas here
sudo yum -y install gcc openssl-devel bzip2-devel libffi-devel
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
tar xzf Python-3.8.1.tgz
cd Python-3.8.1
sudo ./configure --enable-optimizations
sudo make altinstall
# check
python3.8 --version
pip3.8 --version
cd /mnt/efs
pip3.8 install --upgrade --target lambda/ pandas
Set up Lambda function Need to belong to VPC Added policy ʻAmazonElasticFileSystemClientReadWriteAcces` to Lambda execution role Add EFS
Import with Lambda You can import it like this.
import sys
sys.path.append("/mnt/efs")
import pandas as pd
Recommended Posts