3
4

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.

MacPortsでaws-cliをインストールする

Posted at

いつの間にか正式リリースされていたのでまとめておきます

前提

  • macportsがインストールされていること
  • Pythonがインストールされていること(Python versions 2.6.x 以上 3.3.x以下)
  • git-coreをインストールしていれば、Pythonが入っているはず

インストール

インストールされているPythonを確認する
$ sudo port installed | grep py
  git-core @1.8.4_0+credential_osxkeychain+doc+pcre+python27 (active)
  python27 @2.7.5_1 (active)
  ・・・
pythonのバージョンに対応するpipをmacportsでインストール(setuptoolsも依存しているので入る)
$ sudo port install py27-pip
パッケージ管理システムからpipモジュールをインストール
$ sudo easy_install pip
aws-cliをインストール
$ sudo pip install awscli 

設定

サブコマンドのオートコンプリートを有効にする
 $ complete -C aws_completer aws
awsの設定を確認する
  1. AWS Management Consoleを開く
  2. Security Credentialsなどで、Access Key ID と Secret Access Keyを確認
  3. EC2 DashboardのAvailability Zone Statusなどからリージョン名を確認(例:ap-northeast-1aの末尾を取った値、ap-northeast-1がリージョン名)
いずれかの方法を行う
  • Environment variables
  • Config file
  • IAM Role
Environment variablesの場合
$ export AWS_ACCESS_KEY_ID=<access_key>
$ export AWS_SECRET_ACCESS_KEY=<secret_key>
Config fileの場合

この方法だとporfile指定でそれぞれの環境用に記述できる

[default]
aws_access_key_id=<default access key>
aws_secret_access_key=<default secret key>
# Optional, to define default region for this profile.
region=<リージョン名>

[profile testing]
aws_access_key_id=<testing access key>
aws_secret_access_key=<testing secret key>
region=<リージョン名>
$ export AWS_CONFIG_FILE=/path/to/config_file
IAM Roleの場合

EC2インスタンス上でaws-cliをインストールして利用する場合で、且つIAMを利用している場合は、自動的にAccess Key ID と Secret Access Keyを使用してくれるようです。

試しに実行

Environment variables, IAM Roleの場合
$ aws ec2 describe-instance-status --region <リージョン名>
Config fileの場合
  • profile testingを利用する場合
$ aws ec2 describe-instance-status --profile=testing

公式サイト

3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?