LoginSignup
5
9

More than 5 years have passed since last update.

Mac OS X への AWS CLI のセットアップ

Last updated at Posted at 2015-05-04

AWS Command Line Interface (CLI) を Mac OS X にセットアップした時のメモ。Linuxでも同じです。

Install

# Install
$ sudo pip install awscli

# Confirm installation
$ aws --version
aws-cli/1.7.19 Python/2.7.5 Linux/3.10.0-123.20.1.el7.x86_64

Config

# Configure
$ aws configure
AWS Access Key ID [None]: <Access Key>
AWS Secret Access Key [None]: <Secret Access Key>
Default region name [None]: ap-northeast-1      # "ap-northeast-1 for Japan region"
Default output format [None]: json              # "text" or "table" or "json"

設定は .asw/{config|credentials} に保存される

$ ls -l ~/.aws/
total 16
-rw-------  1 user01  staff   49 Feb  6 22:23 config
-rw-------  1 user01  staff  116 Apr  5 17:23 credentials

$ cat ~/.aws/config
[default]
output = json
region = ap-northeast-1

$ cat .aws/credentials
[default]
aws_access_key_id = AKIAXXXXXXXXXXXXXXXXX
aws_secret_access_key = DXhqXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

ひとまずこんな感じで出力されればOK

$ aws ec2 describe-vpcs --output json
{
    "Vpcs": [
        {
            "VpcId": "vpc-9f1fc8fa",
            "InstanceTenancy": "default",
            "State": "available",
            "DhcpOptionsId": "dopt-c5a7bca7",
            "CidrBlock": "172.31.0.0/16",
            "IsDefault": true
        },
        {
            "VpcId": "vpc-2ce93449",
            "InstanceTenancy": "default",
            "Tags": [
                {
                    "Value": "aws_book_vpc",
                    "Key": "Name"
                }
            ],
            "State": "available",
            "DhcpOptionsId": "dopt-c5a7bca7",
            "CidrBlock": "10.0.0.0/16",
            "IsDefault": false
        }
    ]
}

Upgrade

$ sudo pip install -U awscli

コマンド補完の設定

コマンド補完には、aws_completer というプログラムが使える。

Mac OS Xの場合 /usr/local/bin/aws_completer

$ type aws_completer
aws_completer is /usr/local/bin/aws_completer

completeコマンドのoptionにパスを、argsにawsを指定して.bash_profileに追記。

$ echo "complete -C '/usr/local/bin/aws_completer' aws" >> $HOME/.bash_profile 

リンク

5
9
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
5
9