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
42 changes: 42 additions & 0 deletions packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@ export interface DistributionProps {
* @default false
*/
readonly publishAdditionalMetrics?: boolean;

/**
* Is the distribution being created a regular distribution or a multi-tenant distribution.
*
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront-readme.html#cloudfront-saas-manager-resources
*
* @default false
*/
readonly multiTenant?: boolean;

/**
* Configuration for a distribution tenant.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-distribution-tenantconfig.html
*
* @default - No special tenant configurations (undefined).
*/
readonly tenantConfig?: CfnDistribution.TenantConfigProperty;
}

/**
Expand Down Expand Up @@ -337,6 +355,8 @@ export class Distribution extends Resource implements IDistribution {
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);

this.validateMultiTenantConfig(props);

if (props.certificate) {
const certificateRegion = Stack.of(this).splitArn(props.certificate.certificateArn, ArnFormat.SLASH_RESOURCE_NAME).region;
if (!Token.isUnresolved(certificateRegion) && certificateRegion !== 'us-east-1') {
Expand Down Expand Up @@ -393,6 +413,8 @@ export class Distribution extends Resource implements IDistribution {
viewerCertificate: this.certificate ? this.renderViewerCertificate(this.certificate,
props.minimumProtocolVersion, props.sslSupportMethod) : undefined,
webAclId: Lazy.string({ produce: () => this.webAclId }),
connectionMode: props.multiTenant ? 'tenant-only' : 'direct',
tenantConfig: props.tenantConfig ?? undefined,
},
});

Expand Down Expand Up @@ -846,6 +868,26 @@ export class Distribution extends Resource implements IDistribution {
throw new ValidationError(`'httpVersion' must be ${validHttpVersions.join(' or ')} if 'enableGrpc' in 'defaultBehavior' or 'additionalBehaviors' is true, got ${this.httpVersion}`, this);
}
}

private validateMultiTenantConfig(props: DistributionProps) {
if (!props.multiTenant) {
if (props.tenantConfig) {
throw new ValidationError('tenantConfig is not supported for direct distributions', this);
}
} else {
if (props.domainNames) {
throw new ValidationError('domainNames may not be configured for multi-tenant distributions', this);
} if (props.enableIpv6) {
throw new ValidationError('enableIpv6 field is not supported for multi-tenant distributions, please use a connection group to configure IPV6 options', this);
} if (props.priceClass) {
throw new ValidationError('priceClass may not be configured for multi-tenant distributions', this);
} if (props.sslSupportMethod && props.sslSupportMethod == SSLMethod.VIP) {
throw new ValidationError( 'invalid SSL Method', this);
} if (props.defaultBehavior.smoothStreaming) {
throw new ValidationError( 'smoothStreaming not supported by multi-tenant distributions', this);
}
}
}
}

/** Maximum HTTP version to support */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export interface MTDProps {
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-cloudfront-distribution-tenantconfig.html
*
* @default - No special tenant configurations.
* @default - No special tenant configurations (undefined).
*/
readonly tenantConfig?: CfnDistribution.TenantConfigProperty;
}
Expand Down Expand Up @@ -364,7 +364,7 @@ export class MTDistribution extends Resource implements IMTDistribution {
props.minimumProtocolVersion, props.sslSupportMethod) : undefined,
webAclId: Lazy.string({ produce: () => this.webAclId }),
connectionMode: 'tenant-only',
tenantConfig: props.tenantConfig ?? {},
tenantConfig: props.tenantConfig ?? undefined,
},
});

Expand Down