Python 3.x 如何解决AWS Lambda无法导入模块错误消息?
我按照本视频()中的步骤创建了一个虚拟环境,并将依赖项与代码一起压缩 我的代码:Python 3.x 如何解决AWS Lambda无法导入模块错误消息?,python-3.x,aws-lambda,python-imaging-library,Python 3.x,Aws Lambda,Python Imaging Library,我按照本视频()中的步骤创建了一个虚拟环境,并将依赖项与代码一起压缩 我的代码: import os import io import boto3 import botocore from botocore.exceptions import NoCredentialsError, ClientError from PIL import Image s3_resource = boto3.resource('s3') def get_img_list(): s3 = boto3.cli
import os
import io
import boto3
import botocore
from botocore.exceptions import NoCredentialsError, ClientError
from PIL import Image
s3_resource = boto3.resource('s3')
def get_img_list():
s3 = boto3.client('s3')
response = s3.list_objects_v2(
Bucket='imagesforgreendub',
Prefix='photo_test/',
)
for val in response['Contents']:
if val['Key'] != 'photo_test/':
temp = val['Key']
img_name = temp.split('/')
print(img_name)
if img_name[1] != '':
thumb_name = 'thumb_' + str(img_name[1])
print(thumb_name, img_name[1])
img = image_from_s3('imagesforgreendub', val['Key'])
img_thumb(img, thumb_name)
def image_from_s3(bucket_name, key):
bucket = s3_resource.Bucket(bucket_name)
image = bucket.Object(key)
img_data = image.get().get('Body').read()
return Image.open(io.BytesIO(img_data))
def img_thumb(img, thumb_name):
MAX_SIZE = (100, 100)
img.thumbnail(MAX_SIZE)
img.save('local_img.jpg')
s3 = boto3.client('s3')
s3.upload_file('local_img.jpg', 'imagesforgreendub', '%s/%s' % ('thumbs', thumb_name))
处理程序名称为lambda\u函数。get\u img\u list
(get\u img\u list()是应运行的第一个函数)
我了解到本地库是针对本地机器体系结构编译的(我使用的是Windows 10和Powershell)
前面提到的lambda包线程中给出的是Python2.7的枕头,我使用的是3.8
我如何解决这个问题
谢谢。这可能会有所帮助:。这是一个包装枕头的演练。您也可能从中受益。这可能会有所帮助:。这是一个包装枕头的演练。你也可能从中受益。