DEV Community

Michael Wahl for AWS Community Builders

Posted on

Diagrams as Code DaC to go along with infrastructure as Code IaC

I have started using Diagrams which lets you easily draw/create cloud architecture using Python code!

This also allows you to visualize existing system architecture. The major providers are supported including AWS,Azure, and GCP. It also supports on-premise and SaaS applications.

Setup

The install is pretty straight forward, it does require python 3.6 or higher. Diagrams uses Graphviz to render the diagram, so you will need to install it first before you install and use Diagrams.

macOS users can download the Graphviz via brew install graphviz. Windows users fear not, you are not forgotten, and may use Chocolatey to run choco install graphviz.

# using pip (pip3)
$ pip install diagrams

# using pipenv
$ pipenv install diagrams

# using poetry
$ poetry add diagrams

Enter fullscreen mode Exit fullscreen mode

Demo or Quick Start


# demo.py
from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB

with Diagram("Web Service", show=False):
    ELB("lb") >> EC2("web") >> EC2("web") >> EC2("web") >>  RDS("userdb")

Enter fullscreen mode Exit fullscreen mode

This generates the diagram below, saved as a png file within your working directory.

$ python3 demo.py

Image description

More Info

Check out the Quick start guide

Check out the guides

Available nodes list

Top comments (0)