Skip to content
Closed
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 @@ -394,6 +394,10 @@ export class Distribution extends Resource implements IDistribution {
this.httpVersion = props.httpVersion ?? HttpVersion.HTTP2;
this.validateGrpc(props.defaultBehavior);

if (props.minimumProtocolVersion && !this.certificate) {
Annotations.of(this).addWarningV2('@aws-cdk/aws-cloudfront:minProtocolVersionIgnored', 'The \'minimumProtocolVersion\' property is only applicable when a custom SSL/TLS certificate is configured. Without a certificate, CloudFront uses its default security policy.');
}

const originId = this.addOrigin(props.defaultBehavior.origin);
this.defaultBehavior = new CacheBehavior(originId, { pathPattern: '*', ...props.defaultBehavior });
if (props.additionalBehaviors) {
Expand Down
12 changes: 12 additions & 0 deletions packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1702,3 +1702,15 @@ describe('gRPC', () => {
}).toThrow(msg);
});
});

test('warns when minimumProtocolVersion is set without custom certificate', () => {
const testApp = new App();
const testStack = new Stack(testApp, 'Stack');
new Distribution(testStack, 'Dist', {
defaultBehavior: { origin: defaultOrigin() },
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2_2019,
});

const warnings = Annotations.fromStack(testStack).findWarning('*', Match.stringLikeRegexp('minimumProtocolVersion'));
expect(warnings.length).toBeGreaterThanOrEqual(1);
});
Loading