【发布时间】:2020-02-25 04:52:50
【问题描述】:
问题
我有一个 IAM 用户和一个 IAM 角色。我正在尝试将 IAM 用户配置为有权使用 STS 代入 IAM 角色。我不确定为什么会收到“拒绝访问”错误。
详情
IAM 角色:arn:aws:iam::123456789:role/athena_access
IAM 用户:arn:aws:iam::123456789:user/athena-external-user
允许代入角色的 IAM 用户策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "StsAssumeRole",
"Effect": "Allow",
"Action": "sts:*",
"Resource": "arn:aws:iam::123456789:role/athena_access"
}
]
}
代码:
import boto3
os.environ['AWS_ACCESS_KEY_ID'] = '...'
os.environ['AWS_SECRET_ACCESS_KEY'] = '...'
client = boto3.client('sts')
role_to_assume_arn='arn:aws:iam::123456789:role/athena_access'
role_session_name='test_session'
response=client.assume_role(
RoleArn=role_to_assume_arn,
RoleSessionName=role_session_name
)
错误:
botocore.exceptions.ClientError:调用 AssumeRole 操作时发生错误 (AccessDenied):用户:arn:aws:iam::123456789:user/athena-external-user 无权执行:sts:AssumeRole on resource : arn:aws:iam::123456789:role/athena_access
【问题讨论】:
标签: python amazon-web-services boto3 amazon-iam