通过AWS CLI解压S3文件并将解压后的文件推回S3

3

您能否使用AWS CLI解压S3中的文件,并将解压后的版本推回S3?

尝试以下操作,但目前还没有成功。

unzip aws s3 cp https://aws-lake/test/test.zip

您可以使用管道来完成此操作。aws s3 cp xxxx.zip || unzip xxx.zip -d test/ || aws s3api put-object --bucket text-content --key dir-1/ --body test/ - Prashanna
解压缩 aws s3 cp https://aws-lake/bucket/file.zip || unzip file.zip -d test/ || aws s3 put-object --bucket https://aws-lake/bucket/这是我尝试的命令,但是出现了以下错误: unzip: 找不到或无法打开 aws、aws.zip 或 aws.ZIP。 unzip: 找不到或无法打开 file.csv、file.zip 或 file.ZIP。 - 0004
1个回答

7
您至少需要执行三个操作:
# Download the zip file from S3, note the use of the S3 URI, not HTTPS
aws s3 cp s3://aws-lake/test/test.zip temp.zip

# Decompress the zip file into a temp directory
unzip -d temp_zip_contents temp.zip

# Sync up the contents of the temp directory to S3 prefix
aws s3 sync temp_zip_contents s3://aws-lake/test/test_contents

# And optionally, clean up the temp files and directory
# Unix:
rm -rf temp.zip temp_zip_contents
# Windows
rd /s/q temp_zip_contents
del temp.zip

有可能编写程序将文件下载到内存中,读取zip文件的内容并解压缩单个文件进行上传,但需要执行多个命令行命令。


那么您的意思是我不能使用AWS CLI,只能使用Python脚本吗? - 0004
您可以使用AWS cli在命令行中运行这三个命令(以及第四个清理命令)。如果您需要一条命令来完成它,可以编写批处理文件或脚本。如果您需要在没有本地存储的情况下完成它,则需要编写Python脚本或更复杂的脚本。 - Anon Coward
这意味着文件已损坏。如果您删除本地文件,重新下载并获得相同的错误(相同的 CRC 数字),则表示在 S3 上它是损坏的。 - Anon Coward
为什么会将一个 CSV 文件推到哪里了? - Anon Coward
不确定为什么您在复制了所有文件夹的文件后还要复制一个文件,但如果您想要复制一个文件,请使用类似于 aws s3 cp local_filename.csv s3://bucket/prefix/remote_filename.csv 的命令。 - Anon Coward
显示剩余10条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接