Help us understand the problem. What is going on with this article?

aws cli が profileを読み取ってくれなくてハマった

More than 1 year has passed since last update.

やりたかったこと

aws cliでプロファイルを複数指定したかった。
仕事用のプロファイルをdefaultにして、プライベート環境をprivateというプロファイルにしようとしたらregionを読み込んでくれなくて困った。

最初にやったこと

以下のように~/.aws/credentialsと~/.aws/configを指定した。

~/.aws/credentials
[default]
aws_access_key_id=AKIAXXXXXXXXXXXXXXXXXX
aws_secret_access_key=Q+SaNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

[private]
aws_access_key_id=AKIAYYYYYYYYYYYYYYYYYY
aws_secret_access_key=nxO0CYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
~/.aws/config
[default]
region=ap-northeast-1

[private]
region=ap-northeast-1

試してみる

## dynamoにsample-table-1というテーブルを作る

$ aws --profile=private dynamodb create-table \
        --table-name sample-table-1 \
        --attribute-definitions AttributeName=LockID,AttributeType=S \
        --key-schema AttributeName=LockID,KeyType=HASH \
        --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
You must specify a region. You can also configure your region by running "aws configure".

aws configureを実行しろと怒られる。

正しくは

~/.aws/config
[default]
region=ap-northeast-1
[profile private]      ## ← "profile private"と指定しなければいけない
region=ap-northeast-1

もう一度試してみる

$ aws --profile=private dynamodb create-table \
        --table-name sample-table-1 \
        --attribute-definitions AttributeName=LockID,AttributeType=S \
        --key-schema AttributeName=LockID,KeyType=HASH \
        --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
TABLEDESCRIPTION    1526629948.28   0   arn:aws:dynamodb:ap-northeast-1:929250186533:table/sample-table-1   814a448b-4fd8-40cb-8d02-4be323a17927    sample-table-1  0   CREATING
ATTRIBUTEDEFINITIONS    LockID  S
KEYSCHEMA   LockID  HASH
PROVISIONEDTHROUGHPUT   0   1   1

作れた。どうでもいいことに10分ぐらいハマってしまったのでメモ。

参考

名前付きプロファイル

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away