Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,10 @@ export class Distribution extends Resource implements IDistribution {
}

private validateWebAclId(webAclId: string) {
if (Token.isUnresolved(webAclId)) {
// Cannot validate unresolved tokens or non-string values at synth-time.
return;
}
if (webAclId.startsWith('arn:')) {
const webAclRegion = Stack.of(this).splitArn(webAclId, ArnFormat.SLASH_RESOURCE_NAME).region;
if (!Token.isUnresolved(webAclRegion) && webAclRegion !== 'us-east-1') {
Expand Down
14 changes: 13 additions & 1 deletion packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as iam from '../../aws-iam';
import * as kinesis from '../../aws-kinesis';
import * as lambda from '../../aws-lambda';
import * as s3 from '../../aws-s3';
import { App, Aws, Duration, Stack } from '../../core';
import { App, Aws, Duration, Stack, Token } from '../../core';
import {
AllowedMethods,
CfnDistribution,
Expand Down Expand Up @@ -1432,6 +1432,18 @@ describe('attachWebAclId', () => {
});
}).toThrow(/WebACL for CloudFront distributions must be created in the us-east-1 region; received ap-northeast-1/);
});

test('does not validate unresolved token webAclId', () => {
const origin = defaultOrigin();

const distribution = new Distribution(stack, 'MyDist', {
defaultBehavior: { origin },
webAclId: Token.asString({ Ref: 'SomeWebAcl' }), // unresolved token
});

// Should synthesize without error
Template.fromStack(stack);
});
});
});

Expand Down