aws-cdk-lib.aws_cloudfront.CachePolicyProps

interface CachePolicyProps

LanguageType name
.NETAmazon.CDK.AWS.CloudFront.CachePolicyProps
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#CachePolicyProps
Javasoftware.amazon.awscdk.services.cloudfront.CachePolicyProps
Pythonaws_cdk.aws_cloudfront.CachePolicyProps
TypeScript (source)aws-cdk-lib » aws_cloudfront » CachePolicyProps

Properties for creating a Cache Policy.

Example

// Creating a custom cache policy for a Distribution -- all parameters optional
declare const bucketOrigin: origins.S3Origin;
const myCachePolicy = new cloudfront.CachePolicy(this, 'myCachePolicy', {
  cachePolicyName: 'MyPolicy',
  comment: 'A default policy',
  defaultTtl: Duration.days(2),
  minTtl: Duration.minutes(1),
  maxTtl: Duration.days(10),
  cookieBehavior: cloudfront.CacheCookieBehavior.all(),
  headerBehavior: cloudfront.CacheHeaderBehavior.allowList('X-CustomHeader'),
  queryStringBehavior: cloudfront.CacheQueryStringBehavior.denyList('username'),
  enableAcceptEncodingGzip: true,
  enableAcceptEncodingBrotli: true,
});
new cloudfront.Distribution(this, 'myDistCustomPolicy', {
  defaultBehavior: {
    origin: bucketOrigin,
    cachePolicy: myCachePolicy,
  },
});

Properties

NameTypeDescription
cachePolicyName?stringA unique name to identify the cache policy.
comment?stringA comment to describe the cache policy.
cookieBehavior?CacheCookieBehaviorDetermines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin.
defaultTtl?DurationThe default amount of time for objects to stay in the CloudFront cache.
enableAcceptEncodingBrotli?booleanWhether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is 'br'.
enableAcceptEncodingGzip?booleanWhether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is 'gzip'.
headerBehavior?CacheHeaderBehaviorDetermines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.
maxTtl?DurationThe maximum amount of time for objects to stay in the CloudFront cache.
minTtl?DurationThe minimum amount of time for objects to stay in the CloudFront cache.
queryStringBehavior?CacheQueryStringBehaviorDetermines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin.

cachePolicyName?

Type: string (optional, default: generated from the id)

A unique name to identify the cache policy.

The name must only include '-', '_', or alphanumeric characters.


comment?

Type: string (optional, default: no comment)

A comment to describe the cache policy.


cookieBehavior?

Type: CacheCookieBehavior (optional, default: CacheCookieBehavior.none())

Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin.


defaultTtl?

Type: Duration (optional, default: The greater of 1 day and minTtl)

The default amount of time for objects to stay in the CloudFront cache.

Only used when the origin does not send Cache-Control or Expires headers with the object.


enableAcceptEncodingBrotli?

Type: boolean (optional, default: false)

Whether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is 'br'.


enableAcceptEncodingGzip?

Type: boolean (optional, default: false)

Whether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is 'gzip'.


headerBehavior?

Type: CacheHeaderBehavior (optional, default: CacheHeaderBehavior.none())

Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.


maxTtl?

Type: Duration (optional, default: The greater of 1 year and defaultTtl)

The maximum amount of time for objects to stay in the CloudFront cache.

CloudFront uses this value only when the origin sends Cache-Control or Expires headers with the object.


minTtl?

Type: Duration (optional, default: Duration.seconds(0))

The minimum amount of time for objects to stay in the CloudFront cache.


queryStringBehavior?

Type: CacheQueryStringBehavior (optional, default: CacheQueryStringBehavior.none())

Determines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin.