Skip to content

Commit 77ad145

Browse files
committed
use Names.uniqueResourceName instead of custom generateUniqueName
1 parent 915c40a commit 77ad145

File tree

1 file changed

+2
-19
lines changed
  • packages/aws-cdk-lib/aws-synthetics/lib

1 file changed

+2
-19
lines changed

packages/aws-cdk-lib/aws-synthetics/lib/group.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export class Group extends cdk.Resource implements IGroup {
125125

126126
constructor(scope: Construct, id: string, props: GroupProps = {}) {
127127
super(scope, id, {
128-
physicalName: props.groupName || cdk.Lazy.string({
129-
produce: () => this.generateUniqueName(),
128+
physicalName: props.groupName ?? cdk.Lazy.string({
129+
produce: () => cdk.Names.uniqueResourceName(this, { maxLength: 64 }),
130130
}),
131131
});
132132

@@ -175,21 +175,4 @@ export class Group extends cdk.Resource implements IGroup {
175175
public get canaries(): ICanary[] {
176176
return Array.from(this._canaries);
177177
}
178-
179-
/**
180-
* Generate a unique name for the group
181-
*/
182-
private generateUniqueName(): string {
183-
const uniqueId = cdk.Names.uniqueId(this);
184-
const maxLength = 64; // AWS limit for group names
185-
186-
if (uniqueId.length <= maxLength) {
187-
return uniqueId;
188-
}
189-
190-
// Truncate and add hash to ensure uniqueness
191-
const hash = cdk.Names.nodeUniqueId(this.node).slice(-8);
192-
const truncated = uniqueId.slice(0, maxLength - 9); // Leave room for hash and separator
193-
return `${truncated}-${hash}`;
194-
}
195178
}

0 commit comments

Comments
 (0)