-
Notifications
You must be signed in to change notification settings - Fork 4.5k
(cloudfront): Function name is created non-deterministically #28629
Copy link
Copy link
Closed
Labels
@aws-cdk/aws-cloudfrontRelated to Amazon CloudFrontRelated to Amazon CloudFrontbugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp2
Description
Describe the bug
Creating a CloudFront Function without specifying name can result in non-deterministic naming when the Node ID is relatively long. This results in unexpected function renames.
Expected Behavior
The method used to create a CloudFront Function name should be deterministic, predicable, and stable.
Current Behavior
The name of Functions is unstable, resulting in resource renames and snapshot failures.
Reproduction Steps
Run the following sample integration test several times. See that eventually it bounces between:
AReallyLonIdIsAlsoPrettyLongIGuess25040025AReallyLoIdIsAlsoPrettyLongIGuess25040025
for the name of the function.
import * as cdk from 'aws-cdk-lib';
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
import * as integ from '@aws-cdk/integ-tests-alpha';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'A-Really-Long-Stack-Name-Example');
const fn = new cloudfront.Function(stack, 'ExampleFunctionIdIsAlsoPrettyLongIGuess', {
code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
});
new integ.IntegTest(app, 'FunctionNameLong', {
testCases: [stack],
});Possible Solution
aws-cdk/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts
Lines 198 to 205 in 3656a4c
| private generateName(): string { | |
| const name = Stack.of(this).region + Names.uniqueId(this); | |
| if (name.length > 64) { | |
| return name.substring(0, 32) + name.substring(name.length - 32); | |
| } | |
| return name; | |
| } | |
| } |
Names.uniqueResourceName should probably be used instead.
Additional Information/Context
This is also causing the failure on #28571
CDK CLI Version
2.118.0
Framework Version
2.118.0
Node.js Version
v20.2.0
OS
Linux
Language
TypeScript
Language Version
No response
Other information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-cloudfrontRelated to Amazon CloudFrontRelated to Amazon CloudFrontbugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp2