AWS CLI 未列出附加到角色的策略

AWS CLI not listing policies attached to role

我按照说明 here 设置和删除了 python lambda 函数(以及关联的 AWS 资源)。

当我尝试清理函数、角色策略和角色时,指令失败了,因为 CLI 无法找到附加的角色策略。特别是,如果我 运行:

aws iam list-role-policies --role-name myrolename

...我得到以下输出:

{
    "PolicyNames": []
}

但是当我在 AWS 控制台中查找相同的角色时,I can see the policy is there.

那么这是怎么回事?这是一个 AWS 错误(CLI 版本 aws-cli/2.1.33 Python/3.9.2 Darwin/20.4.0 source/x86_64),还是我搞错了?

正如我从图像中看到的那样,它是一个托管策略,不幸的是 list-role-policies 仅列出嵌入在指定 IAM 角色中的内联策略的名称。

Doc says

An IAM role can also have managed policies attached to it. To list the managed policies that are attached to a role, use ListAttachedRolePolicies

以这个为例

aws iam list-attached-role-policies --role-name SecurityAuditRole