interface DistributionConfigProperty
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.CloudFront.CfnDistribution.DistributionConfigProperty |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#CfnDistribution_DistributionConfigProperty |
![]() | software.amazon.awscdk.services.cloudfront.CfnDistribution.DistributionConfigProperty |
![]() | aws_cdk.aws_cloudfront.CfnDistribution.DistributionConfigProperty |
![]() | aws-cdk-lib » aws_cloudfront » CfnDistribution » DistributionConfigProperty |
A distribution configuration.
Example
// Create the simple Origin
const myBucket = new s3.Bucket(this, 'myBucket');
const s3Origin = origins.S3BucketOrigin.withOriginAccessControl(myBucket, {
originAccessLevels: [cloudfront.AccessLevel.READ, cloudfront.AccessLevel.LIST],
});
// Create the Distribution construct
const myMultiTenantDistribution = new cloudfront.Distribution(this, 'cf-hosted-distribution', {
defaultBehavior: {
origin: s3Origin,
},
defaultRootObject: 'index.html', // recommended to specify
});
// Access the underlying L1 CfnDistribution to configure SaaS Manager properties which are not yet available in the L2 Distribution construct
const cfnDistribution = myMultiTenantDistribution.node.defaultChild as cloudfront.CfnDistribution;
const defaultCacheBehavior: cloudfront.CfnDistribution.DefaultCacheBehaviorProperty = {
targetOriginId: myBucket.bucketArn,
viewerProtocolPolicy: 'allow-all',
compress: false,
allowedMethods: ['GET', 'HEAD'],
cachePolicyId: cloudfront.CachePolicy.CACHING_OPTIMIZED.cachePolicyId
};
// Create the updated distributionConfig
const distributionConfig: cloudfront.CfnDistribution.DistributionConfigProperty = {
defaultCacheBehavior: defaultCacheBehavior,
enabled: true,
// the properties below are optional
connectionMode: 'tenant-only',
origins: [
{
id: myBucket.bucketArn,
domainName: myBucket.bucketDomainName,
s3OriginConfig: {},
originPath: "/{{tenantName}}"
},
],
tenantConfig: {
parameterDefinitions: [
{
definition: {
stringSchema: {
required: false,
// the properties below are optional
comment: 'tenantName',
defaultValue: 'root',
},
},
name: 'tenantName',
},
],
},
};
// Override the distribution configuration to enable multi-tenancy.
cfnDistribution.distributionConfig = distributionConfig;
// Create a connection group so we have access to the RoutingEndpoint associated with the tenant we are about to create
const connectionGroup = new cloudfront.CfnConnectionGroup(this, 'self-hosted-connection-group', {
enabled: true,
ipv6Enabled: true,
name: 'self-hosted-connection-group',
});
// Export the RoutingEndpoint, skip this step if you'd prefer to fetch it from the CloudFront console or via Cloudfront.ListConnectionGroups API
new CfnOutput(this, 'RoutingEndpoint', {
value: connectionGroup.attrRoutingEndpoint,
description: 'CloudFront Routing Endpoint to be added to my hosted zone CNAME records',
});
// Create a distribution tenant with a self-hosted domain.
const selfHostedTenant = new cloudfront.CfnDistributionTenant(this, 'self-hosted-tenant', {
distributionId: myMultiTenantDistribution.distributionId,
connectionGroupId: connectionGroup.attrId,
name: 'self-hosted-tenant',
domains: ['self-hosted-tenant.my.domain.com'],
enabled: true,
managedCertificateRequest: {
primaryDomainName: 'self-hosted-tenant.my.domain.com',
validationTokenHost: 'self-hosted',
},
});
Properties
Name | Type | Description |
---|---|---|
default | IResolvable | Default | A complex type that describes the default cache behavior if you don't specify a CacheBehavior element or if files don't match any of the values of PathPattern in CacheBehavior elements. |
enabled | boolean | IResolvable | From this field, you can enable or disable the selected distribution. |
aliases? | string[] | > This field only supports standard distributions. |
anycast | string | > To use this field for a multi-tenant distribution, use a connection group instead. |
cache | IResolvable | IResolvable | Cache [] | A complex type that contains zero or more CacheBehavior elements. |
cnam | string[] | An alias for the CloudFront distribution's domain name. |
comment? | string | A comment to describe the distribution. |
connection | string | This field specifies whether the connection mode is through a standard distribution (direct) or a multi-tenant distribution with distribution tenants (tenant-only). |
continuous | string | > This field only supports standard distributions. |
custom | IResolvable | IResolvable | Custom [] | A complex type that controls the following:. |
custom | IResolvable | Legacy | The user-defined HTTP server that serves as the origin for content that CloudFront distributes. |
default | string | When a viewer requests the root URL for your distribution, the default root object is the object that you want CloudFront to request from your origin. |
http | string | (Optional) Specify the HTTP version(s) that you want viewers to use to communicate with CloudFront . |
ipv6 | boolean | IResolvable | > To use this field for a multi-tenant distribution, use a connection group instead. |
logging? | IResolvable | Logging | A complex type that controls whether access logs are written for the distribution. |
origin | IResolvable | Origin | A complex type that contains information about origin groups for this distribution. |
origins? | IResolvable | IResolvable | Origin [] | A complex type that contains information about origins for this distribution. |
price | string | > This field only supports standard distributions. |
restrictions? | IResolvable | Restrictions | A complex type that identifies ways in which you want to restrict distribution of your content. |
s3 | IResolvable | Legacy | The origin as an Amazon S3 bucket. |
staging? | boolean | IResolvable | > This field only supports standard distributions. |
tenant | IResolvable | Tenant | > This field only supports multi-tenant distributions. |
viewer | IResolvable | Viewer | A complex type that determines the distribution's SSL/TLS configuration for communicating with viewers. |
web | string | > Multi-tenant distributions only support AWS WAF V2 web ACLs. |
defaultCacheBehavior
Type:
IResolvable
|
Default
A complex type that describes the default cache behavior if you don't specify a CacheBehavior
element or if files don't match any of the values of PathPattern
in CacheBehavior
elements.
You must create exactly one default cache behavior.
enabled
Type:
boolean |
IResolvable
From this field, you can enable or disable the selected distribution.
aliases?
Type:
string[]
(optional)
This field only supports standard distributions.
You can't specify this field for multi-tenant distributions. For more information, see Unsupported features for SaaS Manager for Amazon CloudFront in the Amazon CloudFront Developer Guide .
A complex type that contains information about CNAMEs (alternate domain names), if any, for this distribution.
anycastIpListId?
Type:
string
(optional)
To use this field for a multi-tenant distribution, use a connection group instead.
For more information, see ConnectionGroup .
ID of the Anycast static IP list that is associated with the distribution.
cacheBehaviors?
Type:
IResolvable
|
IResolvable
|
Cache
[]
(optional)
A complex type that contains zero or more CacheBehavior
elements.
cnamEs?
Type:
string[]
(optional)
An alias for the CloudFront distribution's domain name.
This property is legacy. We recommend that you use Aliases instead.
comment?
Type:
string
(optional, default: "")
A comment to describe the distribution.
The comment cannot be longer than 128 characters.
connectionMode?
Type:
string
(optional)
This field specifies whether the connection mode is through a standard distribution (direct) or a multi-tenant distribution with distribution tenants (tenant-only).
continuousDeploymentPolicyId?
Type:
string
(optional)
This field only supports standard distributions.
You can't specify this field for multi-tenant distributions. For more information, see Unsupported features for SaaS Manager for Amazon CloudFront in the Amazon CloudFront Developer Guide .
The identifier of a continuous deployment policy. For more information, see CreateContinuousDeploymentPolicy
.
customErrorResponses?
Type:
IResolvable
|
IResolvable
|
Custom
[]
(optional)
A complex type that controls the following:.
- Whether CloudFront replaces HTTP status codes in the 4xx and 5xx range with custom error messages before returning the response to the viewer.
- How long CloudFront caches HTTP status codes in the 4xx and 5xx range.
For more information about custom error pages, see Customizing Error Responses in the Amazon CloudFront Developer Guide .
customOrigin?
Type:
IResolvable
|
Legacy
(optional)
The user-defined HTTP server that serves as the origin for content that CloudFront distributes.
This property is legacy. We recommend that you use Origin instead.
defaultRootObject?
Type:
string
(optional, default: "")
When a viewer requests the root URL for your distribution, the default root object is the object that you want CloudFront to request from your origin.
For example, if your root URL is https://www.example.com
, you can specify CloudFront to return the index.html
file as the default root object. You can specify a default root object so that viewers see a specific file or object, instead of another object in your distribution (for example, https://www.example.com/product-description.html
). A default root object avoids exposing the contents of your distribution.
You can specify the object name or a path to the object name (for example, index.html
or exampleFolderName/index.html
). Your string can't begin with a forward slash ( /
). Only specify the object name or the path to the object.
If you don't want to specify a default root object when you create a distribution, include an empty DefaultRootObject
element.
To delete the default root object from an existing distribution, update the distribution configuration and include an empty DefaultRootObject
element.
To replace the default root object, update the distribution configuration and specify the new object.
For more information about the default root object, see Specify a default root object in the Amazon CloudFront Developer Guide .
httpVersion?
Type:
string
(optional, default: "http1.1")
(Optional) Specify the HTTP version(s) that you want viewers to use to communicate with CloudFront .
The default value for new distributions is http1.1
.
For viewers and CloudFront to use HTTP/2, viewers must support TLSv1.2 or later, and must support Server Name Indication (SNI).
For viewers and CloudFront to use HTTP/3, viewers must support TLSv1.3 and Server Name Indication (SNI). CloudFront supports HTTP/3 connection migration to allow the viewer to switch networks without losing connection. For more information about connection migration, see Connection Migration at RFC 9000. For more information about supported TLSv1.3 ciphers, see Supported protocols and ciphers between viewers and CloudFront .
ipv6Enabled?
Type:
boolean |
IResolvable
(optional)
To use this field for a multi-tenant distribution, use a connection group instead.
For more information, see ConnectionGroup .
If you want CloudFront to respond to IPv6 DNS requests with an IPv6 address for your distribution, specify true
. If you specify false
, CloudFront responds to IPv6 DNS requests with the DNS response code NOERROR
and with no IP addresses. This allows viewers to submit a second request, for an IPv4 address for your distribution.
In general, you should enable IPv6 if you have users on IPv6 networks who want to access your content. However, if you're using signed URLs or signed cookies to restrict access to your content, and if you're using a custom policy that includes the IpAddress
parameter to restrict the IP addresses that can access your content, don't enable IPv6. If you want to restrict access to some content by IP address and not restrict access to other content (or restrict access but not by IP address), you can create two distributions. For more information, see Creating a Signed URL Using a Custom Policy in the Amazon CloudFront Developer Guide .
If you're using an Amazon Route 53 AWS Integration alias resource record set to route traffic to your CloudFront distribution, you need to create a second alias resource record set when both of the following are true:
- You enable IPv6 for the distribution
- You're using alternate domain names in the URLs for your objects
For more information, see Routing Traffic to an Amazon CloudFront Web Distribution by Using Your Domain Name in the Amazon Route 53 AWS Integration Developer Guide .
If you created a CNAME resource record set, either with Amazon Route 53 AWS Integration or with another DNS service, you don't need to make any changes. A CNAME record will route traffic to your distribution regardless of the IP address format of the viewer request.
logging?
Type:
IResolvable
|
Logging
(optional)
A complex type that controls whether access logs are written for the distribution.
For more information about logging, see Access Logs in the Amazon CloudFront Developer Guide .
originGroups?
Type:
IResolvable
|
Origin
(optional)
A complex type that contains information about origin groups for this distribution.
Specify a value for either the Origins
or OriginGroups
property.
origins?
Type:
IResolvable
|
IResolvable
|
Origin
[]
(optional)
A complex type that contains information about origins for this distribution.
Specify a value for either the Origins
or OriginGroups
property.
priceClass?
Type:
string
(optional, default: "PriceClass_All")
This field only supports standard distributions.
You can't specify this field for multi-tenant distributions. For more information, see Unsupported features for SaaS Manager for Amazon CloudFront in the Amazon CloudFront Developer Guide .
The price class that corresponds with the maximum price that you want to pay for CloudFront service. If you specify PriceClass_All
, CloudFront responds to requests for your objects from all CloudFront edge locations.
If you specify a price class other than PriceClass_All
, CloudFront serves your objects from the CloudFront edge location that has the lowest latency among the edge locations in your price class. Viewers who are in or near regions that are excluded from your specified price class may encounter slower performance.
For more information about price classes, see Choosing the Price Class for a CloudFront Distribution in the Amazon CloudFront Developer Guide . For information about CloudFront pricing, including how price classes (such as Price Class 100) map to CloudFront regions, see Amazon CloudFront Pricing .
restrictions?
Type:
IResolvable
|
Restrictions
(optional)
A complex type that identifies ways in which you want to restrict distribution of your content.
s3Origin?
Type:
IResolvable
|
Legacy
(optional)
The origin as an Amazon S3 bucket.
This property is legacy. We recommend that you use Origin instead.
staging?
Type:
boolean |
IResolvable
(optional)
This field only supports standard distributions.
You can't specify this field for multi-tenant distributions. For more information, see Unsupported features for SaaS Manager for Amazon CloudFront in the Amazon CloudFront Developer Guide .
A Boolean that indicates whether this is a staging distribution. When this value is true
, this is a staging distribution. When this value is false
, this is not a staging distribution.
tenantConfig?
Type:
IResolvable
|
Tenant
(optional)
This field only supports multi-tenant distributions.
You can't specify this field for standard distributions. For more information, see Unsupported features for SaaS Manager for Amazon CloudFront in the Amazon CloudFront Developer Guide .
A distribution tenant configuration.
viewerCertificate?
Type:
IResolvable
|
Viewer
(optional)
A complex type that determines the distribution's SSL/TLS configuration for communicating with viewers.
webAclId?
Type:
string
(optional, default: "")
Multi-tenant distributions only support AWS WAF V2 web ACLs.
A unique identifier that specifies the AWS WAF web ACL, if any, to associate with this distribution. To specify a web ACL created using the latest version of AWS WAF , use the ACL ARN, for example arn:aws:wafv2:us-east-1:123456789012:global/webacl/ExampleWebACL/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111
. To specify a web ACL created using AWS WAF Classic, use the ACL ID, for example a1b2c3d4-5678-90ab-cdef-EXAMPLE11111
.
AWS WAF is a web application firewall that lets you monitor the HTTP and HTTPS requests that are forwarded to CloudFront, and lets you control access to your content. Based on conditions that you specify, such as the IP addresses that requests originate from or the values of query strings, CloudFront responds to requests either with the requested content or with an HTTP 403 status code (Forbidden). You can also configure CloudFront to return a custom error page when a request is blocked. For more information about AWS WAF , see the AWS WAF Developer Guide .