Redshift 数据库用户无权承担 IAM 角色

Redshift database user is not authorized to assume IAM Role

我正在尝试 运行 一个复制命令,将一些数据从账户 A 中的 s3 存储桶复制到账户 B 中的红移。我创建了两个不同的 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>

我解决了这个问题。 我已将存储桶策略添加到我的 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/