LoginSignup
0

More than 3 years have passed since last update.

MacでAWS CLIをインストールして、コマンドでS3にバケットを作る

Posted at

はじめに

下記の公式ページを参考にAWS CLIをインストールします。

macOS に AWS CLIをインストールする

その後、コマンド操作でS3にバケットを作成するまでを行います。

AWS CLIとは

AWS CLI(AWS Command Line Interface)はコマンドを使用して、マネジメントコンソールと同等の操作をすることができるツールです。

慣れるとこっちの方が早そうです。

インストールしたMacOS

macOS High Sierra
バージョン 10.13.6

前提条件

Python 2 バージョン 2.6.5+ または Python 3 バージョン 3.3+

Python2の場合は2.6.5以上でPython3の場合は3.3以上が条件のようです。
下記のコマンドでPythonのバージョンを確認できます。

$ python --version
Python 2.7.10

インストールできているみたいなので、前提条件はクリアです。

AWS CLIをインストール

インストーラをダウンロード

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

パッケージを解凍

unzip awscli-bundle.zip

インストールプログラムを実行
※パスワード入力あり

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

下記のコマンドでバージョンを確認できればインストール完了!

aws --version

例えばs3を操作したいときのヘルプを見ることもできます。

aws s3 help

AWS側の設定

IAMユーザーページの認証情報タブからアクセスキーを作成します。
作成したら下記のコマンドを入力し、さらに入力が求められるのでリストの順番で設定します。

aws configure
  • アクセスキーID
  • シークレットアクセスキー
  • デフォルトリージョン名(東京リージョン:ap-northeast-2)
  • アウトプットフォーマット(例:json)

S3にバケットを作成

mbコマンドでS3にバケットを作成できます。
が、実行してみるとエラーになりました。

$ aws s3 mb s3://testbacket

make_bucket failed: s3://testbacket An error occurred (BucketAlreadyExists) when calling the CreateBucket operation: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.

S3のバケット名は全世界で一意のものでないとだめらしいです。
他の人と被っちゃダメなんですね。 testbacket なんていかにも被りそう。

testbackettest-20190718 命名センスないですが、とりあえずこれで作成できました。

$ aws s3 mb s3://testbackettest-20190718
make_bucket: testbackettest-20190718

おわりに

下記のページで最新のCLIコマンドリファレンスを確認できます。
コマンドで何か操作したくなったらこちらで確認するように心がけるといいと思います。
こういうリファレンスを読める系のエンジニアになりたい。。。

AWS CLI Command Reference

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