pkaramol
pkaramol

Reputation: 19402

aws cli fails to return a role policy

I am copying the name of a policy a created (and attached to a role) and running the following command:

▶ aws iam get-role-policy --role-name MyRole  --policy-name MyPolicy

however I am getting:

An error occurred (NoSuchEntity) when calling the GetRolePolicy operation: The role policy with name MyPolicy cannot be found.

The policy is right there, I am copying the name from the AWS console.

What is the issue here?

I have also tried the following, that does list the policy

$ aws iam list-attached-role-policies --role-name MyRole

{
    "AttachedPolicies": [
        {
            "PolicyName": "MyPolicy",
            "PolicyArn": "arn:aws:iam::123456789:policy/MyPolicy"
        }
    ]
}
(END)

Upvotes: 1

Views: 1410

Answers (1)

alex
alex

Reputation: 11400

list-attached-role-policies lists all managed policies attached to a role and get-role-policy retrieves an inline policy. In order to retrieve a managed policy you'll want to use get-policy, get the policy version from there and retrieve it using get-policy-version.

Upvotes: 2

Related Questions