英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论