简体   繁体   中英

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)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM