draws is a dependency-free tool for automating AWS architecture diagram creation.
pip install draws
Add Diagrams.of(app)
before app.synth()
.
app.py:
from aws_cdk import App
from draws import Diagrams
from infra.api_to_s3_stack import ApiToS3Stack
from infra.s3_bucket_stack import S3BucketStack
app = App()
bucket_stack = S3BucketStack(app, f"draws-dev-bucket", public_prefix="public")
docs_ui_stack = ApiToS3Stack(app, f"draws-dev-docs-ui", bucket=bucket_stack.bucket)
# Pass the cdk app into Diagrams.of() (directory defaults to app.py location)
Diagrams.of(app, directory="examples/output")
app.synth()
Run cdk ls
to generate diagrams for each stack.
output:
$ cdk ls
Diagram saved to: examples/output/draws-dev-bucket.diagram.svg
Diagram saved to: examples/output/draws-dev-docs-ui.diagram.svg
import os
from pathlib import Path
from draws import Diagram
if __name__ == "__main__":
curr_dir = Path(os.path.abspath(os.path.dirname(__file__)))
templates_dir = curr_dir / "cdk.out"
D = Diagram.from_template(
filename=templates_dir / "my-stack.template.json",
title="My AWS Stack",
)
D.to_svg()
import os
from pathlib import Path
from draws import Diagram, Elem
if __name__ == "__main__":
with Diagram(title="My AWS Stack") as D:
rest_api = Elem("AWS::ApiGateway::RestApi", "Rest API")
lambda_func = Elem("AWS::Lambda::Function", "Lambda")
bucket = Elem("AWS::S3::Bucket", "Bucket")
rest_api >> lambda_func
rest_api << lambda_func
lambda_func >> bucket
D.to_svg()