从另一个帐户 S3 存储桶复制到 Redshift

Copy to Redshift from another accounts S3 bucket

是否可以从一个 AWS 帐户 S3 存储桶复制到另一个 AWS 帐户 Redshift 集群?我尝试这样做的方法是使用 SQL Workbench 登录到我的 AWS 帐户 (Account1) 并使用 (Account2) 的 IAM 用户像这样复制文件:

copy my_table (town,name,number)
from 's3://other-s3-account-bucket/fileToCopy.tsv'
credentials 'aws_access_key_id=<other_accounts_aws_access_key_id>;aws_secret_access_key=<other_accounts_aws_secret_access_key>'
delimiter '\t';

我仔细检查后知道另一个帐户的用户有s3权限。我是否共享 IAM 用户或设置不同的权限才能执行此操作?

您将需要"pull"来自其他帐户的 S3 存储桶的数据。

  1. AWS 账户 A 有一个名为 source-bucket-account-a 的 S3 存储桶。
  2. AWS 账户 B 有一个名为 TargetCluster 的 Redshift 集群。
  3. 在存储桶 source-bucket-account-a 上,添加允许 AWS 账户 B 读取文件的存储桶策略。

示例策略:

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Sid": "DelegateS3Access",
         "Effect": "Allow",
         "Principal": {
            "AWS": "arn:aws:iam::<account-b-number>:root"
         },
         "Action": [
            "s3:Get*",
            "s3:List*"
         ],
         "Resource": [
            "arn:aws:s3:::source-bucket-account-a",
            "arn:aws:s3:::source-bucket-account-a/*"
         ]
      }
   ]
}

它与以下内容非常相似: http://docs.aws.amazon.com/AmazonS3/latest/dev/example-walkthroughs-managing-access-example2.html

或以下内容: http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_policy-examples.html

  1. 存储桶策略到位后,您可以使用 AWS 账户 B 的凭据来 运行 copy 命令,因为它拥有 Redshift 集群。在 copy 命令中,您通过名称 source-bucket-account-a.
  2. 指定存储桶

存储桶策略已授予对 AWS 账户 B 的读取权限,因此它可以 "pull" 将数据导入 Redshift。