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:
AReallyLonIdIsAlsoPrettyLongIGuess25040025
AReallyLoIdIsAlsoPrettyLongIGuess25040025
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
|
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; |
|
} |
|
} |
Should probably be reworked but that might result in yet again renaming functions.
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
Describe the bug
Creating a CloudFront Function without specifying
namecan result in non-deterministic naming when theNodeID 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:
AReallyLonIdIsAlsoPrettyLongIGuess25040025AReallyLoIdIsAlsoPrettyLongIGuess25040025for the name of the function.
Possible Solution
aws-cdk/packages/aws-cdk-lib/aws-cloudfront/lib/function.ts
Lines 198 to 205 in 3656a4c
Names.uniqueResourceNameshould 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