CloudFormation CLI Wrapper
Project description
AWS CloudFormation CLI
The missing CloudFormation CLI. Reborn!
This code base was forked from https://github.com/Kotaimen/awscfncli with the aim of continuing its use alongside AWS CLI v2 which enables login through AWS Identity Center
This codebase does not aim to maintain the backwards compatibility that the original cfn-cli
repo maintained. As such it was forked, detached and will be maintained separately with feature development that will likely not be paralleled in the original code base. This allows for modern dependencies of boto3 and botocore and other python libraries to be used - reducing conflict on installation of the CLI.
This version of cfn-cli
has been tested and validated operational on AWS CloudShell, AWS Cloud 9, AWS Linux 2023 AMIs.
Compatibility
This tool supports Python 3.7 and above. Python 2.X is not supported.
Note this tool is incompatible with the AWS
cloudformation-cli
package due to the name clash between the two tools. A "rename" is not being considered at the moment as it is considered unlilkely to require both this tool and the AWS module/resource provider development tool within the same Python environment (i.e. without use of .venv)
License
This tool is distributed under the MIT license. The AWS CLI dependent code is distributed under the Apache 2.0 license - see ext_customizations README and LICENCE.
Whats New
See Feature Development for a list of new features added since the repo was forked from the original source.
Introduction
cfncli
helps manage AWS CloudFormation deployments.
Highlights:
- Manage deployments accoss accounts and regions use single YAML config file.
- Cross-stack parameter reference works cross-region and cross-account.
- Organize stack using stages and blueprints.
- Automatically package and upload template resources.
- Push button SAM deployment using
stack sync
command. - Display and track stack events in the CLI.
- List stack resources, outputs and exports in the CLI.
Install
Install from "Test" PyPi
pip3 install cfncli --extra-index-url=https://test.pypi.org/simple/
Usage
Quickstart
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.-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 or environment variableAWS_PROFILE
.--region
: Override AWS region specified in the config.--artifact-store
: Override bucket used for template transform/packaging 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
tries to locate cfn-cli.yml
or cfn-cli.yaml
file in current directory, override this use -f
.
Stack Selector
Individual stack can be selected using full qualified name:
cfn-cli -s Default.Table2 status
Or, select stacks use Unix globs:
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 specified.
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.
Auto Completion
Auto completion is supported by 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
Supported completion:
-
Commands and sub commands:
> cfn-cli drift d<TAB><TAB> detect (Detect stack drifts.) diff (Show stack resource drifts.)
-
Options and parameters:
> 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…)
-
Parameter choices:
> cfn-cli stack deploy --on-failure <TAB> <TAB> DELETE DO_NOTHING ROLLBACK
-
Dynamic complete for
--profile
by search profile name inawscli
config:> cfn-cli -p <TAB><TAB> default prod staging
-
Dynamic complete for
--stack
by search stack name incfn-cli
config:> cfn-cli -s <TAB><TAB> Develop.ApiBackend-Develop (ApiBackend-Develop) Production.ApiBackend-Production (ApiBackend-Production) Staging.ApiBackend-Staging (ApiBackend-Staging)
Automatic Packaging
If a template contains property which requires a S3 url or text block, Set stack Package
parameter to True
tells
cfn-cli
to package the resource automatically and upload to a S3 artifact 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 it will be created automatically
on first run. Override the default bucket using ArtifactStore
parameter.
The following resource property are supported by awscfncli
and official aws cloudformation package
command:
BodyS3Location
property for theAWS::ApiGateway::RestApi
resourceCode
property for theAWS::Lambda::Function
resourceCodeUri
property for theAWS::Serverless::Function
resourceContentUri
property for theAWS::Serverless::LayerVersion
resourceDefinitionS3Location
property for theAWS::AppSync::GraphQLSchema
resourceRequestMappingTemplateS3Location
property for theAWS::AppSync::Resolver
resourceResponseMappingTemplateS3Location
property for theAWS::AppSync::Resolver
resourceDefinitionUri
property for theAWS::Serverless::Api
resourceLocation
parameter for theAWS::Include
transformSourceBundle
property for theAWS::ElasticBeanstalk::ApplicationVersion
resourceTemplateURL
property for theAWS::CloudFormation::Stack
resourceCommand.ScriptLocation
property for theAWS::Glue::Job
resource
To package a template build by
awssamcli
, pointTemplate
parameter tosam build
output.
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 many cases, a stack's input parameter depends on output from other stacks during deployment. Cross stack reference allows stacks collect their inputs from outputs form other stacks, including stacks deployed to other region and account.
An stack parameter can reference ouputs of another stack in same configuration file by using the following syntax:
Stack1:
Parameters:
VpcId: ${StageName.StackName.OutputName}
This feature make managing related cross-account and/or cross-region stacks much easier. See VPC peering and CodePipeline for example.
Note: Take care of the order of deployment so eferenced stack is deployed first.
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
File details
Details for the file cfncli-0.1.0.tar.gz
.
File metadata
- Download URL: cfncli-0.1.0.tar.gz
- Upload date:
- Size: 56.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 669b279d5d65f9dcbb97c0f1c94c96b5b32e981f517cb22064490a641a1ad82b |
|
MD5 | 158e3208f1791a0565583488cc45f37b |
|
BLAKE2b-256 | c1036881e9d46fb83f0b2ece4d8ed6675cc6432aa629f110f177edcf9dbf00c1 |