Is it possible to get all nodes (cdk.ConstructNode) from a stack?
I want to be able to iterate all of the nodes recursively and check their metadata.
The solution is to use IAspect
import { IAspect, IConstruct } from '@aws-cdk/core'
import { LambdaWebpack } from './lambda-webpack'
/**
* Class that uses a visitor pattern to find all our Lambda functions and aggregate them in
* the `lambdas` property for access later.
*/
export class LambdaAggregator implements IAspect {
/**
* Gathers all lambdas from the stack in this property.
*/
public readonly lambdas: LambdaWebpack[] = []
public visit(node: IConstruct): void {
if (node instanceof LambdaWebpack) {
this.lambdas.push(node)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With