Skip to content

Commit

Permalink
Update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Gama committed Jun 11, 2024
1 parent 1ee9a97 commit 0b5f603
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/aws-cdk-lib/aws-cloudfront/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,14 @@ export class Function extends Resource implements IFunction {
}

private generateName(): string {
return Stack.of(this).region + Lazy.string({
produce: () => Names.uniqueResourceName(this, { maxLength: 40, allowedSpecialCharacters: '-_' }),
});
// const name = Stack.of(this).region + Names.uniqueId(this);
const maxNameLength = 64 - '${Token[AWS.Region.00]}'.length;
const nameId = Names.uniqueId(this);
if (nameId.length > maxNameLength) {
const splicePoint = Math.floor(maxNameLength / 2);
return Stack.of(this).region + nameId.substring(0, splicePoint) + nameId.substring(nameId.length - splicePoint);
}
return Stack.of(this).region + nameId;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('CloudFront Function', () => {
{
Ref: 'AWS::Region',
},
'CdkTestWithALongoudFrontFunction302260D0',
'CdkTestWithALongNamerontFunction302260D0',
],
],
},
Expand Down

0 comments on commit 0b5f603

Please sign in to comment.