AWS CLIとは、AWSのCommand Line Interface つまりターミナルからAWSを操作するためのツール群です。
$ aws s3 ls s3://nu.mine.kino.hogebucket 2016-11-10 12:46:26 700 hoge2.py
とかやってS3をターミナルから操作することが出来ます。便利です。。
あちなみにMacでやっててOSは El Capitanです
$ sw_vers ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G1108
$ sudo easy_install pip $ sudo pip install awscli --upgrade --ignore-installed six $ sudo pip install boto3 --upgrade --ignore-installed six $ sudo aws --v $ which aws
どうもこのignoreオプションをつけないとエラーが出たっぽい、、。
クライアントにcredential情報を設定するためのコマンドを実行します。 AWS Access Key ID、AWS Secret Access Keyはマネジメントコンソールであらかじめ設定済みと仮定します。
参考 Amazon S3 再入門 – AWS IAMでアクセスしてみよう!
$ aws configure AWS Access Key ID [****************]: xxxxxxxxxxxxxx ←あらかじめマネジメントコンソールで設定済みの値。 AWS Secret Access Key [****************]: yyyyyyyyyy ←あらかじめマネジメントコンソールで設定済みの値。 Default region name [None]: ap-northeast-1 ← 東京 Default output format [None]: json $ $ ls -lrt ~/.aws/ -rw-r--r-- 1 masatomix staff 118 11 10 12:41 credentials -rw------- 1 masatomix staff 48 11 10 12:41 config $ cat ~/.aws/config [default] output = json region = ap-northeast-1 $ cat ~/.aws/credentials [default] aws_access_key_id = xxxxxxxxxxxxxx aws_secret_access_key = yyyyyyyyyy
インストール完了です。コマンドラインからAWSが操作できるようになりました。
$ aws s3 ls ← Bucketの一覧表示 2016-11-08 18:59:46 nu.mine.kino.hogebucket $ aws s3 ls s3://nu.mine.kino.hogebucket --recursive ← 指定したBucketの中身を表示 $ ls -lrt dir1 total 8 -rw-r--r-- 1 masatomix staff 13 11 12 10:31 file1.txt $ aws s3 sync dir1 s3://nu.mine.kino.hogebucket/dir2 upload: dir1/file1.txt to s3://nu.mine.kino.hogebucket/dir2/file1.txt ローカルのdir1ディレクトリと、Bucketのdir2ディレクトリを同期。 $ aws s3 ls s3://nu.mine.kino.hogebucket/ --recursive 2016-11-12 10:33:26 13 dir2/file1.txt
この記事は
現在のアクセス:2895