是否可以从堆栈中获取所有节点(cdk.ConstructNode
)?
我希望能够递归地迭代所有节点并检查其元数据。
谢谢!
答案 0 :(得分:0)
解决方案是使用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)
}
}
}