Charlene
Charlene

Reputation: 337

AWS CLI list-policies to find a policy with a specific name

I am trying to locate a policy in AWS with a specific name via the aws cli. I tried get-policy first but it threw and error. Now I am trying list-policies and putting in a prefix. According to the documentation if I start and end the string with a forward slash it should search but it hasn't been working. I get an empty array back... any ideas?

aws iam list-policies --scope Local --path-prefix /policyname.xyz/

Upvotes: 2

Views: 4496

Answers (2)

unacorn
unacorn

Reputation: 1032

You can use the --query flag. For example, for exact search,

aws iam list-policies --query 'Policies[?PolicyName==`policyname.xyz`]'

If you want more flexible search, you can refer to https://jmespath.org/specification.html for some functions for example 'to start with policynamexxx'

aws iam list-policies --query 'Policies[?starts_with(PolicyName,`policynamexxx`)]'

Upvotes: 3

OARP
OARP

Reputation: 4077

It is an issue with AWS CLI V2. The issue is still open on the github repository of the AWS SDK since 11 Jan. You can check the detail here: https://github.com/aws/aws-sdk/issues/36

Complete list of issues: https://github.com/aws/aws-sdk/issues

Upvotes: 2

Related Questions