Skip to content

Problem acessing EFS via lambda in ap-southeast-2

0

I've created an EFS for adding dependencies to a lambda function to overcome the 250mb limit using layers. When trying my code I get : [ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'PIL' Traceback (most recent call last):. So i started some trouleshooting and it appears that all the subfolders in the EFS are not visible?

ubuntu@ip-172-31:/mnt/efs$ ls PIL imageio-2.35.0.dist-info networkx numpy.libs pillow-10.4.0.dist-info scipy.libs bin imutils networkx-3.3.dist-info opencv_python-4.10.0.84.dist-info pillow.libs skimage cv2 imutils-0.5.4.dist-info numpy opencv_python.libs scikit_image-0.24.0.dist-info tifffile dependencies.zip lazy_loader numpy-1.26.4.dist-info packaging scipy tifffile-2024.8.10.dist-info imageio lazy_loader-0.4.dist-info numpy-2.0.1.dist-info packaging-24.1.dist-info scipy-1.14.0.dist-info

Test code:

import os import logging

logger = logging.getLogger() logger.setLevel(logging.INFO)

def lambda_handler(event, context): logger.info("Accessing EFS directory: /mnt/efs") try: contents = os.listdir('/mnt/efs') logger.info(f"EFS directory contents: {contents}")

    for item in contents:
        if os.path.isdir(os.path.join('/mnt/efs', item)):
            logger.info(f"Found subdirectory: {item}")
            subdirectory_contents = os.listdir(os.path.join('/mnt/efs', item))
            logger.info(f"Subdirectory contents: {subdirectory_contents}")

    return {
        'statusCode': 200,
        'body': 'EFS directory contents listed successfully'
    }
except Exception as e:
    logger.error(f"Error accessing EFS: {e}")
    return {
        'statusCode': 500,
        'body': f"Error: {e}"
    }

Result:

Test Event Name test1

Response { "statusCode": 200, "body": "EFS directory contents listed successfully" }

Function Logs START RequestId: 537e48d8-20ca-40cb-879a-c0d07a1a1291 Version: $LATEST [INFO] 2024-08-24T23:33:54.618Z 537e48d8-20ca-40cb-879a-c0d07a1a1291 Accessing EFS directory: /mnt/efs [INFO] 2024-08-24T23:33:54.625Z 537e48d8-20ca-40cb-879a-c0d07a1a1291 EFS directory contents: ['dependencies.zip'] END RequestId: 537e48d8-20ca-40cb-879a-c0d07a1a1291 REPORT RequestId: 537e48d8-20ca-40cb-879a-c0d07a1a1291 Duration: 10.12 ms Billed Duration: 11 ms Memory Size: 128 MB Max Memory Used: 30 MB Init Duration: 72.54 ms

Request ID 537e48d8-20ca-40cb-879a-c0d07a1a1291

Only the file (dependencies.zip) seems to be visible?

asked a year ago196 views
1 Answer
1

Hello.

I tried referencing the directory after EFS mounting using the code you created, and was able to successfully check the contents of the directory.
Therefore, it is possible that the directory where the "ls" command is executed and the directory mounted by Lambda do not match, or the access point is incorrect.
In the environment I tested, I installed only "Pillow" within EFS and confirmed its operation.

[INFO]	2024-08-25T02:58:35.563Z	11111111-1111-1111-1111-111111111111	Accessing EFS directory: /mnt/efs
[INFO]	2024-08-25T02:58:35.568Z	11111111-1111-1111-1111-111111111111	EFS directory contents: ['pillow-10.4.0.dist-info', 'PIL', 'pillow.libs']
[INFO]	2024-08-25T02:58:35.568Z	11111111-1111-1111-1111-111111111111	Found subdirectory: pillow-10.4.0.dist-info
[INFO]	2024-08-25T02:58:35.573Z	11111111-1111-1111-1111-111111111111	Subdirectory contents: ['top_level.txt', 'REQUESTED', 'INSTALLER', 'METADATA', 'WHEEL', 'LICENSE', 'RECORD', 'zip-safe']
[INFO]	2024-08-25T02:58:35.573Z	11111111-1111-1111-1111-111111111111	Found subdirectory: PIL
[INFO]	2024-08-25T02:58:35.585Z	11111111-1111-1111-1111-111111111111	Subdirectory contents: ['SpiderImagePlugin.py', 'PsdImagePlugin.py', 'ImageFilter.py', 'PcdImagePlugin.py', 'XbmImagePlugin.py', 'ImageMorph.py', 'FtexImagePlugin.py', 'PSDraw.py', '__main__.py', 'ImageDraw.py', 'BmpImagePlugin.py', 'ImageWin.py', 'DcxImagePlugin.py', 'GbrImagePlugin.py', 'ImageMath.py', 'FliImagePlugin.py', 'PcxImagePlugin.py', 'DdsImagePlugin.py', '_util.py', 'IcoImagePlugin.py', 'ImageOps.py', 'ImageEnhance.py', '_version.py', 'SgiImagePlugin.py', 'Jpeg2KImagePlugin.py', 'ContainerIO.py', 'QoiImagePlugin.py', 'PyAccess.py', 'ExifTags.py', 'MpegImagePlugin.py', 'MicImagePlugin.py', 'GimpGradientFile.py', 'TiffImagePlugin.py', 'Image.py', 'ImageFile.py', 'ImageDraw2.py', 'BdfFontFile.py', 'McIdasImagePlugin.py', '_imagingcms.cpython-39-x86_64-linux-gnu.so', 'ImageStat.py', 'IcnsImagePlugin.py', 'ImageGrab.py', 'TarIO.py', 'BufrStubImagePlugin.py', 'features.py', 'PpmImagePlugin.py', '_imagingtk.cpython-39-x86_64-linux-gnu.so', 'PaletteFile.py', 'ImageTransform.py', 'Hdf5StubImagePlugin.py', 'PngImagePlugin.py', 'WalImageFile.py', 'FontFile.py', 'XpmImagePlugin.py', '_tkinter_finder.py', '_imagingcms.pyi', 'PdfParser.py', '_imagingmath.cpython-39-x86_64-linux-gnu.so', '_imagingft.cpython-39-x86_64-linux-gnu.so', '_imagingmorph.pyi', 'EpsImagePlugin.py', 'ImageFont.py', '_typing.py', 'ImageColor.py', 'MspImagePlugin.py', 'IptcImagePlugin.py', '_webp.cpython-39-x86_64-linux-gnu.so', '__pycache__', 'ImageTk.py', 'ImagePalette.py', 'GdImageFile.py', 'MpoImagePlugin.py', '_imagingft.pyi', 'TgaImagePlugin.py', '_imagingmath.pyi', 'PixarImagePlugin.py', '_webp.pyi', '_imagingmorph.cpython-39-x86_64-linux-gnu.so', 'ImageCms.py', 'py.typed', 'ImtImagePlugin.py', 'JpegPresets.py', 'PdfImagePlugin.py', 'WmfImagePlugin.py', 'CurImagePlugin.py', 'GimpPaletteFile.py', '_deprecate.py', 'report.py', 'ImageSequence.py', 'PalmImagePlugin.py', 'GribStubImagePlugin.py', 'ImageShow.py', '_binary.py', '_imaging.pyi', 'XVThumbImagePlugin.py', 'WebPImagePlugin.py', 'ImageChops.py', '__init__.py', 'BlpImagePlugin.py', '_imaging.cpython-39-x86_64-linux-gnu.so', 'ImagePath.py', 'PcfFontFile.py', 'FpxImagePlugin.py', 'GifImagePlugin.py', 'ImageMode.py', 'ImImagePlugin.py', 'ImageQt.py', 'SunImagePlugin.py', 'FitsImagePlugin.py', 'TiffTags.py', 'JpegImagePlugin.py']
[INFO]	2024-08-25T02:58:35.585Z	11111111-1111-1111-1111-111111111111	Found subdirectory: pillow.libs
[INFO]	2024-08-25T02:58:35.602Z	11111111-1111-1111-1111-111111111111	Subdirectory contents: ['libpng16-58efbb84.so.16.43.0', 'liblzma-13fa198c.so.5.4.5', 'libbrotlidec-ba690955.so.1', 'libxcb-b8a56d01.so.1.1.0', 'libwebpmux-d524b4d5.so.3.1.0', 'liblcms2-e69eef39.so.2.0.16', 'libharfbuzz-89381d8f.so.0.60850.0', 'libbrotlicommon-3ecfe81c.so.1', 'libopenjp2-05423b53.so', 'libfreetype-be14bf51.so.6.20.1', 'libXau-154567c4.so.6.0.0', 'libjpeg-77ae51ab.so.62.4.0', 'libwebpdemux-f2642bcc.so.2.0.15', 'libwebp-2fd3cdca.so.7.1.9', 'libsharpyuv-898c0cb5.so.0.1.0', 'libtiff-0a86184d.so.6.0.2']
EXPERT
answered a year ago
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago
  • Hi Riku, I took a gamble and unzipped the dependencies again, this time the path is /mnt/efs/dependencies with PIL etc under there. Then I ran the code to check the contents from lambda and they appear. I don't know why they are now visible, maybe the order in which I did things to make the efs matters?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.