- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4.3k
feat(cloudfront): new L2 constructs for multi-tenant distribution, connection group, distribution tenant, and updated distribution L2 construct to support multi-tenant configurations #35225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            codyzhao2770
  wants to merge
  30
  commits into
  aws:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
codyzhao2770:saas-new-constructs
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    …and interface changes
Distribution
implemented connection group
done distribution tenant, other small changes
Saas new constructs
| This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. | 
    
      
        1 similar comment
      
    
  
    | This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state. | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      Labels
      
    beginning-contributor
  [Pilot] contributed between 0-2 PRs to the CDK 
  
    p2
  
    pr/needs-further-review
  PR requires additional review from our team specialists due to the scope or complexity of changes. 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Reason for this change
The latest Cloudfront feature release introduced the new SaaS Manager resource, including changes to the L2 Distribution construct allowing for Multi-Tenant Distribution (MTD) creation and new associated L1 constructs Distribution Tenant and Connection Group. However, the existing Cloudfront Distribution L2 construct currently only supports regular (direct) Distribution configurations. Creating an MTD must be done either through using the L1 construct CfnDistribution directly, or creating an L2 Distribution and accessing the underlying L1 construct, either of which is not optimal for user experience. Distribution Tenant and Connection Group are also only available as L1 constructs with limited functionality.
This pull request adds comprehensive support for AWS CloudFront MTDs, enabling developers to create and manage MTDs with associated tenants and connection groups. The implementation provides both a dedicated L2
MTDistributionclass and extends the existing L2Distributionclass to support MTDs, as well as new L2 constructsDistributionTenantandConnectionGroup.Description of changes
New Constructs Added
1. Multi-Tenant Distribution (
MTDistribution)This class was designed based on the existing
Distributionclass to maintain congruency as MTDs are still a type of Cloudfront Distribution.File:
packages/aws-cdk-lib/aws-cloudfront/lib/multi-tenant-distribution.tsPurpose: Dedicated construct for creating multi-tenant distributions
Key Features:
Automatically sets
connectionMode: 'tenant-only'Disables IPv6 by default (required for multi-tenant distributions)
MTDs do not support dedicated IP addresses, which is enabled by setting
sslSupportMethodtoSSLMethod.VIP. A validation was created for this:Supports all standard distribution features (metrics, functions, Lambda@Edge, policies)
The underlying L1 construct is configured accordingly for MTDs
Design Decisions:
MTDistributionis a stand-alone construct instead of extending the existing Distribution construct to accommodate for its distinct configuration restrictions, such as requiringdomainsNamesandipv6Enabledto be absent from the Cloudformation template. It also allows for future feature additions that may cause it to diverge from the regular Distribution.However, an MTD shares many identical customizations to regular Distributions. Existing implementations
HttpVersion, ViewerProtocolPolicy, SSLMethod, SecurityPolicyProtocol, AllowedMethods, CachedMethods, ErrorResponse, EdgeLambda, TenantConfigPropsfromDistributionwere used byMTDistributionThe
MTDistributionPropsinterface is identical toDistributionPropsbut withoutdomainNames,enableIpv6, andpriceClasswhich are features not supported by MTDs, and has the new propertytenantConfig, an MTD only customization2. Distribution Tenant (
DistributionTenant)File:
packages/aws-cdk-lib/aws-cloudfront/lib/distribution-tenant.tsPurpose: Manages individual tenants within a multi-tenant distribution
Key Features:
Associates domains with specific tenants
Supports custom certificates and managed certificate requests
Configurable geo-restrictions and WebACL overrides
Tenant-specific parameters and tags
Underlying L1 construct configuration:
Design Decisions:
Since this is a basic initial implementation of the Distribution Tenant construct, new interfaces
CustomizationProps,ManagedCertificateRequestProps, andParameterPropsused for definingDistributionTenantPropswere created that simply extend their corresponding Cfn interfaces without adding any changes. These should be simplified and given their own unique interface implementations in the future, notably forCustomizationProps, to simplify their usage and improve user experience.Further helper method implementations should also be considered, notably a method for retrieving a tenant's associated routing endpoint since tenants may be assigned the default Cloudfront connection group if the user does not assign their own, making the endpoint difficult to access dynamically.
Example Usage:
3. Connection Group (
ConnectionGroup)File:
packages/aws-cdk-lib/aws-cloudfront/lib/connection-group.tsPurpose: Manages connection groups for multi-tenant distributions
Key Features:
IPv6 configuration support
Anycast IP list integration
Tagging support
Routing endpoint management
Underlying L1 construct config:
Design Decisions:
Example Usage:
Distribution Class Updates
Updating the Distribution construct to support MTD creation is very similar to the MTD construct class implementation, adding appropriate interface properties and implementing checks to prevent illegal configurations whether the user was creating a regular distribution or MTD
File:
packages/aws-cdk-lib/aws-cloudfront/lib/distribution.tsChanges:
Added
connectionModeproperty (DIRECT|TENANT_ONLY) andtenantConfigtoDistributionPropsConnectionModeenumDesign Decisions
There were considerations of whether to update the existing current Distribution construct to support MTDs only, or to also create a dedicated MTD construct. I went the route of having both options available for users to maximize clarity with the dedicated construct, and to provide flexible options to use either construct.
Legal distribution configuration validation is already done by the Cloudformation API, however this requires users to wait for Cloudformation deployments to fail and return the error. This can be especially time consuming as there is a hard coded wait time for deployments involving Cloudfront Distributions. Implementing a validation function allows users to fix their configurations faster, especially considering the specificity of MTD and regular distribution configurations
Example Usage:
Description of how you validated changes
Unit Tests
Integration Testing:
Total of 22 new integration tests added covering all configurations for each construct and common workflow configurations
Multi-Tenant Distribution Tests (MTDistribution)
14 tests including full backward compatibility coverage
integ.mt-distribution-basic.ts- Basic MTDistribution test with IAM role permissions for invalidation and listinginteg.mt-distribution-additional-metrics.ts- Tests MTDistribution with additional CloudWatch metrics (origin latency, cache hit rate, error rates)integ.mt-distribution-default-metrics.ts- Tests MTDistribution with default CloudWatch metrics (requests, bytes, error rates)integ.mt-distribution-extensive.ts- Comprehensive MTDistribution test with logging, geo restrictions, HTTP version, and tenant config parametersinteg.mt-distribution-geo-restrictions.ts- Tests MTDistribution with geographic restrictions (US, GB allowlist)integ.mt-distribution-grpc.ts- Tests MTDistribution with gRPC support enabledinteg.mt-distribution-http-version.ts- Tests MTDistribution with different HTTP versions (1.1, 2, 2&3, 3)integ.mt-distribution-key-group.ts- Tests MTDistribution with trusted key groups for signed URLs/cookiesinteg.mt-distribution-lambda.ts- Tests MTDistribution with Lambda@Edge functionsinteg.mt-distribution-logbucket.ts- Tests MTDistribution with S3 logging bucket configurationinteg.mt-distribution-multiple-tenants.ts- Tests MTDistribution with multiple tenants using connection groups and certificatesinteg.mt-distribution-origin-id.ts- Tests MTDistribution with custom origin IDsinteg.mt-distribution-policies.ts- Tests MTDistribution with cache, origin request, and response headers policiesinteg.mt-distribution-with-webacl.ts- Tests MTDistribution with WAF WebACL attachmentDistribution Tenant Tests
3 tests covering all possible certificate configurations
integ.distribution-tenant-basic.ts- Basic DistributionTenant test with certificate and domain configurationinteg.distribution-tenant-custom-certificate.ts- Tests DistributionTenant with custom ACM certificate, connection group, WebACL, and geo restrictionsinteg.distribution-tenant-managed-certificate.ts- Tests DistributionTenant with CloudFront-managed certificate and DNS validationDistribution Tests
3 new tests covering MTD creation configurations
integ.distribution-tenantmode-basic.ts- Basic Distribution with TENANT_ONLY connection modeinteg.distribution-tenantmode-validation.ts- Tests Distribution in tenant mode with validation for supported featuresinteg.distribution-tenantmode-with-config.ts- Tests Distribution in tenant mode with tenant configuration parametersConnection Group Tests
2 tests with comprehensive configuration coverage
integ.connection-group-basic.ts- Basic ConnectionGroup test with minimal configurationinteg.connection-group-extensive.ts- Comprehensive ConnectionGroup test with anycast IP list, tags, and full configuration optionsManual Testing:
Core Implementation Files
packages/aws-cdk-lib/aws-cloudfront/lib/multi-tenant-distribution.ts(NEW)packages/aws-cdk-lib/aws-cloudfront/lib/distribution-tenant.ts(NEW)packages/aws-cdk-lib/aws-cloudfront/lib/connection-group.ts(NEW)packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts(MODIFIED)Note: Most of the files changed come from integration test snapshots
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license