1

I followed the steps in this video (https://www.youtube.com/watch?v=ItE6MAZaiJY) to create a virtual environment and zip the dependencies along with my code.

My code:

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))

The handler name is lambda_function.get_img_list (get_img_list() is the first function that should run).

I read on this thread that the local libraries are compiled for the local machine architecture (I am using Windows 10 and Powershell).

The github link given in the aforementioned thread for lambda packages has Pillow for Python 2.7 and I am using 3.8.

How do I resolve this?

Thanks.

Bittu
  • 79
  • 1
  • 8
  • This might be of assistance: [Sample Amazon S3 Function Code - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html#with-s3-example-deployment-pkg-python). It is a walkthrough that packages up Pillow. You might also benefit from [Installing Windows Subsystem for Linux (WSL) on Windows 10 | Microsoft Docs](https://learn.microsoft.com/en-us/windows/wsl/install-win10). – John Rotenstein Mar 29 '20 at 03:29

0 Answers0