【发布时间】:2020-03-24 14:09:15
【问题描述】:
我正在尝试在 cloudformation (yaml) 中定义角色和用户之间的信任关系策略文档。
为了在角色的AssumeRolePolicyDocument 中指定用户的 ARN,我想从实际的 cloudformation 资源中引用 ARN,而不必构造 ARN 字符串。
但是,它不起作用。当我使用 !Ref rUser 时,在创建 cloudformation 堆栈时出现“策略中的主体无效”的错误。
当我只是将 ARN 字符串粘贴为值时,它可以工作。是因为!Ref rUser 返回一个用户对象类型并且不计算为字符串吗?如果是这样,我如何从资源中引用 ARN?
代码:
rUser:
Type: "AWS::IAM::User"
Properties:
UserName: "my_user"
rRole:
DependsOn: rRole
Type: "AWS::IAM::Role"
Properties:
RoleName: "my_role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
AWS:
# this does not work, gives error "Invalid Principal in policy"
- !Ref rUser
# this does work (just hard coding the ARN string):
# - "arn:aws:iam::111111111111:user/my_user"
Action:
- "sts:AssumeRole"
【问题讨论】:
标签: amazon-web-services yaml amazon-cloudformation amazon-iam