Skip to content
Open
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
14 changes: 14 additions & 0 deletions packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,20 @@ export class Distribution extends Resource implements IDistribution {
}
}

if (props.minimumProtocolVersion && !props.certificate) {
Annotations.of(this).addWarningV2(
'@aws-cdk/aws-cloudfront:minimumProtocolVersionWithoutCertificate',
'Setting \'minimumProtocolVersion\' without a \'certificate\' has no effect. The distribution will use the CloudFront default certificate with a fixed security policy.',
);
}

if (props.sslSupportMethod && !props.certificate) {
Annotations.of(this).addWarningV2(
'@aws-cdk/aws-cloudfront:sslSupportMethodWithoutCertificate',
'Setting \'sslSupportMethod\' without a \'certificate\' has no effect. The distribution will use the CloudFront default certificate.',
);
}

this.httpVersion = props.httpVersion ?? HttpVersion.HTTP2;
this.validateGrpc(props.defaultBehavior);

Expand Down
31 changes: 31 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 @@ -534,6 +534,37 @@ describe('certificates', () => {
},
});
});

test('warns when minimumProtocolVersion is set without a certificate', () => {
new Distribution(stack, 'Dist', {
defaultBehavior: { origin: defaultOrigin() },
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2016,
});

Annotations.fromStack(stack).hasWarning('/Stack/Dist', Match.stringLikeRegexp('.*minimumProtocolVersion.*without.*certificate.*'));
});

test('warns when sslSupportMethod is set without a certificate', () => {
new Distribution(stack, 'Dist', {
defaultBehavior: { origin: defaultOrigin() },
sslSupportMethod: SSLMethod.SNI,
});

Annotations.fromStack(stack).hasWarning('/Stack/Dist', Match.stringLikeRegexp('.*sslSupportMethod.*without.*certificate.*'));
});

test('does not warn about minimumProtocolVersion when certificate is provided', () => {
const certificate = acm.Certificate.fromCertificateArn(stack, 'Cert', 'arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012');

new Distribution(stack, 'Dist', {
defaultBehavior: { origin: defaultOrigin() },
domainNames: ['example.com'],
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2016,
certificate,
});

Annotations.fromStack(stack).hasNoWarning('/Stack/Dist', Match.stringLikeRegexp('.*minimumProtocolVersion.*'));
});
});

describe('custom error responses', () => {
Expand Down
Loading