Networking with AWS CDK (Java) with Lombok, JGraphT and D3 js

Networking with AWS CDK (Java) with Lombok, JGraphT and D3 js

pingMeCdkTransitGatewayWGraph

Lately I made several deployments with AWS CDK. I used Typescript, Python and Java; I really enjoy working with the Java API because the constructor pattern is used which makes navigating the API easy, you find yourself less often in the documentation. Working with Lombok becomes natural and makes the stack implementation uniform with @lombok.Builder.

Because networking has a graph topology, it seemed interesting to me to incorporate the Jgraph library to generate the visual of a CDK application representing links between VPCs.

My POC starts from a JSON file representing my topology to be deployed.

infra.json

{
  "vpcs":[
    {
      "cidr": "10.0.1.0/24",
      "name": "vpc1",
      "links": ["vpc2","vpc3"]
    },
    {
      "cidr": "10.0.2.0/24",
      "name": "vpc2",
      "links": ["vpc1","vpc3"]
    },
    {
      "cidr": "10.0.3.0/24",
      "name": "vpc3",
      "links": ["vpc1","vpc2"]
    }
  ]
}        

NetworkTopologyService.java : Loads the definition and builds the topology.

VpcStack.java: builds the different VPCs, Subnets, Security Groups

InstanceStack.java: builds a bastion instance per VPC to test the links

TransitGatewayStack.java: builds the Transit Gateway and its attachments

RoutesToTransitGatewayStack.java: sets up the different routes between the VPCs

GraphPlotService.java: generates the Graphviz metadata that will be updated using D3 js in the index.html file in project root.

All links can be tested using AWS System Manager / Session Manager Service with Ping terminal app from one Bastion instance to others.

sh-4.2$ ping 10.0.1.9 -c 3
PING 10.0.1.9 (10.0.1.9) 56(84) bytes of data.
64 bytes from 10.0.1.9: icmp_seq=1 ttl=254 time=1.29 ms
64 bytes from 10.0.1.9: icmp_seq=2 ttl=254 time=0.603 ms
64 bytes from 10.0.1.9: icmp_seq=3 ttl=254 time=0.553 ms

--- 10.0.1.9 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2032ms
rtt min/avg/max/mdev = 0.553/0.817/1.295/0.338 ms        

This graph will be plot: png

ps: working on an extra regions implementation, a more useful use case.

Inspired by this article.

That’s what I mean when I say you are brilliant!

To view or add a comment, sign in

More articles by Stephane Charron

Others also viewed

Explore content categories