amazon-web-servicesaws-cli

AWS CLI not listing policies attached to role


I followed the instructions here to set up and remove a python lambda function (and associated AWS resources).

When I try to clean up the function, role-policy and role, the instructions failed because the CLI does not manage to find the attached role policies. In particular, if I run:

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

... I get an output of:

{
    "PolicyNames": []
}

But when I look up the same role in the AWS console, I can see the policy is there.

enter image description here

So what is going on here? Is this an AWS bug (CLI version aws-cli/2.1.33 Python/3.9.2 Darwin/20.4.0 source/x86_64), or am I muddled up here somehow?


Solution

  • As I can see from the image, it's a managed policy and unfortunately list-role-policies only lists the names of the inline policies that are embedded in the specified IAM role.

    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

    Use this for example:

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