Role.addToPolicy() 只适用于新角色。

huangapple go评论55阅读模式
英文:

Role.addToPolicy() only on new Role

问题

addtoPolicy方法在通过名称(或ARN)获取现有角色时为什么不可用?fromRoleName方法应该返回一个Role对象。例如:

let testRole = Role.fromRoleName(this, "test-role", "test-role");
testRole.addToPolicy() // 方法未找到

另一方面,以下代码可行:

testRole = new Role(this, "test-role", {
  assumedBy: new ServicePrincipal('lambda.amazonaws.com')
})
testRole.addToPolicy() // 可行
英文:

Why is the addtoPolicy method not available on the Role object if I get an existing role by name (or by arn)? The fromRoleName method should return a Role object. For example:

let testRole=Role.fromRoleName(this,"test-role","test-role");
testRole.addToPolicy()//Method not found

On the other hand, this works:

testRole = new Role(this,"test-role", {
  assumedBy: new ServicePrincipal('lambda.amazonaws.com')
})
testRole.addToPolicy() //OK

答案1

得分: 1

这是因为 fromRoleName 返回一个 IRole 接口。这个接口没有 addToPolicy 方法。

英文:

This is because fromRoleName returns an IRole interface. This interface does not have a addToPolicy method.

huangapple
  • 本文由 发表于 2023年2月16日 09:13:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定