Amazon CloudFront is a global content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to your viewers with low latency and high transfer speeds. CloudFront fronts user provided content and caches it at edge locations across the world. Here's how you can use this construct: ```ts const sourceBucket = new s3.Bucket(this, 'Bucket'); const distribution = new cloudfront.CloudFrontWebDistribution(this, 'MyDistribution', { originConfigs: [ { s3OriginSource: { s3BucketSource: sourceBucket, }, behaviors : [ {isDefaultBehavior: true}], }, ], }); ``` This will create a CloudFront distribution that uses your S3Bucket as its origin. You can customize the distribution using additional properties from the CloudFrontWebDistributionProps interface.
import { CloudFrontWebDistribution } from 'aws-cdk-lib/aws-cloudfront';Or use the module namespace:
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
// cloudfront.CloudFrontWebDistributionConfiguration passed to the constructor as CloudFrontWebDistributionProps.
originConfigsRequiredSourceConfiguration[]The origin configurations for this distribution. Behaviors are a part of the origin.
commentOptionalstringA comment for this distribution in the CloudFront console.
Default: - No comment is added to distribution.
defaultRootObjectOptionalstringThe default object to serve.
Default: - "index.html" is served.
enabledOptionalbooleanEnable or disable the distribution.
Default: true
enableIpV6OptionalbooleanIf your distribution should have IPv6 enabled.
Default: true
errorConfigurationsOptionalCustomErrorResponseProperty[]How CloudFront should handle requests that are not successful (eg PageNotFound). By default, CloudFront does not replace HTTP status codes in the 4xx and 5xx range with custom error messages. CloudFront does not cache HTTP status codes.
Default: - No custom error configuration.
geoRestrictionOptionalGeoRestrictionControls the countries in which your content is distributed.
Default: No geo restriction
httpVersionOptionalHttpVersionThe max supported HTTP Versions.
Default: HttpVersion.HTTP2
loggingConfigOptionalLoggingConfigurationOptional - if we should enable logging. You can pass an empty object ({}) to have us auto create a bucket for logging. Omission of this property indicates no logging is to be enabled.
Default: - no logging is enabled by default.
priceClassOptionalPriceClassThe price class for the distribution (this impacts how many locations CloudFront uses for your distribution, and billing).
Default: PriceClass.PRICE_CLASS_100 the cheapest option for CloudFront is picked by default.
viewerCertificateOptionalViewerCertificateSpecifies whether you want viewers to use HTTP or HTTPS to request your objects, whether you're using an alternate domain name with HTTPS, and if so, if you're using AWS Certificate Manager (ACM) or a third-party certificate authority.
Default: ViewerCertificate.fromCloudFrontDefaultCertificate()
viewerProtocolPolicyOptionalViewerProtocolPolicyThe default viewer policy for incoming clients.
Default: RedirectToHTTPs
webACLIdOptionalstringUnique identifier that specifies the AWS WAF web ACL to associate with this CloudFront 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/473e64fd-f30b-4765-81a0-62ad96dd167a`. To specify a web ACL created using AWS WAF Classic, use the ACL ID, for example `473e64fd-f30b-4765-81a0-62ad96dd167a`.
Default: - No AWS Web Application Firewall web access control list (web ACL).
Everything you need to know about Amazon CloudFront on one page. HD quality, print-friendly.
Download Free Infographicaws-cloudfront