Skip to content

Commit 4f067cb

Browse files
authored
fix(cloudfront): auto-generated cache policy name might conflict cross-region (#13737)
This commit changes the auto-generated name of the `CachePolicy` to include stack name and region, thus providing unique name for the `CachePolicy` account-wide. Closes #13629. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 41fd42b commit 4f067cb

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/@aws-cdk/aws-cloudfront/lib/cache-policy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Duration, Names, Resource, Token } from '@aws-cdk/core';
1+
import { Duration, Names, Resource, Stack, Token } from '@aws-cdk/core';
22
import { Construct } from 'constructs';
33
import { CfnCachePolicy } from './cloudfront.generated';
44

@@ -125,7 +125,7 @@ export class CachePolicy extends Resource implements ICachePolicy {
125125
physicalName: props.cachePolicyName,
126126
});
127127

128-
const cachePolicyName = props.cachePolicyName ?? Names.uniqueId(this);
128+
const cachePolicyName = props.cachePolicyName ?? `${Names.uniqueId(this)}-${Stack.of(this).region}`;
129129
if (!Token.isUnresolved(cachePolicyName) && !cachePolicyName.match(/^[\w-]+$/i)) {
130130
throw new Error(`'cachePolicyName' can only include '-', '_', and alphanumeric characters, got: '${props.cachePolicyName}'`);
131131
}

packages/@aws-cdk/aws-cloudfront/test/cache-policy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('CachePolicy', () => {
2424

2525
expect(stack).toHaveResource('AWS::CloudFront::CachePolicy', {
2626
CachePolicyConfig: {
27-
Name: 'StackCachePolicy0D6FCBC0',
27+
Name: 'StackCachePolicy0D6FCBC0-testregion',
2828
MinTTL: 0,
2929
DefaultTTL: 86400,
3030
MaxTTL: 31536000,

0 commit comments

Comments
 (0)