英文:
Uploading Google API python library to Lambda
问题
I have a Jupyter notebook that I've built a script in for extracting data from a Google Sheet using these two imports:
from googleapiclient.discovery import build
from google.oauth import service_account
I'm trying to copy it to AWS Lambda and I'm having trouble uploading these three libraries to a layer:
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
I downloaded them from pypi.org. They all only have one download option and don't specify which version of python 3 they're compatible with, except google-api-python-client
, which has "Python 3.7, 3.8, 3.9, 3.10, and 3.11 are fully supported and tested" in the comments.
I just checked, and it looks like my Jupyter notebook is running Python 3.10. I've also copied the script into VSCode, and these libraries also appear to only work in Python 3.10, which is weird since at least one of them should still work in all versions. It makes me think I'm doing something wrong.
Also, it doesn't look like Lambda supports 3.10. So is there no way to run Google libraries on it? Or do I need to use older libraries?
英文:
I have a Jupyter notebook that i've built a script in for extracting data from a Google Sheet using these two imports:
from googleapiclient.discovery import build
from google.oauth import service_account
I'm trying to copy it to AWS Lambda and I'm having trouble uploading these three libraries to a layer:
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
I downloaded them from pypi.org. They all only have one download option and don't specify which version of python 3 they're compatible with, except google-api-python-client
which has "Python 3.7, 3.8, 3.9, 3.10 and 3.11 are fully supported and tested." in the comments.
I just checked and it looks like my Jupyter notebook is running Python 3.10. I've also copied the script into VSCode and these libraries also appear to only work in Python 3.10. Which is weird since at least one of them should still work in all versions.
It makes me think i'm doing something wrong.
Also, it doesn't look like Lambda supports 3.10? So is there no way to run Google libraries on it? Or do I need to use older libraries?
答案1
得分: 1
FROM amazon/aws-lambda-python:3.9
RUN pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
Build it:
docker build . --progress=plain
See logs:
#5 24.65 Successfully installed cachetools-5.3.0 certifi-2022.12.7 charset-normalizer-3.0.1 google-api-core-2.11.0
google-api-python-client-2.77.0 google-auth-2.16.0
google-auth-httplib2-0.1.0 google-auth-oauthlib-1.0.0
googleapis-common-protos-1.58.0 httplib2-0.21.0 idna-3.4
oauthlib-3.2.2 protobuf-4.21.12 pyasn1-0.4.8 pyasn1-modules-0.2.8
pyparsing-3.0.9 requests-2.28.2 requests-oauthlib-1.3.1 rsa-4.9
six-1.16.0 uritemplate-4.1.1 urllib3-1.26.14
So your requirements.txt
for Python 3.9 will look like:
google-api-python-client==2.77.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
I recommend you work locally using the same version of Python and its packages. Docker is great for that!
英文:
If you don't have 3.9 locally, you can use Docker to run it inside a container and see which packages you need.
FROM amazon/aws-lambda-python:3.9
RUN pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
Build it:
docker build . --progress=plain
See logs:
> #5 24.65 Successfully installed cachetools-5.3.0 certifi-2022.12.7 charset-normalizer-3.0.1 google-api-core-2.11.0
> google-api-python-client-2.77.0 google-auth-2.16.0
> google-auth-httplib2-0.1.0 google-auth-oauthlib-1.0.0
> googleapis-common-protos-1.58.0 httplib2-0.21.0 idna-3.4
> oauthlib-3.2.2 protobuf-4.21.12 pyasn1-0.4.8 pyasn1-modules-0.2.8
> pyparsing-3.0.9 requests-2.28.2 requests-oauthlib-1.3.1 rsa-4.9
> six-1.16.0 uritemplate-4.1.1 urllib3-1.26.14
So your requirements.txt
for Python 3.9 will look like:
google-api-python-client==2.77.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
I recommend you work locally using the same version of Python and its packages. Docker is great for that!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论