Adam M. Lechnos

DevOps engineer with an Infosec Consulting and Finance hobbyist background.

AWS Cloud Development Kit (CDK) - Understanding the Node/Tree Relationship

17 Feb 2023 » aws, devops, cdk

Diagram

AWS Cloud Development Kit Tree/Node Diagram (draw.io viewer)

AWS Cloud Development Kit Tree/Node Diagram

Details

  • The AWS CDK is a tree/node relationship structure, requiring the initializing of the root node via the app = new.cdk.App() object, imported from the aws-cdk-lib CDK library. The object inherits the Stage object which in turn inherits the Construct object.
  • Subsequent AWS resources are instantiated Stack objects, such as the bucketStack = new BucketStack(app, 'BucketStack') instance created, which in turn inherits the Construct object.
  • Hence, each new instantiation of an AWS resource, is a child of the Construct, which is then added to the root Construct, app per the first scope argument for each instantiated resource’s constructor.
    • i.e., handlerStack = new HandlerStack(app, ‘HandlerStack’, extendedProps..)
  • Resouces created inside resources, such as the new LambdaFunction(this, 'LambdaFunction', FunctionProps) Lambda functions, contains the first argument this, for the scope parameter since this is the parent object, handlerStack, which inherits a Construct object.

To button up the tree node relationship, each object is inherited from Construst, which in turn is nested within each other via the scope parameter, either as this when scoping in as a child of a resource, such as handlerStack, or as app for each new instantiated resource. Each nested resource is scoped within it’s parent, and each resource is scoped within its root node, app.

Buy Me A Coffee