简体   繁体   English

使用 lambda 从外部 s3 存储桶下载文件

[英]Download files from external s3 bucket using lambda

I want to use lambda to download backup files from external s3 account.我想使用 lambda 从外部 s3 帐户下载备份文件。 I have got Access Key ID, Secret Access Key, Bucket Name and Region Name.我有访问密钥 ID、秘密访问密钥、存储桶名称和区域名称。 And then synchronize it with my private s3 bucket.然后将它与我的私人 s3 存储桶同步。 Is it possible?是否可以? And how?如何?

It appears your requirement is:看来你的要求是:

  • Take data stored in Bucket-A in Account-AAccount-A获取存储在Bucket-A中的数据
  • Copy it to Bucket-B in Account-B将其复制到Account-B Bucket-B Account-B

The simplest way to do this is to use the CopyObject() command because it can directly transfer data between buckets (even between regions!) without needing to download & upload.最简单的方法是使用CopyObject()命令,因为它可以直接在存储桶之间(甚至在区域之间!)传输数据,而无需下载和上传。

To do this, you will require one set of credentials that have Read permissions on Bucket-A and write permissions on Bucket-B .为此,您将需要一组对Bucket-A具有读取权限并在Bucket-B上具有写入权限的凭据。 This can be either:这可以是:

  • An IAM User-A in Account-A that can read Bucket-A and a Bucket Policy on Bucket-B that permits User-A to write to Bucket-B , OR Account-A User-A中的 IAM User-A可以读取Bucket-A和存储Bucket-B上的Bucket-B桶策略,允许User-A写入Bucket-B
  • An IAM User-B in Account-B that can write to Bucket-B and a Bucket Policy on Bucket-A that permits Read access for User-B Account-B User-B中的 IAM User-B可以写入Bucket-B ,存储Bucket-A上的Bucket-A桶策略允许User-B进行读取访问

Using the Bucket Policy means that one set of credentials can use the CopyObject() command to both Read & Write.使用存储桶策略意味着一组凭据可以使用CopyObject()命令进行读取和写入。 Without that, you'd need to use one set of credentials to download an object and another set of credentials to upload the object.否则,您需要使用一组凭据下载对象,使用另一组凭据上传对象。 That's not a smart way to do it.这不是一个聪明的方法。

See: Provide Cross-Account Access to Objects In S3 Buckets请参阅: 提供对 S3 存储桶中对象的跨账户访问

The easiest way to run the copy command is to use the AWS Command-Line Interface (CLI) aws s3 cp or aws s3 sync commands.运行复制命令的最简单方法是使用AWS 命令​​行界面 (CLI) aws s3 cpaws s3 sync命令。 In your case, if you wish to synchronize the contents of files, you would use aws s3 sync .在您的情况下,如果您希望同步文件的内容,您可以使用aws s3 sync

A final option is to use Cross-Region Replication - Amazon Simple Storage Service , but that only works on buckets in different regions.最后一个选项是使用跨区域复制 - Amazon Simple Storage Service ,但这仅适用于不同区域的存储桶。 The buckets can belong to different AWS accounts.存储桶可以属于不同的 AWS 账户。

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

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