LoginSignup
0
0

More than 1 year has passed since last update.

AWS CLI プロファイル & IAM 関連コマンド集

Last updated at Posted at 2021-10-11

目的

最近、異なる AWS アカウントを切り替えて利用することが増えたため、AWS CLI のプロファイルおよび AIM 関連のよく使うコマンドをまとめておきます。

デフォルトのプロファイルを新規登録 or 更新

コマンド: aws configure

$ aws configure
AWS Access Key ID [None]: XXXXXXXXXX
AWS Secret Access Key [None]: XXXXXXXXXX
Default region name [None]: ap-northeast-1
Default output format [None]: json

名前付きプロファイルを新規登録

コマンド: aws configure --profile Name

$ aws configure --profile Name
AWS Access Key ID [None]: XXXXXXXXXX
AWS Secret Access Key [None]: XXXXXXXXXX
Default region name [None]: ap-northeast-1
Default output format [None]: json

現在使用中のプロファイルを表示

コマンド: aws configure list

$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                     Name           manual    --profile
access_key     ****************XXXX shared-credentials-file
secret_key     ****************XXXX shared-credentials-file
    region           ap-northeast-1      config-file    ~/.aws/config

名前付きプロファイルを指定して表示

コマンド: aws configure list --profile Name

$ aws configure list --profile Name
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                     Name           manual    --profile
access_key     ****************XXXX shared-credentials-file
secret_key     ****************XXXX shared-credentials-file
    region           ap-northeast-1      config-file    ~/.aws/config

使用するプロファイルを変更

# Mac or Linux
$ export AWS_PROFILE=Name

# Windows
[win] set AWS_PROFILE=Name

AWS_PROFILE に何も指定しなかった場合、Mac or Linux と Windows で挙動が異なるようです。

# Mac or Linux
$ export AWS_PROFILE=
$ aws configure list

The config profile () could not be found

# Windows
[win] set AWS_PROFILE=
[win] aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************XXXX shared-credentials-file
secret_key     ****************XXXX shared-credentials-file
    region           ap-northeast-1      config-file    ~/.aws/config

デフォルトで使用するプロファイルを指定

# Mac & Linux
$ export AWS_DEFAULT_PROFILE=Name

# Windows
[win] set AWS_DEFAULT_PROFILE=Name

AWS_PROFILE が設定されている場合、AWS_DEFAULT_PROFILE よりも優先されます。

$ echo $AWS_PROFILE
user1

$ echo $AWS_DEFAULT_PROFILE
user2

$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                    user1           manual    --profile
access_key     ****************XXXX shared-credentials-file
secret_key     ****************XXXX shared-credentials-file
    region           ap-northeast-1      config-file    ~/.aws/config

すべてのプロファイルを一覧表示

コマンド: aws configure list-profiles

$ aws configure list-profiles
default
test1
test2

IAM ユーザーまたはロールの詳細を表示

コマンド: aws sts get-caller-identity

# 現在使用中の IAM ユーザーまたはロールの詳細を表示
$ aws sts get-caller-identity
{
    "UserId": "XXXXXXXXXX",
    "Account": "XXXXXXXXXX",
    "Arn": "arn:aws:iam::XXXXXXXXXX"
}

# 名前付きプロファイルを指定して IAM ユーザーまたはロールの詳細を表示
$ aws sts get-caller-identity --profile user1
{
    "UserId": "XXXXXXXXXX",
    "Account": "XXXXXXXXXX",
    "Arn": "arn:aws:iam::XXXXXXXXXX"
}

アカウントのすべての IAM ユーザーを一覧表示

コマンド: aws iam list-users

$ aws iam list-users
{
    "Users": [
        {
            "Path": "/",
            "UserName": "Name",
            "UserId": "XXXXXXXXXX",
            "Arn": "arn:aws:iam::XXXXXXXXXX",
            "CreateDate": "Date",
            "PasswordLastUsed": "Date"
        }
    ]
}

アカウントのすべてのユーザーグループを一覧表示

コマンド: aws iam list-groups

$ aws iam list-groups
{
    "Groups": [
        {
            "Path": "/",
            "GroupName": "GroupName",
            "GroupId": "XXXXXXXXXX",
            "Arn": "arn:aws:iam::XXXXXXXXXX",
            "CreateDate": "Date"
        }
    ]
}

参考サイト

0
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
0
0