amazon-web-services - Redshift 数据库用户无权担任 IAM 角色
问题描述
我正在尝试运行复制命令将一些数据从账户 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>
解决方案
我解决了这个问题。我在我的 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/
推荐阅读
- javascript - #JavaScript:在小写输入后在函数中切换输入
- python - Python:字符串用 A 或 B 分割
- apache-spark - 并行提交多个作业时 spark-submit 失败
- redux - 使用 React / Redux 在特定情况下检索过滤后的数组长度
- reactjs - 多个导航栏 REACTJS
- python - 使用 Haarcascade 检测到的人脸,如何在不同颜色的相同人脸上绘制边界框
- python - 在 C++ 中估计嵌入式 python 脚本的进度
- javascript - 图像不在画布内旋转
- sql - 如何在分区级别查看分区表的 I/O 统计信息
- javascript - 我试图在单击按钮时禁用/启用下拉菜单