I am trying to run an exiftool for reading image meta data within a python script, as part of a lambda function on AWS.
On an ec2 instance running amazon linux, which is what the python3.6 runtime uses, I can download the tool, extract it, then run it easily. However, trying to do this from my python script in the lambda function does not work.
My lambda function is as follows:
import imageio
import subprocess
import utils
import os
import stat
import boto3
s3_client = boto3.client('s3')
# get exif tool
s3_client.download_file(
'zipped.code',
'Image-ExifTool-11.53.tar.gz',
'/tmp/Image-ExifTool-11.53.tar.gz')
p = subprocess.run('tar -zxvf Image-ExifTool-11.53.tar.gz', cwd='/tmp', shell=True)
def get_meta_data(im):
p = subprocess.Popen(
'/tmp/Image-ExifTool-11.53/exiftool -',
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
out, err = p.communicate(input=imageio.imwrite('<bytes>', im, format='jpg'))
print(out) # b''
print(err) # b'/bin/sh: /tmp/Image-ExifTool-11.53/exiftool: /usr/bin/perl: bad interpreter: No such file or directory\n'
def lambda_handler(event, context):
src_key = event['src_key']
image = utils.download_image_to_memory(src_key)
print(get_meta_data(image))
I have ran this code locally and it works. If I print the contents of /usr/bin within the lambda function by print(os.listdit('/usr/bin')) there is no perl executable in there. However in the /usr/bin directory on an ec2 instance with amazon linux the perl executable is there.
I suspect the problem is my lack of perl (the tool is written in perl), but why is there no perl interpretter given that lambdas are supposed to run with the amazon linux image?