AWS CLIで CloudFormationを操作する
CloudFormationのドキュメントで、コマンドラインのところでもすでに(2013.10.18現在) AWS CLIを使うようになっている。
※ こっちでは、"The prior AWS CloudFormation CLI tools are still available, but not recommended. "と書いてある
※敢えて古い api toolsを使い始めるならこちら( CloudFormaion apitoolsをAmazon Linuxで使う)を参照。
AWS CLIのセットアップ
Amazon Linuxならデフォルトで入っていてPATHも通っているので、credential 関係だけ設定する。
$ vi ~/.awscredential $ cat ~/.awscredential AWSAccessKeyId=<<your AWS access ID>> AWSSecretKey=<<your AWS secret key> > $ vi ~/.bashrc $ cat ~/.bashrc export AWS_CREDENTIAL_FILE=~/.awcredential $ source ~/.bashrc
動作確認
スタック一覧
$ aws cloudformation list-stacks --region ap-northeast-1
スタック作成(S3にあるテンプレートの場合)
$ aws cloudformation create-stack--region ap-northeast-1 \ --stack-name test \ --template-url http://s3.amazonaws.com/sample/test.template \ --parameters ParameterKey=Param1,ParameterValue=value1
スタック作成(ローカルのテンプレートの場合)
$ aws cloudformation create-stack--region ap-northeast-1 \ --stack-name test \ --template-body file:////home/ec2-user/test.template \ --parameters ParameterKey=Param1,ParameterValue=value1
スタック詳細
$ aws cloudformation describe-stacks --region ap-northeast-1 \ --stack-name test
テンプレートのチェック
$ aws cloudformation validate-template --region ap-northeast-1 \ --template-body file:////home/ec2-user/test.template
コマンドリファレンス
http://docs.aws.amazon.com/cli/latest/reference/cloudformation/index.html