https://diagrams.mingrammer.com/
I usually use authoring tools such as Cacoo for configuration diagrams, I tried to see how much I could write using a tool that can draw a configuration diagram with Python code.
――Since it can be written simply, it is good to be able to quickly prototype a new system as it is touted. ――The learning cost is low, and you can start writing as soon as you are familiar with Python. --There was a font size change attribute, but I didn't know how to write annotations.
--Python 3.6 and above --Requires Graphviz
Create a new virtual environment and install packages in it. This procedure is optional.
python -m venv ~/envs/diagrams
source ~/envs/diagrams/bin/activate
Installation
https://diagrams.mingrammer.com/docs/getting-started/installation
#Install with Homebrew
brew install graphviz
#Install with pip
pip install diagrams
For the time being, I tried to output using an example.
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") >> RDS("db")
python diagram.py
2020-05-29 13:50:05.901 +[__NSCFConstantString length]: unrecognized selector sent to class 0x
2020-05-29 13:50:05.905 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[__NSCFConstantString length]: unrecognized selector sent to class 0x'
Immediately, I encountered an error. I didn't know the cause at all, so I decided to upgrade graphviz, which was originally installed, while catching issues.
brew upgrade graphviz
You have successfully upgraded the version to 2.40.1-> 2.44.0.
python diagram.py
I was able to output safely.
from diagrams import Cluster, Diagram
from diagrams.aws.compute import EC2, ElasticBeanstalk
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB, Route53
from diagrams.onprem.client import Client
graph_attr = {
}
def draw():
with Diagram("web_service", show=False, graph_attr=graph_attr, direction="TB"):
route53 = Route53('route53')
client = Client('client')
client >> route53
with Cluster("ElasticBeanstalk"):
with Cluster("WEB"):
with Cluster("Subnet1"):
web1 = EC2("web")
lb1 = ELB("lb1")
lb1 >> web1
with Cluster("Subnet2"):
web2 = EC2("web")
lb2 = ELB("lb2")
lb2 >> web2
route53 - [lb1, lb2]
with Cluster("DB"):
db_master = RDS("master")
with Cluster("Subnet3"):
rds1 = RDS("slave1")
with Cluster("Subnet4"):
rds2 = RDS("slave2")
db_master - [rds1, rds2]
[web1, web2] >> db_master
if __name__ == '__main__':
draw()
Recommended Posts