繁体   English   中英

从S3下载,存储在Lambda的/ tmp /中,并在/ tmp /目录中解压缩

[英]Download from S3, store in /tmp/ of Lambda and unzip in /tmp/ directory

我在S3上有一个zip文件。 我需要使用Lambda的/tmp文件夹进行我用于存储zip文件的延迟加载,然后我需要该文件夹包含解压缩的内容。 我正在使用Python进行操作。 下面是代码:

import sys
import zipfile
import subprocess

s3 = boto3.resource('s3')
s3.meta.client.download_file('bucket', 'dependencies/dependencies.zip', '/tmp/dependencies.zip')

output = subprocess.check_output('unzip /tmp/dependencies.zip -d /tmp/')
print("Output: ", output.decode('utf-8'))

我收到错误消息: No such file or directory: 'unzip /tmp/dependencies.zip -d /tmp/': 'unzip /tmp/dependencies.zip -d /tmp/' Unknown application error occurred

我将代码放在lambda_handler()之外以进行冷启动。 由此,我什至无法确定已将压缩文件复制到/tmp目录,因为该行没有引发任何错误,而且我也无法解压缩内容。 我试图删除tmp前面的/ ,但这也没有帮助。 我要去哪里错了?

首先要确认文件已下载( 如何检查文件是否在Python中存在-dbader.org )。

问题可能在于子流程找不到unzip

我注意到您已导入zipfile ,因此可以将该库解压缩。 python解压缩文件中

import zipfile
with zipfile.ZipFile('/tmp/dependencies.zip', 'r') as zip_ref:
    zip_ref.extractall('/tmp/')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM