🔑

AWS CLIの設定

2024/10/27に公開1

👤対象者

  • AWS使っている人
  • AWS CLIの設定方法忘れた人

記事の内容

AWS CLIの設定を以前したことあるのだけど、新しいPCを購入したときにまた設定するのですがやり方忘れたのでメモしようと思った。AWSのIAMの知識がある人前提で記事を書いているので設定のやり方わからない方がいたら公式やUdemyで勉強してください。
https://aws.amazon.com/jp/iam/

Todo

  1. IAMユーザーを作成する。アクセスキーとシークレットアクセスキーを作成する
  2. 公式サイトからAWS CLIをダウンロードする。csvファイルが作成されるのでダウンロードしておく。なくさないように!
  3. ダウンロードしたツールをインストールする
  4. aws configureの設定をする

curlでもインストールできるようですが私はブラウザで、macOS pkg ファイルをダウンロードしました。
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/getting-started-install.html

https://youtu.be/HhwTOLX_yFc

🏠homeディレクトリに.awsディレクトリを作成する。

mkdir .aws
# .awsディレクトリに移動する
cd .aws

aws configureファイルを設定する。
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-configure-files.html#cli-configure-files-settings

AWS CLIが動作するか確認する。

jboy422@Jboy422 .aws % aws --version
aws-cli/2.18.15 Python/3.12.6 Darwin/23.3.0 exe/x86_64

.awsディレクトリ内で実行する。

aws configure

IAMユーザー作成時に入手したアクセスキーとシークレットアクセスキーを設定する。リージョンは東京リージョンのap-northeast-1でDefault output format [None]: はjsonにする。

jboy422@Jboy422 .aws % aws configure
AWS Access Key ID [None]: AK*****************************
AWS Secret Access Key [None]: 01nY***************************
Default region name [None]: ap-northeast-1
Default output format [None]: json

感想

久しぶりに環境構築してみました。やり方を毎回忘れるので手順をメモしたらスクリーショットはとっておくと便利です。手順は技術ブログやNotion、Obsidianにメモしておくと良いでしょう。

Discussion

JboyHashimotoJboyHashimoto

Wrapのターミナルだと失敗するみたいです?
普通のターミナルだとできた。

https://www.warp.dev/

The aws configure command is an interactive command that helps you set up your AWS credentials and configuration. It will prompt you for:

  1. AWS Access Key ID
  2. AWS Secret Access Key
  3. Default region name (recommended: ap-northeast-1 for Asia Pacific (Tokyo))
  4. Default output format (recommended: json)

For security best practices:

  • Never share or commit your AWS credentials
  • Consider using AWS SSO or IAM roles for production environments
  • Regularly rotate your access keys
  • Use different profiles for different AWS accounts

Since you're in the ~/.aws directory, the credentials will be stored in:

  • Credentials: ./credentials
  • Configuration: ./config

If you want to configure credentials for a specific profile, you can use:
aws configure --profile <profile_name>