newbie dev
newbie dev

Reputation: 171

How to install Pillow on AWS lambda for python 3.8?

I have installed necessary python libraries and made zip and uploaded to layers in AWS lambda. Among those libraries, i have PIL and Pillow-8.2.0 also. However, when i try to get image in AWS lambda using the following code.

import openpyxl
from openpyxl.writer.excel import save_virtual_workbook
from openpyxl.drawing.image import Image
import PIL
import io
import urllib3

wb = openpyxl.Workbook()
ws = wb.active
r = 1
http = urllib3.PoolManager()
r = http.request('GET', 'http://myridia.com/assets/images/logo.png')
image_file = io.BytesIO(r.data)
img = Image(image_file)
ws.add_image(img, 'A2')
wb.save("hello.xlsx")

But above code works fine when i run in my local machine. I have also tried using arn:aws:lambda:ap-south-1:770693421928:layer:Klayers-python38-Pillow:10 but it shows the same error. My runtime is python 3.6 or 3.8. I am unable to understand, how do i make it work. Can anyone please help me?

enter image description here

Upvotes: 4

Views: 9288

Answers (1)

newbie dev
newbie dev

Reputation: 171

At First, I uninstall the PIL and Pillow package from local file and made a zip then uploaded to AWS lambda layer. As expected, it showed the above error of PILLOW install. Then, I added a layer using arn name of PIllow from https://api.klayers.cloud//api/v2/p3.8/layers/latest/ap-south-1/csv (Others by region). Then it did work as expected.

Upvotes: 3

Related Questions