0

我正在尝试运行复制命令将一些数据从账户 A 中的 s3 存储桶复制到账户 B 中的 redshift。我创建了两个不同的 IAM 角色,一个用于账户 A 中的 s3,一个用于账户 B 中的 redshift。我已附加将 IAM 角色添加到 redshift 集群,并为 s3 角色添加了相同的信任实体。

这是 s3 IAM 角色的信任策略:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<redshiftAccountId>:root"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

以下是 redshift IAM 角色的内联策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "rds-db:connect",
                "redshift:GetClusterCredentials",
                "redshift:JoinGroup",
                "redshift:CreateClusterUser"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Resource": "arn:aws:iam::<s3AccountId>:role/<s3Role>"
        }
    ]
}

每次我运行复制命令时,我都会收到以下错误: ERROR: User arn:aws:redshift:<redshiftAccountRegion>:<redshiftAccountId>:dbuser:<redshift-cluster>/<database-user> is not authorized to assume IAM Role arn:aws:iam::<redshiftAccountid>:role/<redshift-role>,arn:aws:iam::<s3AccountId>:role/<s3Role>

4

1 回答 1

0

我解决了这个问题。我在我的 s3 存储桶中添加了存储桶策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowS3",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<redshiftAccountId>:root"
            },
            "Action": [
                "s3:PutObject",
                "s3:ListBucket",
                "s3:GetObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::<bucket-name>/*",
                "arn:aws:s3:::<bucket-name>"
            ]
        }
}

我还为我的 redshift IAM 角色附加了一项新政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowS3",
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::<bucket-name>/*",
                "arn:aws:s3:::<bucket-name>"
            ]
        }
    ]
}

下面是我的红移查询:

COPY users
FROM 's3://<bucket-name>/<file-name>'
iam_role 'arn:aws:iam::<redshiftAccountId>:role/<redshiftRole>'
DELIMITER '|'
REGION '<aws-region>'

参考以下: https ://www.pmg.com/blog/cross-account-redshift-unload-copy/

于 2021-03-17T09:55:19.810 回答