0
votes

I am new to AWS Lambda, I am trying to add a googles google-api-python-client to my function and what I've read so far this is the way to do it:

  1. I download the file locally pip install google-api-python-client -t ./google, then zip the google folder, upload it as a layer in AWS lambda Create layer section as a .zip file.
  2. I do the same with another package pip install google-auth-oauthlib -t ./google_auth
  3. My lambda function looks like this:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

def lambda_handler(event, context):
    return ('test')

When I run it I get:

Response:
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'apiclient'",
  "errorType": "Runtime.ImportModuleError"
}

enter image description here

How can I include these packages to be available in my script?

1

1 Answers

1
votes

While working with layers, the zip file should have all the modules/libraries inside a "python" folder as here the doc. You can install the package using $ pip install google-api-python-client -t ./python followed by zip -r layer.zip python and try uploading this as a new Layer and reference that in the function.

You can quickly verify the output of the .zip file using $ zipinfo layer.zip or $ unzip -l layer.zip to ensure it matches the requirements as per the docs -

pillow.zip
│ python/PIL
└ python/Pillow-5.3.0.dist-info