diff --git a/src/fixPathsMetadataAspect.ts b/src/fixPathsMetadataAspect.ts index 24e3cec..cae03fb 100644 --- a/src/fixPathsMetadataAspect.ts +++ b/src/fixPathsMetadataAspect.ts @@ -3,12 +3,11 @@ import {IConstruct} from 'constructs'; export class FixPathsMetadataAspect implements IAspect { public visit(node: IConstruct): void { - const possibleL1 = node.node.defaultChild ? node.node.defaultChild : node; - if (possibleL1 instanceof CfnResource && node.node.path) { + if (node instanceof CfnResource && typeof node.getMetadata('aws:cdk:path') === 'string') { const stackId = Stack.of(node).node.id; - const parts = node.node.path.split('/'); + const parts = (node.getMetadata('aws:cdk:path') as string).split('/'); if (parts.indexOf(stackId) !== -1) { - possibleL1.addMetadata('aws:cdk:path', parts.slice(parts.indexOf(stackId)).join('/')); + node.addMetadata('aws:cdk:path', parts.slice(parts.indexOf(stackId)).join('/')); } } }