AWS CloudFormation CLI
Project description
AWS CloudFormation CLI
The missing AWS CloudFormation CLI.
Official
cfncliis not designed to manage stacks at this point.
Introduction
awscfncli helps build and manage AWS CloudFormation stacks.
Features:
-
Manage stacks in different accounts & regions in a single YAML config file.
-
Organize stack using stages and blueprints.
-
Select stacks to operate on using globs.
-
Cross-stack parameter reference.
-
Automatically package and upload template resources.
-
Push button SAM deployment using
stack synccommand.Now
samcliis getting better at deploying SAM template automatically. -
Display and tracking stack events in the CLI.
-
List stack resources, outputs and exports in the CLI.
Install
pip install awscfncli2
If you are install cfn-cli globally, using pipx is recommended:
pipx install awscfncli2
Auto Completion
Auto completion is supported by click and click_completion, supported shells are bash, zsh , fish and Powershell.
To install auto completion, run this in target shell:
> cfn-cli --install-completion
fish completion installed in /Users/Bob/.config/fish/completions/cfn-cli.fish
Three types of auto completions are supported:
- Commands and sub commands.
- Options and parameters.
- Dynamic complete for
--profileand--stacks.
> cfn-cli drift d<TAB><TAB>
detect (Detect stack drifts.) diff (Show stack resource drifts.)
> cfn-cli stack deploy --<TAB> <TAB>
--disable-rollback (Disable rollback if stack creation failed. You can specify ei…)
--help (Show this message and exit.)
--ignore-existing (Don't exit with error if the stack already exists.)
--no-wait (Exit immediately after deploy is started.)
--on-failure (Determines what action will be taken if stack creation fails. This …)
--timeout-in-minutes (The amount of time in minutes that can pass before the stac…)
> cfn-cli stack deploy --on-failure <TAB> <TAB>
DELETE DO_NOTHING ROLLBACK
> cfn-cli -s <TAB><TAB>
Develop.ApiBackend-Develop (ApiBackend-Develop)
Production.ApiBackend-Production (ApiBackend-Production)
Staging.ApiBackend-Staging (ApiBackend-Staging)
Usage
cfn-cli [OPTIONS...] COMMAND SUBCOMMAND [ARGS...]
To view a list of available subcommands, use:
cfn-cli COMMAND --help
Options:
-f, --file: Specify an alternate config file, (default:cfn-cli.yml).-s, --stack: Specify stacks to operate on, defined bySTAGE_NAME.STACK_NAME, default value is*, which means all stacks in all stages.--profile: Override AWS profile specified in the config.--region: Override AWS region specified in the config.--artifact-store: Override ArtifactStore (AWS bucket name) specified in the config.--verbose: Be more verbose.
Options can also be specified using environment variables:
CFN_STACK=Default.Table1 cfn-cli stack deploy
By default, cfn-cli will try to locate cfn-cli.yml or cfn-cli.yaml file
in current directory, override this behaviour using -f option.
Stack Selector
Individual stack can be selected using full qualified name:
cfn-cli -s Default.Table2 status
Unix globs is supported when selecting stacks:
cfn-cli -s Default.Table* status
cfn-cli -s Def*.Table1 status
If . is missing from stack selector, cfn-cli will assume
stage name * is specfied, thus * is equivalent to
*.*, which means all stacks in all stages.
Available Commands
Use --help to see help on a particular command.
generate- Generate sample configuration file.status- Print stack status and resources.validate- Validate template file.stack- Stack operations.sync-Apply changes using ChangeSetsdeploy- Deploy new stacks.update- Update existing stacks.tail- Print stack events.delete- Delete stacks.cancel- Cancel stack update.
drift- Drift detection.detect- Detect stack drifts.diff- Show stack resource drifts.
Automatic Packaging
If a template contains property which requires a S3 url or text block,
Set Package parameter to True so the resource will be automatically
upload to a S3 bucket, and S3 object location is inserted into the
resource location.
This feature is particular useful when your property is a lambda source code, SQL statements or some kind of configuration.
By default, the artifact bucket is awscfncli-${AWS_ACCOUNT_ID}-${AWS_RERION},
and the bucket will be created automatically.
You can override the default bucket using ArtifactStore parameter
The following resource property are supported by awscfncli and official
aws cloudformation package command:
BodyS3Locationproperty for theAWS::ApiGateway::RestApiresourceCodeproperty for theAWS::Lambda::FunctionresourceCodeUriproperty for theAWS::Serverless::FunctionresourceContentUriproperty for theAWS::Serverless::LayerVersionresourceDefinitionS3Locationproperty for theAWS::AppSync::GraphQLSchemaresourceRequestMappingTemplateS3Locationproperty for theAWS::AppSync::ResolverresourceResponseMappingTemplateS3Locationproperty for theAWS::AppSync::ResolverresourceDefinitionUriproperty for theAWS::Serverless::ApiresourceLocationparameter for theAWS::IncludetransformSourceBundleproperty for theAWS::ElasticBeanstalk::ApplicationVersionresourceTemplateURLproperty for theAWS::CloudFormation::StackresourceCommand.ScriptLocationproperty for theAWS::Glue::Jobresource
Configuration
awscfncli uses a yaml config file to manage which stacks to deploy and
how to deploy them. By default, it is cfn-cli.yml.
Anatomy
The config is composed of the following elements, Version, Stages
and Blueprints.
Version(required): Version of cfn-cli config, support 2 and 3 now.Stages(required): Definition of the stack to be deployed.Blueprints(optional): Template of the stack.
The following is a simple example of a typical config:
Version: 3
Stages:
Default:
DDB:
Template: DynamoDB_Table.yaml
Region: us-east-1
Parameters:
HashKeyElementName: id
DDB2ndIdx:
Template: DynamoDB_Secondary_Indexes.yaml
Region: us-east-1
StackPolicy: stack_policy.json
ResourceTypes:
- AWS::DynamoDB::Table
Parameters:
ReadCapacityUnits: 10
A stage could have multiple stacks.
In the above example, Stage Default have two stacks DDB and DDB2ndIdx.
Stack name could be customized and should contain only alpha and numbers.
Each stack may have the following attributes.
- Attributes introduced by
awscfncli:Profile: Profile name of your aws credentialRegion: Eg. us-east-1Package: Automatically package your template or notArtifactStore: Name of S3 bucket to store packaged filesOrder: Deployment order of stacksExtends: Extend a blueprint
- Attributes introduced by
boto3:- Please refer to Boto3 Create Stack
Blueprints and Inheritance
Blueprint serves as a template of a common stack. A stack could extends a stack and override its attributes with its own attributes.
-
Inheritance behaviors:
- scalar value: replace
- dict value: update
- list value: extend
-
Special attributes:
Capabilities: replace
For example, please refer to Blueprints Example
Stages and Ordering
Stage and stacks could be deployed according to the order you specified.
Order numbers are positive integers. cfn-cli will deploy stacks in
stages with lower order first and in each stage stacks with lower order will
be deployed first
- Stage Order
- Stack Order
Stages:
Stage1:
Order: 1
Stack1:
Order: 1
Stack2:
Order: 2
Stage2:
Order: 2
For examples, please refer to Order Example
Cross Stack Reference
In config version 3, we support a new feature called cross stack reference. In many cases, stacks' input depends on outputs from other stacks during deployment, so this new feature will allow stacks collect their inputs as needed and be deployed without interruption.
An attribute could reference ouputs of another stack by using the following syntax:
Stack1:
Parameters:
VpcId: ${StageName.StackName.OutputName}
For example, please refer to Cross Stack Example
Please Note: You should take care of the order of deployment yourself so that referenced stack is deployed first
Migrate from 2.0.x
Config File
If you are using new "cross stack reference" feature then version 3 is required:
Version: 3
Also NotificationARNs, ResourceTypes, RollbackConfiguration are supported now but no changes is required if old config file is not using them.
Migrate from 0.x
Config File
New configuration file supports multiple stages and stacks, to convert an 0.x configure file to current version,
- Add following block to the head of conf file and indent properly:
Version: 2
Stages:
Default:
<< old config file >>
- Change any
TemplateURLorTemplateBodyparameter toTemplate.
For example:
Old:
Stack:
TemplateURL: https://s3.amazonaws.com/cloudformation-templates-us-east-1/IAM_Users_Groups_and_Policies.template
Region: us-east-1
StackName: SampleIAMUsersGroupsAndPolicies
Capabilities: [CAPABILITY_IAM]
Parameters:
Password: bob180180180
Tags:
project: Bob
New:
Version: 2
Stages:
Default:
Stack:
Template: https://s3.amazonaws.com/cloudformation-templates-us-east-1/IAM_Users_Groups_and_Policies.template
Region: us-east-1
StackName: SampleIAMUsersGroupsAndPolicies
Capabilities: [CAPABILITY_IAM]
Parameters:
Password: bob180180180
Tags:
project: Bob
CLI
cfnis renamed tocfn-clito avoid conflict withtroposphere.templatecommand is removed.changesetcommand is removed, but a newsynccommand is added.- Because config file supports multiple stages and stacks, stack selector must be specified when you want to operate a subset of stacks.
Sync
New sync command combines aws cloudformation package and aws cloudformation deploy in one step:
cfn changeset create
cfn changeset execute
Is replaced by:
cfn-cli -s sam.api sync
sync uses ChangeSet internally which is useful when dealing with template transforms (eg: SAM or macros).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awscfncli2-3.0.0b1.tar.gz.
File metadata
- Download URL: awscfncli2-3.0.0b1.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20e4c5e90e4687d5da7a3056f2504a8ea613d7e801e914c13b1320a7510807f3
|
|
| MD5 |
8f21fd07c8bb6cabcca2a33963e8f076
|
|
| BLAKE2b-256 |
f049fc5be70126af96b6f2f9cc53bf04a5b0ed66bfc2f8295cd95fb7bdb8e17d
|
File details
Details for the file awscfncli2-3.0.0b1-py2.py3-none-any.whl.
File metadata
- Download URL: awscfncli2-3.0.0b1-py2.py3-none-any.whl
- Upload date:
- Size: 59.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f06af655b8d33bf8591f9de0680dc505e4339a571bafd54c9dcac1a242ace562
|
|
| MD5 |
33d7d232e0619be7c8a6d4feb42d6643
|
|
| BLAKE2b-256 |
90a033e3293d8bc43f078492ce4d792504b5314c8fc26ead1b2dc9741c54ddf7
|