php 上传ZIP文件到S3,使用EC2解压
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9719302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uploading ZIP file to S3, use EC2 to Unzip
提问by Nyxynyx
I have a Codeigniter web app that is uploading many tiny files every hour to Amazon S3, which is causing my S3 request charges to shoot up real fast. One way to overcome this will be to zip up the file, upload the zip file to S3, then unzip it when it is on S3.
我有一个 Codeigniter Web 应用程序,它每小时向 Amazon S3 上传许多小文件,这导致我的 S3 请求费用非常快。解决此问题的一种方法是压缩文件,将 zip 文件上传到 S3,然后在 S3 上解压缩。
Can this be done using EC2? Or is there a better method to achieve this? Thank you!!
这可以使用 EC2 完成吗?或者有没有更好的方法来实现这一目标?谢谢!!
EDIT: If I were to use EC2, do I use PHP to trigger the creation of a EC2 instance, upload the PHP file required to unzip the zipped files, copy the uncompressed files to S3, then destroy the EC2 instance?
编辑:如果我使用 EC2,我是否使用 PHP 来触发 EC2 实例的创建,上传解压缩压缩文件所需的 PHP 文件,将未压缩的文件复制到 S3,然后销毁 EC2 实例?
回答by Akshat
If you have an EC2 machine in the same region I would suggest you upload it there zipped and then it drop it to s3 from there unzipped. S3 cannot unzip it on its own as its all static.
如果您在同一地区有一台 EC2 机器,我建议您将其上传到压缩文件中,然后从那里解压缩到 s3。S3 无法自行解压缩,因为它完全是静态的。
Theres no charges between ec2 and s3 so ec2 can handle the unzipping and then write it out into your s3 bucket without additional transfer charges.
ec2 和 s3 之间没有任何费用,因此 ec2 可以处理解压缩,然后将其写入您的 s3 存储桶,而无需额外的传输费用。
回答by Aman Garg
You can write code in a lambda to unzip a file of S3 bucket, you just have to use it, AWS Lambda will do this for you.
您可以在 lambda 中编写代码来解压缩 S3 存储桶的文件,您只需要使用它,AWS Lambda 将为您完成此操作。
Referece:
参考:
回答by bwight
S3 is just storage. Whatever file you upload is the file that is stored. You cannot upload a zip file then extract it once its in S3. If you wrote the application the best thing I could say is to try to re-design how you store the files. S3 requests are pretty cheap... you must be making a lot of requests.
S3 只是存储。您上传的任何文件都是存储的文件。您不能上传 zip 文件,然后在 S3 中将其解压缩。如果您编写了应用程序,我能说的最好的事情就是尝试重新设计您存储文件的方式。S3 请求非常便宜……您一定会提出很多请求。
回答by Henry Cullen
I have been using this service to unzip files full of thousands of tiny image files, each zip I upload is about 4GB, and costs around $1 to unzip using http://www.cloudzipinc.com/service/s3_unzip, maybe that might help someone.
我一直在使用这项服务来解压缩包含数千个小图像文件的文件,我上传的每个 zip 大约 4GB,使用http://www.cloudzipinc.com/service/s3_unzip解压缩大约需要 1 美元,也许这可能会有所帮助某人。
Having said that, you might find it easier to use Python with the Boto library. That will work far more efficiently than PHP.
话虽如此,您可能会发现将 Python 与 Boto 库一起使用会更容易。这将比 PHP 更有效地工作。