LoginSignup
83
67

More than 5 years have passed since last update.

brewでAWS CLIのインストール

Last updated at Posted at 2018-01-25

MacにHomebrewでAWSのCLIをインストールする。

brewのアップデート

$ brew update

$ brew search aws
==> Searching local taps...
aws-apigateway-importer    aws-elasticbeanstalk       aws-sns-cli
aws-as                     aws-keychain               awscli
aws-cfn-tools              aws-mon                    awslogs
aws-cloudsearch            aws-sdk-cpp                kube-aws
aws-elasticache            aws-shell                  yaws

CLIのインストール

$ brew install awscli

確認
$ aws --version
aws-cli/1.14.30 Python/3.6.4 Darwin/16.7.0 botocore/1.8.34

環境変数の設定

$ vi ~/.bash_profile

以下を追記
export PATH=~/.local/bin:$PATH

アクセスキーの設定

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE  (自分の)
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY  (自分の)
Default region name [None]: ap-northeast-1  (東京リージョン)
Default output format [None]: json  (空だとJSON)

ロールの切り替え

プロファイルの設定

設定ファイル(~/.aws/config)にロールの情報を記述します。

[profile プロファイル名]
output = json
region = ap-northeast-1
role_arn = arn:aws:iam::操作対象のAWSアカウントID:role/ロール名
source_profile = default
$ vi ~/.aws/config

[profile hoge]
role_arn = arn:aws:iam::069581120308:role/role-name
region = ap-northeast-1
source_profile = default

動作確認

$ aws ec2 describe-instances --profile hoge
実行中のインスタンスが表示される

デフォルトプロファイルの設定

何度もプロファイルを指定するのが面倒であれば、

$ export AWS_PROFILE=hoge

とすれば、シェルセッションの終了時までプロファイルが固定される。

83
67
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
83
67