CachePolicyProps

class aws_cdk.aws_cloudfront.CachePolicyProps(*, cache_policy_name=None, comment=None, cookie_behavior=None, default_ttl=None, enable_accept_encoding_brotli=None, enable_accept_encoding_gzip=None, header_behavior=None, max_ttl=None, min_ttl=None, query_string_behavior=None)

Bases: object

Properties for creating a Cache Policy.

Parameters:
  • cache_policy_name (Optional[str]) – A unique name to identify the cache policy. The name must only include ‘-’, ‘_’, or alphanumeric characters. Default: - generated from the id

  • comment (Optional[str]) – A comment to describe the cache policy. Default: - no comment

  • cookie_behavior (Optional[CacheCookieBehavior]) – Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin. Default: CacheCookieBehavior.none()

  • default_ttl (Optional[Duration]) – 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. Default: - The greater of 1 day and minTtl

  • enable_accept_encoding_brotli (Optional[bool]) – Whether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is ‘br’. Default: false

  • enable_accept_encoding_gzip (Optional[bool]) – Whether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is ‘gzip’. Default: false

  • header_behavior (Optional[CacheHeaderBehavior]) – Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin. Default: CacheHeaderBehavior.none()

  • max_ttl (Optional[Duration]) – 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. Default: - The greater of 1 year and defaultTtl

  • min_ttl (Optional[Duration]) – The minimum amount of time for objects to stay in the CloudFront cache. Default: Duration.seconds(0)

  • query_string_behavior (Optional[CacheQueryStringBehavior]) – Determines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin. Default: CacheQueryStringBehavior.none()

ExampleMetadata:

infused

Example:

# Creating a custom cache policy for a Distribution -- all parameters optional
# bucket_origin: origins.S3Origin

my_cache_policy = cloudfront.CachePolicy(self, "myCachePolicy",
    cache_policy_name="MyPolicy",
    comment="A default policy",
    default_ttl=Duration.days(2),
    min_ttl=Duration.minutes(1),
    max_ttl=Duration.days(10),
    cookie_behavior=cloudfront.CacheCookieBehavior.all(),
    header_behavior=cloudfront.CacheHeaderBehavior.allow_list("X-CustomHeader"),
    query_string_behavior=cloudfront.CacheQueryStringBehavior.deny_list("username"),
    enable_accept_encoding_gzip=True,
    enable_accept_encoding_brotli=True
)
cloudfront.Distribution(self, "myDistCustomPolicy",
    default_behavior=cloudfront.BehaviorOptions(
        origin=bucket_origin,
        cache_policy=my_cache_policy
    )
)

Attributes

cache_policy_name

A unique name to identify the cache policy.

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

Default:
  • generated from the id

comment

A comment to describe the cache policy.

Default:
  • no comment

cookie_behavior

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

Default:

CacheCookieBehavior.none()

default_ttl

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.

Default:
  • The greater of 1 day and minTtl

enable_accept_encoding_brotli

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

Default:

false

enable_accept_encoding_gzip

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

Default:

false

header_behavior

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

Default:

CacheHeaderBehavior.none()

max_ttl

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.

Default:
  • The greater of 1 year and defaultTtl

min_ttl

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

Default:

Duration.seconds(0)

query_string_behavior

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

Default:

CacheQueryStringBehavior.none()