aws s3 putObject 与同步

aws s3 putObject vs sync

我需要将一个大文件上传到 aws s3 存储桶。我的代码每 10 分钟从源目录中删除旧文件并生成一个新文件。文件大小约为 500 MB。现在我使用 s3.putObject() 方法在创建后上传每个文件。我还听说过 aws s3 同步。它与 aws-cli 一起提供。它用于将文件上传到 s3 存储桶。

我使用 aws-sdk node.js 进行 s3 上传。 node.js 的 aws-sdk 不包含 s3-sync 方法。 s3-sync 是否优于 s3.putObject() 方法?我需要更快的上传速度。

总是有很多方法可以做,所以要将文件上传到 S3 存储桶中,您可以:

  • 使用 aws CLI 和 运行 aws s3 cp ...
  • 使用 aws CLI 和 运行 aws s3api put-object ...
  • 使用 aws SDK(您选择的语言)

您也可以使用 sync 方法,但对于单个文件,无需同步整个目录,通常在寻求更好的性能时最好启动多个 cp 实例以受益来自多线程与同步单线程。

基本上所有这些方法都是 aws S3 API 调用的包装器。来自 amazon doc

Making REST API calls directly from your code can be cumbersome. It requires you to write the necessary code to calculate a valid signature to authenticate your requests. We recommend the following alternatives instead:

  • Use the AWS SDKs to send your requests (see Sample Code and Libraries). With this option, you don't need to write code to calculate a signature for request authentication because the SDK clients authenticate your requests by using access keys that you provide. Unless you have a good reason not to, you should always use the AWS SDKs.
  • Use the AWS CLI to make Amazon S3 API calls. For information about setting up the AWS CLI and example Amazon S3 commands see the following topics: Set Up the AWS CLI in the Amazon Simple Storage Service Developer Guide. Using Amazon S3 with the AWS Command Line Interface in the AWS Command Line Interface User Guide.

所以亚马逊会推荐使用SDK。归根结底,我认为这真的取决于您最喜欢什么以及如何将这段代码集成到程序的其余部分中。对于一次性行动,我总是去 CLI。

虽然就性能而言,使用其中一个不会有什么不同,因为它们只是 AWS API 调用的包装器。对于传输优化,您应该查看 aws s3 transfer acceleration 并查看是否可以启用它