public_subnets = [ PublicSubnet("Subnet zone a"), PublicSubnet("Subnet zone b"), PublicSubnet("Subnet zone c"), PublicSubnet("Subnet zone d"), ] nat_gateway = NATGateway("NAT gateway") with Cluster("Private network"): private_subnets = [ PrivateSubnet("Subnet zone a"), PrivateSubnet("Subnet zone b"), PrivateSubnet("Subnet zone c"), PrivateSubnet("Subnet zone d"), ] with Cluster("Kubernetes cluster"): autoscaling_group = AutoScaling("Autoscaling group") autoscaling_group_instances = [ EC2("K8s worker zone a"), EC2("K8s worker zone b"), EC2("K8s worker zone c"), EC2("K8s worker zone d"), ] ingress = Ingress("Ingress gateway") services = Service("Services") pods = Pod("Container pods") ci_pipeline = GitlabCI("CI pipeline") terraform_repo = Terraform("Infra as code") remote_state = S3("Remote state") ssl_certificate - dns_name
from diagrams import Diagram, Cluster, Edge from diagrams.aws.compute import AutoScaling from diagrams.aws.network import VPC from diagrams.onprem.iac import Ansible from diagrams.programming.language import Bash from diagrams.onprem.compute import Server with Diagram("AWS Launch Template", show=False, direction="TB"): with Cluster("vpc"): launch_template = AutoScaling("launch template") VPC("security group(s)") >> launch_template [Bash("bash"), Ansible("ansible"), Server("cloud-init")] >> Edge(label="userdata") >> launch_template
app_servers >> db_master app_servers >> nfs with Diagram("AWS web application", show=True): users = Users('website/mobile users') with Cluster("Ingress"): dns = Route53("Route53") with Cluster("Cloudfront CDN"): s3_content = S3('Shared content') cf = CF('Cloudfront CDN') with Cluster('VPC'): with Cluster("WebProxy AutoScalingGroup (ASG)"): web_asg = AutoScaling('ASG') web_lb = ELB("NLB") with Cluster("Application servers AutoScalingGroup (ASG)"): app_asg = AutoScaling('ASG') app_lb = ELB("NLB") with Cluster("AWS Batch"): cwa = cw('CW Event') batch_s3 = S3('Batch data') batch = Batch('AWS Batch') with Cluster("DB Cluster"): db_master = RDS("master") db_master - [RDS("slave")]
from diagrams import Diagram, Cluster from diagrams.aws.compute import ECS, AutoScaling from diagrams.aws.network import APIGateway, CloudMap with Diagram("AWS ECS Cluster", show=False, direction="TB"): api_gw = APIGateway("api gateway") with Cluster("vpc"): api_gw >> CloudMap("service discovery") >> ECS( "ecs cluster") >> AutoScaling("capacity provider")
ecr = ECR("Webservices Image") with Cluster("VPC"): PrivateSubnet("Private Subnet") with Cluster("Loadbalancing"): loadbalancer = ELB("Loadbalancer\nEndpoint") [maindomain, secondarydomain] >> loadbalancer with Cluster("ECS Cluster"): clusterecs = ECS("Webservices-Prod") autoscalingclusterecs = AutoScaling("Cluster Scaling") ec2 = EC2("EC2 Instances") alarmscluster = Cloudwatch("Cluster Reserved CPU Alarm") clusterecs >> alarmscluster >> autoscalingclusterecs >> ec2 with Cluster("Webservices Service"): webservices = EC2("Webservices Tasks") autoscalingwebservices = AutoScaling( "Webservices docker scaling") alarmswebservices = Cloudwatch("Service CPU Alarm")
from diagrams import Diagram, Cluster from diagrams.aws.compute import AutoScaling, EC2 with Diagram("AWS AutoScaling Group", show=False, direction="TB"): with Cluster("vpc"): EC2("nodes 0..n") << AutoScaling("autoscaling group") << [ AutoScaling("schedule up"), AutoScaling("schedule down") ]
PublicSubnet("Subnet c"), ] nat_gateways = [ NATGateway("NAT Gateway a"), NATGateway("NAT Gateway b"), NATGateway("NAT Gateway c"), ] bastion_host = EC2("Bastion Host") with Cluster("Private Network"): private_subnets = [ PrivateSubnet("Subnet a"), PrivateSubnet("Subnet b"), PrivateSubnet("Subnet c"), ] with Cluster("ECS Cluster"): autoscaling_group = AutoScaling("Autoscaling Group") autoscaling_group_instances = [ EC2("EC2 Instance a"), EC2("EC2 Instance b"), EC2("EC2 Instance c"), ] with Cluster("Aurora Cluster"): aurora_endpoint = AuroraInstance("Aurora Endpoint") aurora_autoscaling_group_instances = [ Aurora("Primary Instance"), Aurora("Aurora Replica"), Aurora("Aurora Replica"), ] aurora_autoscaling_group = AutoScaling("Aurora Autoscaling") with Cluster("Container Service"):
from diagrams.onprem.iac import Terraform, Ansible graph_attr = {"bgcolor": "transparent", "dpi": "300"} with Diagram( "Example Project", show=True, filename="clustered_web_services_example", graph_attr=graph_attr, ): with Cluster("Multi-Region"): lb = ELB("ELB") with Cluster("Services"): autoscaling = AutoScaling("autoscaling-group") svc_group = [EC2("web-01"), EC2("web-02")] lb >> autoscaling >> svc_group with Cluster("AMI"): docker = Docker("Docker") with Cluster("Docker Image"): app = Python("App") svc_group - docker docker - Edge(style="dotted") - app
from urllib.request import urlretrieve from diagrams import Cluster, Diagram from diagrams.custom import Custom from diagrams.aws.compute import ECS, AutoScaling, EC2 from diagrams.aws.database import ElastiCache from diagrams.aws.network import ELB, Route53 kafka_icon = "assets/kafka.png" with Diagram("Infrastructure architecture", show=False): dns = Route53("Smart-Foodies-Shop.com") lb = ELB("Load Balancer") scaler = AutoScaling("Auto Scaling Group") with Cluster("VPC"): svc_group = [ECS("Frontend"), EC2("Redis"), EC2("Backend")] queue = Custom("Kafka", kafka_icon) db = EC2("MySQL") dns >> lb >> scaler scaler >> svc_group svc_group >> db svc_group >> queue