AWS CloudFormation stack command line management tool
- An AWS account
- Node.js version 8+
Warning: Using this tool to deploy templates that are successfully created will result in service charges. Please be aware of what you are doing before doing it. You've been warned.
Clone the repository, currently I am not providing this as a package, though I may do so in the future.
$ git clone https://github.com/azjones/stacks.gitInstall as global link. This will make bin/stacks available in PATH
$ cd stacks
$ npm linkIf you wish to make changes, prior to doing so, you will need to install dependencies
$ npm iAnd if you do make changes, make sure to rebuild the bin.
$ npm run build$ npm uninstall -g stacksYou refer to the program as either stacks or stx. Currently you are able to deploy, delete, list, upload, validate, certs and account. All commands are easy to use. But if you need help, simply $ stacks -h.
Usage: stacks [options] [command]
Options:
-V, --version output the version number
-p, --profile <default> aws profile (default: default)
-r, --region <us-west-2> aws region (default: us-west-2)
-h, --help output usage information
Commands:
deploy [options] [template] [name] deploys a stack
delete [type] [name] delete stack, bucket, logs
list [type] list stacks, exports, buckets, logs
upload [options] [template] uploads template to bucket
account show account information
validate [template] validates the template
certs lists ssl certificates
There are two default options, -p, --profile and -r, --region. The profile option defaults to your AWS [default] credential located in ~/.aws/credentials. The region option defaults to us-west-2 and currently is not pulled from ~/.aws/config. This needs to be fixed, currently the aws-sdk package does not import the region value expressed in its config as it should. So I explicitly configure it here.
Deploying a template is easy. Simply tell stacks to deploy, and point to a file somewhere on your machine. Currently stacks only supports *.yml and *.yaml files. The deploy command has 2 options, --params and --protect. The params option takes a list of CloudFormation parameters defined by key-value pairs separated by a comma, like ParamOne=some-value,ParamTwo=anotherValue. The protect option is a boolean that defaults to false. If you pass --protect you are telling stacks to make the template you are cloud forming to be protected from accidental deletion.
The following are possible ways to use stacks deploy
$ stacks deploy ../templates/vpc.yml --protect --params Cidr=10.1.0.0/16$ stacks deploy ./ec2.ymlIf you wish to deploy a template to an AWS environment other than your default, you can simply pass the -p, --profile and/or -r, --region options. Where prd is a profile type in your ~/.aws/credentials
$ stacks deploy ~/Projects/cloudapp/templates/api.yml -p prd -r us-east-1You may also name your stacks other than the name of the file you pass it. In the above examples, your stack names would be vpc and ec2 respectively. But you can also pass a name argument, in this case the name of the stack will be cognito.
$ stacks deploy ../template/usermanagement.yaml cognito --protect --params AuthName=test -p stageDeleting a template is easier than deploying it! Just tell stacks to delete and pass the name of the stack. Or you can tell stacks to delete bucket or delete logs
$ stacks delete stack cognitoOr you can delete a bucket or log group
$ stacks delete bucket cicd-deploy-artifacts
$ stacks delete logs /aws/lambda/functionIf you need to delete a stack from an environment other than your default, simply pass the profile.
$ stacks delete stack cognito -p stageWith the list command, you can list stacks or exports. Simply pass either stacks, exports, buckets or logs in the command. You can list stacks.
$ stacks listor
$ stacks list stacksOr you can list exports, buckets or logs
$ stacks list exports
$ stacks list buckets
$ stacks list logsAnd of course you can list stacks or exports in different environments.
$ stacks list exports -p stageYou can upload single templates or you upload entire directories of templates with stacks. Uploading entire directories may be useful for those who use nested stacks in their deployments. And require multiple stack templates to exist in the s3 bucket prior to stacks deploy.
By default, if you are looking to only deploy a single template file, you do not need to upload first, the stacks deploy command will handle that for you. However if you wish to put templates files out on to s3 for safe keeping the upload command would be a nice option. If you require nested templates to exist prior to deploy, you may upload them one-by-one.
$ stacks upload ./nestedTemplate.yml
$ stacks upload ./anotherTemplate.ymlIf you wish to simply upload the directory of templates, simply point to a directory and pass the --dir option.
$ stacks upload ../cloudformation/templates/ --dirIf you need a quick reference to some of the basic account information provided to you from AWS, you can:
$ stacks accountAnd with all the commands, you can pass the profile option.
If you aren't confident the template you are about to deploy is valid, you can have stacks validate it.
$ stacks validate ~/Projects/cloudapp/templates/sql.yamlSome stacks require you pass a CertificateArn, namely, a AWS::CloudFront::Distribution stack. You can use stacks to quickly look up available certificates.
$ stacks certsMIT