IAMへCloudFormation実行ユーザーを作成する
AWSコンソールへログインし「サービス」→「セキュリティ、アイデンティティ、コンプライアンス」→「
IAM」を選択する「個々のIAM ユーザーの作成」→「ユーザーの管理」を選択する
「ユーザーを追加」を選択する
「ユーザー名」へユーザー名を入力、「アクセスの種類」で「プログラムによるアクセス」へチェックを入れ「次のステップ: アクセス権限」を実行する
CloudFormationフルアクセスポリシーを作成する(自分で作成する必要がある)
file
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "cloudformation:*",
"Resource": "*"
}
]
}
EC2フルアクセス等必要なポリシーとCloudFormationフルアクセスのポリシーをユーザーに付与する
ユーザーを作成しCredentialsをダウンロードする(もしくはメモする)
AWS CLIの設定を行う
一般ユーザーにて行う方が良いと思われる。また場合によってはCloudFormation実行用ユーザーのプロファイルで設定した方が良いと思われる。
$ aws configure --profile your-profile-name
AWS Access Key ID [None]: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Default region name [None]: ap-northeast-1
Default output format [None]: json
操作方法
一般ユーザーにて行う方が良いと思われる。また場合によってはCloudFormation実行用ユーザーのプロファイルで設定した方が良いと思われる。
$ #スタックを作成する
$ aws cloudformation create-stack --stack-name stack-name --template-body file://stack.yml --profile cfn-user
$
$ #スタックを削除する
$ aws cloudformation delete-stack --stack-name stack-name --profile cfn-user