# CloudFrontWebDistribution

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.

Extends: Construct › Resource › CloudFrontWebDistribution
Implements: IResource, IDistribution, IEnvironmentAware, IDistributionRef, IConstruct, IDependable

- CloudFormation: [`AWS::CloudFront::Distribution`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-cloudfront-distribution.html)
- L1 type: [`CfnDistribution`](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.CfnDistribution.html)
- Source: [`aws-cloudfront/lib/web-distribution.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-cloudfront/lib/web-distribution.ts#L760)
- Type last changed: v2.227.0 · 21 Nov 2025

## Example

```ts
declare const sourceBucket: s3.Bucket;
const viewerCertificate = cloudfront.ViewerCertificate.fromIamCertificate('MYIAMROLEIDENTIFIER', {
  aliases: ['MYALIAS'],
});

new cloudfront.CloudFrontWebDistribution(this, 'MyCfWebDistribution', {
  originConfigs: [
    {
      s3OriginSource: {
        s3BucketSource: sourceBucket,
      },
      behaviors : [ {isDefaultBehavior: true} ],
    },
  ],
  viewerCertificate: viewerCertificate,
});
```

## Initializer

```ts
new CloudFrontWebDistribution(scope: Construct, id: string, props: CloudFrontWebDistributionProps)
```

## Construct Props

- `comment`: string — A comment for this distribution in the CloudFront console.

  **Default:** No comment is added to distribution.

- `defaultRootObject`: string — The default object to serve.

  **Default:** "index.html" is served.

- `enabled`: boolean = true — Enable or disable the distribution.

- `enableIpV6`: boolean = true — If your distribution should have IPv6 enabled.

- `errorConfigurations`: [CfnDistribution.CustomErrorResponseProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.CfnDistribution.CustomErrorResponseProperty.html)[] — How CloudFront should handle requests that are not successful (eg PageNotFound).

  **Default:** No custom error configuration.

  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.

- `geoRestriction`: [GeoRestriction](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.GeoRestriction.html) — Controls the countries in which your content is distributed.

  **Default:** No geo restriction

- `httpVersion`: [HttpVersion](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.HttpVersion.html) = HttpVersion.HTTP2 — The HTTP version(s) to enable for viewers communicating with CloudFront.

- `loggingConfig`: [LoggingConfiguration](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.LoggingConfiguration.html) — Optional - if we should enable logging.

  **Default:** no logging is enabled by default.

  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.

- `originConfigs`: [SourceConfiguration](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.SourceConfiguration.html)[] (required) — The origin configurations for this distribution.

  Behaviors are a part of the origin.

- `priceClass`: [PriceClass](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.PriceClass.html) — The 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.

- `viewerCertificate`: [ViewerCertificate](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.ViewerCertificate.html) — Specifies 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()

- `viewerProtocolPolicy`: [ViewerProtocolPolicy](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.ViewerProtocolPolicy.html) = RedirectToHTTPs — The default viewer policy for incoming clients.

- `webACLId`: string — Unique identifier that specifies the AWS WAF web ACL to associate with this CloudFront distribution.

  **Default:** No AWS Web Application Firewall web access control list (web ACL).

  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`.

## Properties

- `distributionArn`: string (required) — The distribution ARN for this distribution.

- `distributionDomainName`: string (required) — The domain name created by CloudFront for this distribution.

  If you are using aliases for your distribution, this is the domainName your DNS records should point to.
  (In Route53, you could create an ALIAS record to this value, for example.)

- `distributionId`: string (required) — The distribution ID for this distribution.

- `distributionRef`: [DistributionReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.DistributionReference.html) (required) — A reference to a Distribution resource.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `grants`: [DistributionGrants](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.DistributionGrants.html) (required) — Collection of grant methods for a Distribution.

- `loggingBucket`: [IBucket](/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) — The logging bucket for this CloudFront distribution.

  If logging is not enabled for this distribution - this property will be undefined.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

## Methods

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromDistributionAttributes(scope: Construct, id: string, attrs: CloudFrontWebDistributionAttributes): IDistribution` (static) — Creates a construct that represents an external (imported) distribution.

- `grant(identity: IGrantable, ...actions: string[]): Grant` — Adds an IAM policy statement associated with this distribution to an IAM principal's policy.

  [disable-awslint:no-grants]

  **Parameters**

  - `identity` — The principal.
  - `actions` — The set of actions to allow (i.e. "cloudfront:ListInvalidations").

- `grantCreateInvalidation(identity: IGrantable): Grant` — Grant to create invalidations for this bucket to an IAM principal (Role/Group/User).

  [disable-awslint:no-grants]

  **Parameters**

  - `identity` — The principal.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
