python - Running perl script in lambda function with python3.6 runtime
问题描述
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?
解决方案
尝试将https://p3rl.org/AWS::Lambda中列出的 ARN 之一添加到您的引用层(那里有说明)。
我自己没有这样做,但从我所看到的一切来看,它应该可以工作。
推荐阅读
- java - Libgdx firebase robovm 绑定
- php - 将 JSON 对象作为字符串而不是数组发送
- reactjs - How Do I Create A 2 Column Form WIth React Material-UI?
- ios - React-native fetch (ios) RANDOMLY 使 https 请求失败,网络请求失败
- c++ - gcc 在这个概念定义中是否错误地评估了 std::declval ?
- java - 在junit类中排序
- ios - Braintree Apple Sandbox Pay 扫描指纹 iOS 后显示付款未完成错误
- google-cloud-platform - How do you implement role based authorisation after authenticating with Google Cloud IAP?
- php - 如何关闭或退出安装在我的 Ubuntu 18.04 中的 Docker?
- java - 如何告诉 eclipse 从 maven repo 中读取 javadocs?