1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWSのManagedPolicyを列挙する方法

Last updated at Posted at 2022-03-03

CDKとかCloudFormation使うときにたまに使いますが、いちいち調べに行くのも面倒なので、調べ方+現時点におけるManagedPolicyのリストを載せて起きます。

リストアップするコマンド

aws iam list-policies --only-attached |\
jq -r '.Policies[] | 
select(.Arn | startswith("arn:aws:iam::aws:policy") ) | 
.PolicyName'

jqでPolicyNameのみとりだしてるので、全情報ほしければ

aws iam list-policies --only-attached |\
jq -r '.Policies[] | 
select(.Arn | startswith("arn:aws:iam::aws:policy") )'

特定の名前のものだけフィルターしたければ

aws iam list-policies --only-attached |\
jq -r '.Policies[] | 
select(.Arn | startswith("arn:aws:iam::aws:policy")) | 
select(.PolicyName | contains("S3"))'

PolicyNameとArnのみ残したJson化

aws iam list-policies --only-attached |\
jq -r '[
  .Policies[] |
  select(.Arn | startswith("arn:aws:iam::aws:policy")) |
  { PolicyName: .PolicyName, Arn: .Arn}
]' \
> policies.json 

現時点のManagedPolicyの一覧

2022/3/3時点のManagedPolicy

補足

ManagedPolicyのNameを指定するときに、ARNのpolicy/の後が、arn:aws:iam::aws:policy/aws-service-role/XXXarn:aws:iam::aws:policy/service-role/YYY
となっている場合は、aws-service-role/XXXservice-role/YYYと指定する必要があります。名前だけを渡すとそんなManagedPolicy存在しないと怒られるので、AWS Consoleとかからコピペって来た場合は、ARNの前部分を確認してみてください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?