21
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

やりたかったこと

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分ぐらいハマってしまったのでメモ。

参考

名前付きプロファイル

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?