使用 EC2 压缩 S3 文件

发布于 2024-09-25 04:45:35 字数 285 浏览 0 评论 0原文

我正在尝试使用 EC2 压缩存储在 S3 存储桶中的一些文件。我已经成功地让 SWFUpload 使用 PHP 并将文件上传到 S3。我读到,压缩 S3 文件而不产生巨大传输成本的最佳方法是使用 EC2 来处理 S3。经过大量努力,我设法让 EC2 服务器运行并通过 SSH 连接到其中,但现在我不知道从这里做什么。

压缩 S3 文件并将其放回存储桶的最佳方法是什么?

理想情况下,用户的批量上传将触发 SQS,然后我每天启动一次 EC2 服务器以将它们全部压缩并将它们交还给 S3 进行下载。不知道从这里去哪里。有想法吗?

I am trying to use EC2 to zip up some files that are stored in an S3 bucket. I have gotten as far as successfully getting SWFUpload to work with PHP and upload the files to S3. I read that the best way to zip up S3 files without incurring huge transfer costs is to use EC2 to deal with S3. After a lot of effort I managed to get a EC2 server running and SSH into it, but now I don't know what to do from here.

What's the best way to zip S3 files and put them back in the bucket?

Ideally, a user's batch upload would trigger an SQS and then I'd spin up the EC2 server once a day to zip them all and hand them back to S3 for downloading. No idea where to go from here. Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2024-10-02 04:45:35

您应该查看 aws - 一个用于 ec2、s3 和其他 AWS 服务。

当您安装该工具并设置 AWS 凭证时,它将创建各种命令的方便符号链接 - 包括 s3。

总体思路是:

  • 从存储桶中下载文件 (s3get)
  • 对其进行压缩 (gzip)
  • 再次上传 (s3put)

如果您需要更多指针,请告诉我。

也许您想在上传之前用 PHP 压缩文件?这需要安装 zip 扩展。

sudo pecl install zip

这是一个示例脚本:

<?php
$zip      = new ZipArchive();
$filename = "/tmp/" . time() .".zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) {
    exit("cannot open <$filename>\n");
}
$zip->addFile('/path/to/uploaded/file');
$zip->close();

// continue uploading to s3

You should check out aws - a command line tool to ec2, s3 and other AWS services.

When you install the tool and setup your AWS credentials, it will create handy symlinks all kinds of commands -- including s3.

The general idea is:

  • download the file from the bucket (s3get <bucket/file>)
  • zip it (gzip <file>)
  • upload it again (s3put <file>)

Let me know if you need more pointers.

Maybe you want to zip the file in PHP before you upload them? This requires the zip extension to be installed.

sudo pecl install zip

Here is an example script:

<?php
$zip      = new ZipArchive();
$filename = "/tmp/" . time() .".zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) {
    exit("cannot open <$filename>\n");
}
$zip->addFile('/path/to/uploaded/file');
$zip->close();

// continue uploading to s3
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文