79
60

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 5 years have passed since last update.

[個人メモ]IAMの情報をAWS CLIで確認する

Last updated at Posted at 2017-08-17

はじめに

AWS CLIでIAMを操作する場合、コマンドがいろいろあって混乱するので、個人的によく使うものを用途に応じてまとめてみました。

ユーザ関連

一覧取得

command
aws iam list-users \
--query 'Users[].UserName' 
result
[
    "user1",
    "user2",
    "user3"
]

##所属グループ取得

command
aws iam list-groups-for-user \
--user-name USERNAME \
--query 'Groups[].GroupName' 
result
[
    "group1",
    "group2",
    "group3"
]

グループ関連

一覧取得

command
aws iam list-groups \
--query 'Groups[].GroupName' 
result
[
    "group1",
    "group2",
    "group3"
]

#ポリシー関連

##管理ポリシー

###AWS管理ポリシー一覧

command
aws iam list-policies --scope AWS
result
{
    "Policies": [
        {
            "PolicyName": "AWSDirectConnectReadOnlyAccess",
            "CreateDate": "2015-02-06T18:40:08Z",
            "AttachmentCount": 0,
            "IsAttachable": true,
            "PolicyId": "ANPAI23HZ27SI6FQMGNQ2",
            "DefaultVersionId": "v1",
            "Path": "/",
            "Arn": "arn:aws:iam::aws:policy/AWSDirectConnectReadOnlyAccess",
            "UpdateDate": "2015-02-06T18:40:08Z"
        },
        {
            "PolicyName": "AmazonGlacierReadOnlyAccess",
            "CreateDate": "2015-02-06T18:40:27Z",
            "AttachmentCount": 0,
            "IsAttachable": true,
            "PolicyId": "ANPAI2D5NJKMU274MET4E",
            "DefaultVersionId": "v2",
            "Path": "/",
            "Arn": "arn:aws:iam::aws:policy/AmazonGlacierReadOnlyAccess",
            "UpdateDate": "2016-05-05T18:46:10Z"
        },

...snip...

###カスタマー管理ポリシー一覧

command
aws iam list-policies --scope Local
result
{
    "Policies": [
        {
            "PolicyName": "CUSTOMER_POLICY",
            "CreateDate": "2016-02-22T08:32:23Z",
            "AttachmentCount": 1,
            "IsAttachable": true,
            "PolicyId": "XXXXXXXXXXXX",
            "DefaultVersionId": "v1",
            "Path": "/",
            "Arn": "arn:aws:iam::XXXXXXXXXXXX:policy/CUSTOMER_POLICY",
            "UpdateDate": "2016-02-22T08:32:23Z"
        }
    ]
}

###なんらかのリソースにアタッチされている管理ポリシー

command
aws iam list-policies --only-attached
result
{
    "Policies": [
        {
            "PolicyName": "AmazonRDSFullAccess",
            "CreateDate": "2015-02-06T18:40:52Z",
            "AttachmentCount": 1,
            "IsAttachable": true,
            "PolicyId": "ANPAI3R4QMOG6Q5A4VWVG",
            "DefaultVersionId": "v2",
            "Path": "/",
            "Arn": "arn:aws:iam::aws:policy/AmazonRDSFullAccess",
            "UpdateDate": "2015-12-16T21:02:23Z"
        },
        {
            "PolicyName": "AmazonS3FullAccess",
            "CreateDate": "2015-02-06T18:40:58Z",
            "AttachmentCount": 1,
            "IsAttachable": true,
            "PolicyId": "ANPAIFIR6V6BVTRAHWINE",
            "DefaultVersionId": "v1",
            "Path": "/",
            "Arn": "arn:aws:iam::aws:policy/AmazonS3FullAccess",
            "UpdateDate": "2015-02-06T18:40:58Z"
        },
    ]
}

###ユーザにアタッチされている管理ポリシー

command
aws iam list-attached-user-policies \
--user-name USERNAME \
--query 'AttachedPolicies[].PolicyArn'
result
[
    "arn:aws:iam::aws:policy/AdministratorAccess"
]

###グループにアタッチされている管理ポリシー

command
aws iam list-attached-group-policies \
--group-name GROUPNAME \
--query 'AttachedPolicies[].PolicyArn'
result
[
    "arn:aws:iam::aws:policy/AdministratorAccess"
]

###管理ポリシードキュメント

command
aws iam get-policy-version \
--version-id v1 \  #管理ポリシーのバージョン
--policy-arn POLICYARN \
--query 'PolicyVersion.Document'
result
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "*",
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

##インラインポリシー
###ユーザにアタッチされているインラインポリシー

command
aws iam list-user-policies \
--user-name USERNAME
result
{
    "PolicyNames": [
        "INLINE_POLICY"
    ]
}

###ユーザにアタッチされているインラインポリシードキュメント

command
aws iam get-user-policy \
--user-name USERNAME \
--policy-name INLINE_POLICY \
--query 'PolicyDocument'
result
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "*",
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

###グループにアタッチされているインラインポリシー

command
aws iam list-group-policies \
--group-name GROUPNAME
result
{
    "PolicyNames": [
        "INLINE_POLICY"
    ]
}

###グループにアタッチされているインラインポリシードキュメント

command
aws iam get-group-policy \
--group-name GROUPNAME \
--policy-name INLINE_POLICY \
--query 'PolicyDocument'
result
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "*",
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
79
60
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
79
60

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?