Skip to content

[cloudfront]: suport for MultiTenantDistribution creation via CDK #37536

@mattiLeBlanc

Description

@mattiLeBlanc

Describe the feature

Create Cloudfront Multi tenant distribution via cdk.

Use Case

I want to deploy all my cloudformation via CDK. Now I have to create the multitenant distribution manually.

Now I get ValidationError: Template format error: Unrecognized resource types: [AWS::CloudFront::MultiTenantDistribution] when I try the proposed solution below

Proposed Solution

It would be nice if this would be supported:

const name = `${this.props.applicationName}-website-manager`;

    const oac = new CfnOriginAccessControl(this, 'WebsiteOAC', {
      originAccessControlConfig: {
        name,
        originAccessControlOriginType: 's3',
        signingBehavior: 'always',
        signingProtocol: 'sigv4',
      },
    });

    // Multi-tenant distribution — parameters {{customerId}} and {{websiteId}} are substituted
    // per tenant at CreateDistributionTenant time.
    // NOTE: CfnResource property names mirror the CloudFront API shape.
    // Adjust if CloudFormation validation fails on first deploy.
    new CfnResource(this, 'WebsiteDistribution', {
      type: 'AWS::CloudFront::MultiTenantDistribution',
      properties: {
        MultiTenantDistributionConfig: {
          Name: name,
          Comment: name,
          Enabled: true,
          Origins: [{
            Id: 'S3Origin',
            DomainName: `${dataBucket.bucketName}.s3.${Stack.of(this).region}.amazonaws.com`,
            OriginPath: '/customers/{{customerId}}/websites/{{websiteId}}/dist',
            S3OriginConfig: { OriginAccessIdentity: '' },
            OriginAccessControlId: oac.attrId,
          }],
          DefaultCacheBehavior: {
            TargetOriginId: 'S3Origin',
            ViewerProtocolPolicy: 'redirect-to-https',
            CachePolicyId: '658327ea-f89d-4fab-a63d-7e88639e58f6', // Managed-CachingOptimized
            Compress: true,
          },
          CustomErrorResponses: [
            { ErrorCode: 403, ResponseCode: 200, ResponsePagePath: '/index.html' },
            { ErrorCode: 404, ResponseCode: 200, ResponsePagePath: '/index.html' },
          ],
          TenantConfig: {
            ParameterDefinitions: [
              { Name: 'customerId' },
              { Name: 'websiteId' },
            ],
          },
        },
      },
    });

    // Connection group — shared CloudFront entry point; each tenant domain routes via this group
    new CfnResource(this, 'WebsiteConnectionGroup', {
      type: 'AWS::CloudFront::ConnectionGroup',
      properties: {
        Name: name,
        Ipv6Enabled: true,
      },
    });

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS CDK Library version (aws-cdk-lib)

^2.248.0

AWS CDK CLI version

2.1100.1 (build db19110)

Environment details (OS name and version, etc.)

Macos 26.3.1 (a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-cloudfrontRelated to Amazon CloudFrontfeature-requestA feature should be added or improved.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions