Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

CloudFormation

Kevin Zhuang edited this page Jul 26, 2020 · 5 revisions

All CloudFormation related action support alternate profile and region. Configure them through the fzfaws.yml config file or you could pass in command line options. The command line option takes higher precedence and will override the config file settings. For more information about priority, checkout here.

fzfaws cloudformation create --profile --region

Configure fzfaws.yml to set default profile and region for all CloudFormation actions, this will override the global settings of profile and region. In the example below, the default profile and us-east-1 will be used for all other services, but CloudFormation service will use the root profile and us-east-2 by default.

global:
  profile: default
  region: us-east-1
services:
  s3:
    profile: root
    region: us-east-2

Creating a stack

Reference individual option flag through fzfaws cloudformation create --help.

Without any arguments:

  1. Select a S3 bucket
  2. Select a cloudformation template in the bucket
  3. Enter the name for the new stack
  4. Enter parameter value for the new stack (if parameter is a list type, you can use TAB to multi select)
  5. Stack will be created
fzfaws cloudformation create

Choose a specific version of the template if bucket has versioning enabled.

fzfaws cloudformation create --version

Configure extra settings when creating a stack, including: Tags, IAM roles, Notifications, StackPolicy, RollbackConfiguration, CreationOption. They resembles the settings you can configure in AWS console. Use TAB to multi select.

fzfaws cloudformation create --extra

You could wait for stack creation to complete, checkout #wating-for-stack-operation-to-complete.

Using template in local machine

Create a stack using a template in current directory.

fzfaws cloudformation create --local

To list files from home directory, you could use the --root flag. Note: it is extremely slow and resource intensive if you don't have fd installed to search from home directory, install fd before using this flag.

fzfaws cloudformation create --local --root

demo

Updating existing stack

Reference individual option flag through fzfaws cloudformation update --help.

Without any arguments:

  1. Select a CloudFormation stack
  2. Update existing parameter
  3. Stack will be updated
fzfaws cloudformation update

Update extra settings when updating a stack, including: Tags, IAM roles, Notifications, StackPolicy, RollbackConfiguration. They resembles the settings you can configure in AWS console. Use TAB to multi select.

fzfaws cloudformation update --extra

You could wait for stack update to complete, checkout #wating-for-stack-operation-to-complete.

Replacing update

You can choose to replace the template during update, mechanics are the same as creating a stack.

fzfaws cloudformation update --replace

Same as creating a stack, you can choose to use a version of a template in S3.

fzfaws cloudformation update --replace --version

A full example to do a replacing update using a template in local machine as well as configuring extra settings and wait for the operation to complete.

fzfaws cloudformation update --replace --local --root --extra --wait

demo

Deleting a stack

Reference individual option flag through fzfaws cloudformation delete --help.

Without any arguments:

  1. Select a CloudFormation stack
  2. Stack will be deleted
fzfaws cloudformation delete

Use a specific IAM role that has the permission to delete the current stack. Useful if you have associate a role with the stack.

fzfaws cloudformation delete --iam

You could wait for stack deletion to complete, checkout #wating-for-stack-operation-to-complete.

Operations around changeset

Reference individual option flag through fzfaws cloudformation changeset --help.

Without any arguments:

  1. Select a CloudFormation stack
  2. Enter a name and description for the changeset
  3. Enter new parameters
  4. Changset will be created
fzfaws cloudformation changeset

Configure extra settings when creating a changeset, including: Tags, IAM roles, Notifications, RollbackConfiguration. They resemble the settings you can configure in AWS console. Use TAB to multi select.

fzfaws cloudformation changeset --extra

You could wait for stack changeset creation to complete, checkout #wating-for-stack-operation-to-complete.

Handling changeset

View results of the changeset.

fzfaws cloudformation changeset --info

Execute a changeset to trigger a stack update.

fzfaws cloudformation changeset --execute

Delete a changeset.

fzfaws cloudformation changeset --delete

Replacing update changeset

Under the hood, this is using a #replacing-update. So same options and mechanics are applied when creating a replacing update changeset.

fzfaws cloudformation changeset --replace

A full example to create a replacing changeset using a template in current machine and also wait for the changeset to finish create.

fzfaws cloudformation changeset --replace --local --wait

Detecting stack drift

Reference individual option flag through fzfaws cloudformation drift --help.

Without any arguments:

  1. Select a CloudFormation stack
  2. A drift detection will init on the selected stack
fzfaws cloudformation drift

Detect drift on a specific resource in a stack, support multi selection.

fzfaws cloudformation drift --select

View the current drift status.

fzfaws cloudformation drift --info

You could wait for drift detection to complete, checkout #wating-for-stack-operation-to-complete.

Validating template

Reference individual option flag through fzfaws cloudformation validate --help.

Without any arguments:

  1. Select a S3 bucket
  2. Select a template in the bucket
  3. The template will be validated
fzfaws cloudformation validate

Validate a version of a template in a versioning enabled S3 bucket.

fzfaws cloudformation validate --version

Validating template in local machine

fzfaws cloudformation validate --local

To list files from home directory, you could use the --root flag. Note: it is extremely slow and resource intensive if you don't have fd installed to search from home directory, install fd before using this flag.

fzfaws cloudformation validate --local --root

Listing CloudFormation information

Checkout the dedicated section for extending fzfaws functionalities which explains how and why for the ls commands. The ls command will just print out information without doing any actions. Consult the help manual to see the available options.

fzfaws cloudformation ls --help

Waiting for stack operation to complete

Apply --wait flag to wait for stack operation to complete before exiting fzfaws.

fzfaws cloudformation create --wait

It is recommended to add --wait as a default argument for CloudFormation operations.

services:
  s3:
    default_args:
      create: --wait
      update: --wait
      delete: --wait
      changeset: --wait
      drift: --wait

Skipping some prompts

Checkout the explanation in S3 wiki which explains the syntax of how to use the --bucket flag.

The difference is CloudFormation operations uses --bucket instead of --bucketpath option in S3 operations.

fzfaws cloudformation create --bucket bucket1/folder1/template.json --wait --extra