• Stars
    star
    901
  • Rank 50,699 (Top 1.0 %)
  • Language
    JavaScript
  • Created over 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CLI tool to visualise CloudFormation/SAM/CDK stacks as visjs networks, draw.io or ascii-art diagrams.

cfn-diagram

Node.js CI

CLI tool to visualise CloudFormation/SAM/CDK templates as diagrams.

Installation

npm i -g @mhlabs/cfn-diagram

Usage

Usage: cfn-dia [options] [command]

Options:
  -v, --vers                          Output the current version
  -h, --help                          Display help for command

Commands:
  draw.io|d [options]                 Generates a draw.io diagram from a CloudFormation template
  html|h [options]                    Generates a vis.js diagram from a CloudFormation template
  browse|b [options]                  Browses and generates diagrams from your deployed templates
  help [command]                      Display help for command

Draw.io Options:
  -t, --template-file [templateFile]  Path to template or cdk.json file
  -c, --ci-mode                       Disable terminal/console interactivity
  -o, --output-file [outputFile]      Name of output file
  -co, --cdk-output [outputPath]      CDK synth output path
  -s, --skip-synth                    Skips CDK synth
  -e, --exclude-types [excludeTypes]  List of resource types to exclude when using CI mode

Html Options:
  -t, --template-file [templateFile]  Path to template or cdk.json file
  -c, --ci-mode                       Disable terminal/console interactivity
  -o, --output-path [outputPath]      Name of output file
  -co, --cdk-output [outputPath]      CDK synth output path
  -s, --skip-synth                    Skips CDK synth

Output formats

Draw.io

Usage: cfn-dia draw.io|d [options]

Generates a draw.io diagram from a CloudFormation template

Options:
  -t, --template-file [templateFile]     Path to template or cdk.json file (default: "template.yaml or
                                         cdk.json")
  -c, --ci-mode                          Disable terminal/console interactivity (default: false)
  --stacks [stacks]                      Comma separated list of stack name(s) to include. Defaults to
                                         all.
  -o, --output-file [outputFile]         Name of output file (default: "template.drawio")
  -co, --cdk-output [outputPath]         CDK synth output path (default: "cdk.out")
  -s, --skip-synth                       Skips CDK synth (default: false)
  -e, --exclude-types [excludeTypes...]  List of resource types to exclude when using CI mode
  -h, --help                             display help for command

Use it in combination with the Draw.io Integration for VS Code to instantly visualise your stacks.

Demo

Example

cfn-dia draw.io -t template.yaml

Features

  • Select only the resource types you want to see. This lets you skip granlar things like roles and policies that might not add to the overview you want to see
  • Navigate through a new differnet layouts
  • Works for both JSON and YAML templates
  • Filter on resource type and/or resource names
  • Works with CloudFormation, SAM and CDK

HTML

Usage: cfn-dia html|h [options]

Generates a vis.js diagram from a CloudFormation template

Options:
  -t, --template-file [templateFile]  Path to template or cdk.json file (default: "template.yaml or
                                      cdk.json")
  --stacks [stacks]                   Comma separated list of stack name(s) to include. Defaults to all.
  -all --render-all                   If set, all nested stacks will be rendered. By default only root
                                      template is rendered (default: false)
  -c, --ci-mode                       Disable terminal/console interactivity (default: false)
  -o, --output-path [outputPath]      Name of output file (default: "/tmp/cfn-diagram")
  -co, --cdk-output [outputPath]      CDK synth output path (default: "cdk.out")
  -s, --skip-synth                    Skips CDK synth (default: false)
  -h, --help                          display help for command

The HTML output uses vis.js to generate an interactive diagram from your template.

Demo

Example

cfn-dia html -t template.yaml

or, for CDK stacks, go to project directory (where cdk.json is located) and enter

cfn-dia html 

Large stacks, in particular multi-stack CDK projects, tend to generate huge diagrams. You can pass the stack names you want to render using the --stacks argument followed by a comma separated list of stack names.

Ascii-art

Usage: cfn-dia ascii-art|a [options]

Generates an ascii-art diagram from a CloudFormation template

Options:
  -t, --template-file [templateFile]     Path to template or cdk.json file (default: "template.yaml or cdk.json")
  --stacks [stacks]                      Comma separated list of stack name(s) to include. Defaults to all.
  -co, --cdk-output [outputPath]         CDK synth output path (default: "cdk.out")
  -s, --skip-synth                       Skips CDK synth (default: false)
  -w, --watch                            Watch for changes in template and rerender diagram on change (default: false)
  -e, --exclude-types [excludeTypes...]  List of resource types to exclude when using CI mode
  -h, --help                             display help for command                           display help for command

Renders a simple Ascii-art diagram of your template directly in the console. Useful to gain a quick overview of smaller stacks.

Demo

Video demo of using the --watch option: Demo of watch command

Mermaid

Usage: cfn-dia mermaid|m [options]

Generates a mermaid graph from a template

Options:
  -t, --template-file [templateFile]  Path to template or cdk.json file (default: "template.yaml or cdk.json")
  -all --render-all                   If set, all nested stacks will be rendered. By default only root template is rendered (default: false)
  -o, --output-path [outputPath]      Name of output file
  -co, --cdk-output [cdkOutputPath]   CDK synth output path (default: "cdk.out")
  -s, --skip-synth                    Skips CDK synth (default: false)
  -h, --help                          display help for command

Renders a mermaid diagram of your template directly in the console or to a file. Useful to gain a quick overview of smaller stacks and to generate as part of your CI/CD flow for up-to-date documentation.

Demo

CI-mode

This functionality lives in its own CLI, cfn-diagram-ci. This is beacuse it requires headless Chromium to be installed which makes the package size very large

It uses pageres to generate a screenshot of a HTML diagram. This can be used in a CI/CD pipeline to keep an always up-to-date diagram in your readme-file.

Installation

npm install -g @mhlabs/cfn-diagram-ci

Example

cfn-dia-ci html -t template.yaml

Known issues

  • Some icons are missing. Working on completing the coverage.
  • When using WSL you might experience Error: spawn wslvar ENOENT when trying to use HTML output. To resolve, install wslu. See issue #9.

More Repositories

1

evb-cli

Pattern generator and debugging tool for Amazon EventBridge
JavaScript
214
star
2

cw-logs-insights-gpt

Chrome extension that generates CloudWatch Logs Insights queries from ChatGPT prompts
JavaScript
89
star
3

samp-cli

CLI tool that offers advanced productivity and debugging features to AWS SAM users
JavaScript
70
star
4

iam-policies-cli

A CLI tool for building simple to complex IAM policies
JavaScript
68
star
5

sfn-workflow-studio-sync

Enables real-time sync between StepFunctions Workflow Studio and your local machine
JavaScript
42
star
6

lambda-debug

Library to help debug JS/TS AWS Lambda functions locally
JavaScript
32
star
7

cfn-resource-actions

Interact with your deployed CloudFormation/SAM templates directly from the template
TypeScript
22
star
8

awesome-lars-tools

Consolidated list of the tools I maintain
13
star
9

cw-logs-insights-snippets

AWS SAM project that adds the snippets from serverlessland.com/snippets as saved queries in CloudWatch Logs Insights
TypeScript
12
star
10

aws-resource-explorer-cli

Searches AWS resources and launches them in the AWS console in your browser
JavaScript
9
star
11

low-code-url-shortener

Low code URL shortener build on AWS API Gateway, StepFunctions Express and DynamoDB
7
star
12

ai-doorbell

AI doorbell that uses speech synthesis to describe the person at the door
JavaScript
7
star
13

stepfunctions-sdk-autocomplete

VSCode autocomplete for AWS StepFunctions SDK integrations
TypeScript
5
star
14

aws-news-comics

Bot that creates comic strips from the latest service announcements from AWS and posts them on X
JavaScript
2
star
15

evb-sfn-event-scheduler

JavaScript
2
star
16

github-codesearch-chrome-extension

Chrome extension lets you make select text on any webpage and search for it in GitHub CodeSearch
JavaScript
2
star
17

cloudwatch-logs-snippets-extension

Chrome extension that gives instant access to the CloudWatch Logs Insights snippets from serverlessland.com/snippets
JavaScript
2
star
18

cw-alarms-poc

Reference project for loosely coupled cloudwatch alarms
JavaScript
1
star
19

reinvent-portal-extension

Chrome extension to help getting a seat at your favourite sessions at re:invent
JavaScript
1
star