L3-level cdk constructs for DMS
Project description
CDK Arch
This library aims at providing a way to autogenerate architectural diagrams for CDK projects.
This library is written using the wonderful projen framework.
Installation
The library is available on npmjs.com and can be installed using:
npm i cdk-arch
And on pypi:
pip install cdk-arch
Usage Examples
As an example, let's consider the following CDK app:
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
export class ExampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const bucket = new s3.Bucket(this, 'Bucket');
const lfunction = new lambda.Function(this, 'Lambda', {
...
});
}
}
const app = new cdk.App();
new ExampleStack(app, 'ExampleStack', {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: 'eu-west-1',
},
});
and imagine that in the diagram we want to show the bucket, the lambda function and an arrow connecting the two. This can be accomplished by changing the code as follows:
export class ExampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const bucket = new s3.Bucket(this, 'Bucket');
const lfunction = new lambda.Function(this, 'Lambda', {
runtime: lambda.Runtime.NODEJS_20_X,
handler: 'index.handler',
code: lambda.Code.fromInline(`
exports.handler = async function(event) {
console.log('event', event);
return {
statusCode: 200,
body: JSON.stringify({ message: 'Hello from Lambda!' }),
};
};
`),
environment: {
BUCKET_NAME: bucket.bucketName,
},
});
// We add some metadata to the resources to be able to position them in the diagram
bucket.node.addMetadata('CDKArch Element', { x: 0, y: 0 });
lfunction.node.addMetadata('CDKArch Element', { x: 300, y: 0 });
// We add a connection between the bucket and the lambda function
bucket.node.addMetadata('CDKArch Connection', { startId: bucket.node.id, endId: lfunction.node.id });
}
}
const app = new cdk.App();
new ExampleStack(app, 'ExampleStack', {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: 'eu-west-1',
},
});
const sketchbuilder = new SketchBuilder();
Aspects.of(app).add(sketchbuilder);
app.synth();
sketchbuilder.exportToFile(filepath);
where we added some metadata to the resources to instruct the SketchBuilder to position two icons in the diagram and a connection between the two, and we added an aspect to the app to instruct the SketchBuilder to generate it when the app is synthetized.
This is the resulting diagram:
Customizing the diagram
Positioning the resources
The position of the resources in the diagram can be customized using the 'x' and 'y' fields in the metadata of the node:
bucket.node.addMetadata('CDKArch Element', { x: 100, y: 200 });
Name of the resouces
By default, the name of the resources is the id of the node. This can be customized by adding a 'text' field to the metadata of the node:
bucket.node.addMetadata('CDKArch Element', { x: 100, y: 200, text: 'Overriding the bucket name' });
Contributors
Matteo Giani matteo.giani.87@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cdk-arch-0.0.0.tar.gz
.
File metadata
- Download URL: cdk-arch-0.0.0.tar.gz
- Upload date:
- Size: 165.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3743b5763d3953861e6cbec3ca2c553dc0d9a02cf13aafdcf1039df05984c361 |
|
MD5 | 94def7fdd1bd661d1bc556f8bbc9f203 |
|
BLAKE2b-256 | df0383886b1e975d8e4be4cfe76ef27974b4376f64174206c58dcaa1b519f7be |
File details
Details for the file cdk_arch-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: cdk_arch-0.0.0-py3-none-any.whl
- Upload date:
- Size: 163.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59d69f84a14524e4fb0c2d6bd27573d397c35d2b9d1ef051b504fa10e977c725 |
|
MD5 | 8a1bfce6f5b8859ae34db5ad5927054f |
|
BLAKE2b-256 | ddfd44680270a25ca1c3e88697c7add9259e8a98203b5ed58239b614a5fb6648 |