0

Getting this error from my python script whenever I run a test

{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'PIL'",
  "errorType": "Runtime.ImportModuleError",
  "stackTrace": []
}

This code should take an input from an aws s3 bucket and transform it to a vangogh painting, then send it back to another s3 bucket.

import boto3
import os
import sys
import uuid
from PIL import Image
import PIL.Image

s3_client = boto3.client('s3')

def vangogh_image(image_path, transformation_path):
    with Image.open(image_path).convert('RGB') as image:
        image.filter('VAN_GOGH')
        image.save(transformation_path)
    
def handler(event, context):
    for record in event['Records']:
        bucket = record['s3']['bucket']['name']
        key = record['s3']['object']['key']
        download_path = 'temp/{}{}'.format(uuid.uuid(), key)
        upload_filename = '/temp/vangogh-{}'.format(key)
    
        s3_client.download_file(bucket, key, download_path)
        vangogh_image(download_path, upload_filename)
        s3_client.upload_file(upload_filename, '{}-vangigh'.format(bucket), key)
Nick ODell
  • 15,465
  • 3
  • 32
  • 66
  • 1
    Does this answer your question? [AWS lambda Unable to import module 'lambda\_function': No module named PIL](https://stackoverflow.com/questions/50734416/aws-lambda-unable-to-import-module-lambda-function-no-module-named-pil) – Tharun K Dec 12 '22 at 04:21
  • It doesn't I am using lambda functions, I do not have an ec2 instance running. Those solutions are requiring logging into the ec2 instance to install a package. – Barry Bonds Dec 12 '22 at 15:58
  • You have to make the library available to your lambda function either in the zip file that you deploy or in a layer. More detail here https://stackoverflow.com/questions/73103700/lambda-layer-using-colander/73115710#73115710 – RodP Dec 13 '22 at 19:25

0 Answers0