diff --git a/packages/@aws-cdk/aws-logs/lib/policy.ts b/packages/@aws-cdk/aws-logs/lib/policy.ts index ed150fa12e9cb..4032d17488931 100644 --- a/packages/@aws-cdk/aws-logs/lib/policy.ts +++ b/packages/@aws-cdk/aws-logs/lib/policy.ts @@ -46,7 +46,7 @@ export class ResourcePolicy extends Resource { physicalName: props?.resourcePolicyName, }); - new CfnResourcePolicy(this, 'ResourcePolicy', { + const l1 = new CfnResourcePolicy(this, 'ResourcePolicy', { policyName: Lazy.string({ produce: () => props?.resourcePolicyName ?? Names.uniqueId(this), }), @@ -55,6 +55,8 @@ export class ResourcePolicy extends Resource { }), }); + this.node.defaultChild = l1; + if (props?.policyStatements) { this.document.addStatements(...props.policyStatements); } diff --git a/packages/@aws-cdk/aws-logs/test/policy.test.ts b/packages/@aws-cdk/aws-logs/test/policy.test.ts index 8ffb66ab8eb29..325d9ac059a85 100644 --- a/packages/@aws-cdk/aws-logs/test/policy.test.ts +++ b/packages/@aws-cdk/aws-logs/test/policy.test.ts @@ -49,4 +49,15 @@ describe('resource policy', () => { PolicyName: 'ResourcePolicy', }); }); + + test('ResourcePolicy has a defaultChild', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const resourcePolicy = new ResourcePolicy(stack, 'ResourcePolicy'); + + // THEN + expect(resourcePolicy.node.defaultChild).toBeDefined(); + }); });