我正在尝试使用资源策略设置API网关端点,该策略允许访问我帐户中的特定IAM角色。 IAM角色是跨帐户,使用信任策略进行设置,该信任策略允许AssumeRole从另一个帐户到特定的IAM用户主体。
在API网关资源策略中,当我将AWS主体设置为角色ARN:arn:aws:iam::********:role/myRole
时,调用API时出现以下403错误:
User: arn:aws:sts::********:assumed-role/myRole/mySession is not authorized to perform: execute-api:Invoke on resource: arn:aws:execute-api:us-west-2:********:********/test/POST/echo
但是,如果我将AWS主体更改为临时STS用户ARN:arn:aws:sts::********:assumed-role/myRole/mySession
,则可以成功调用API。
这是行不通的资源政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::********:role/myRole"
},
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:us-west-2:********:********/*"
}
]
}
这是有效的资源策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:sts::********:assumed-role/myRole/mySession"
},
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:us-west-2:********:********/*"
}
]
}
IAM角色可以用作API网关资源策略的AWS主体吗?