Python package successfully importing for Glue scripts but not for Lambda functions

33 Views Asked by At

I have a .zip file named pg8000.zip sitting on an S3 bucket: mybucket/devops/pg8000.zip

It's currently in use for Glue 4.0 scripts as show below in the Python libraries field: s3://mybucket/devops/pg8000.zip

That works just fine in Glue - however when trying to create a Lambda layer with that same package:

Resources:
  MyLambdaLayer:
    Type: AWS::Lambda::LayerVersion
    Properties:
      LayerName: "Pg8000Layer"
      Description: "Layer containing pg8000"
      Content: 
        S3Bucket: "mybucket"
        S3Key: "devops/pg8000.zip"
      CompatibleRuntimes: 
        - python3.8

I get the following error on my Lambda functions when running with the layer attached: [ERROR] Runtime.ImportModuleError: Unable to import module index: no module named pg8000

Do I have to repackage the library for the 2 services?

Expected the same results between the 2 services for importing libraries - but failed to produce the same results.

1

There are 1 best solutions below

0
Nitesh Kumar  Singh On

how the structure of the .zip file should look:

 pg8000/
__init__.py
other_module.py

Where pg8000 is the root directory containing the library files.