Skip to content
v2.277.0

CachePolicyConfigProperty Struct ​

A cache policy configuration.

This configuration determines the following:

  • The values that CloudFront includes in the cache key. These values can include HTTP headers, cookies, and URL query strings. CloudFront uses the cache key to find an object in its cache that it can return to the viewer.
  • The default, minimum, and maximum time to live (TTL) values that you want objects to stay in the CloudFront cache.

If your minimum TTL is greater than 0, CloudFront will cache content for at least the duration specified in the cache policy's minimum TTL, even if the Cache-Control: no-cache , no-store , or private directives are present in the origin headers.

The headers, cookies, and query strings that are included in the cache key are also included in requests that CloudFront sends to the origin. CloudFront sends a request when it can't find a valid object in its cache that matches the request's cache key. If you want to send values to the origin but not include them in the cache key, use OriginRequestPolicy .

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_cloudfront as cloudfront } from 'aws-cdk-lib';
const cachePolicyConfigProperty: cloudfront.CfnCachePolicy.CachePolicyConfigProperty = {
  defaultTtl: 123,
  maxTtl: 123,
  minTtl: 123,
  name: 'name',
  parametersInCacheKeyAndForwardedToOrigin: {
    cookiesConfig: {
      cookieBehavior: 'cookieBehavior',

      // the properties below are optional
      cookies: ['cookies'],
    },
    enableAcceptEncodingGzip: false,
    headersConfig: {
      headerBehavior: 'headerBehavior',

      // the properties below are optional
      headers: ['headers'],
    },
    queryStringsConfig: {
      queryStringBehavior: 'queryStringBehavior',

      // the properties below are optional
      queryStrings: ['queryStrings'],
    },

    // the properties below are optional
    enableAcceptEncodingBrotli: false,
  },

  // the properties below are optional
  comment: 'comment',
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_cloudfront as cloudfront

cache_policy_config_property = cloudfront.CfnCachePolicy.CachePolicyConfigProperty(
    default_ttl=123,
    max_ttl=123,
    min_ttl=123,
    name="name",
    parameters_in_cache_key_and_forwarded_to_origin=cloudfront.CfnCachePolicy.ParametersInCacheKeyAndForwardedToOriginProperty(
        cookies_config=cloudfront.CfnCachePolicy.CookiesConfigProperty(
            cookie_behavior="cookieBehavior",

            # the properties below are optional
            cookies=["cookies"]
        ),
        enable_accept_encoding_gzip=False,
        headers_config=cloudfront.CfnCachePolicy.HeadersConfigProperty(
            header_behavior="headerBehavior",

            # the properties below are optional
            headers=["headers"]
        ),
        query_strings_config=cloudfront.CfnCachePolicy.QueryStringsConfigProperty(
            query_string_behavior="queryStringBehavior",

            # the properties below are optional
            query_strings=["queryStrings"]
        ),

        # the properties below are optional
        enable_accept_encoding_brotli=False
    ),

    # the properties below are optional
    comment="comment"
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.cloudfront.*;

CachePolicyConfigProperty cachePolicyConfigProperty = CachePolicyConfigProperty.builder()
        .defaultTtl(123)
        .maxTtl(123)
        .minTtl(123)
        .name("name")
        .parametersInCacheKeyAndForwardedToOrigin(ParametersInCacheKeyAndForwardedToOriginProperty.builder()
                .cookiesConfig(CookiesConfigProperty.builder()
                        .cookieBehavior("cookieBehavior")

                        // the properties below are optional
                        .cookies(List.of("cookies"))
                        .build())
                .enableAcceptEncodingGzip(false)
                .headersConfig(HeadersConfigProperty.builder()
                        .headerBehavior("headerBehavior")

                        // the properties below are optional
                        .headers(List.of("headers"))
                        .build())
                .queryStringsConfig(QueryStringsConfigProperty.builder()
                        .queryStringBehavior("queryStringBehavior")

                        // the properties below are optional
                        .queryStrings(List.of("queryStrings"))
                        .build())

                // the properties below are optional
                .enableAcceptEncodingBrotli(false)
                .build())

        // the properties below are optional
        .comment("comment")
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.CloudFront;

var cachePolicyConfigProperty = new CachePolicyConfigProperty {
    DefaultTtl = 123,
    MaxTtl = 123,
    MinTtl = 123,
    Name = "name",
    ParametersInCacheKeyAndForwardedToOrigin = new ParametersInCacheKeyAndForwardedToOriginProperty {
        CookiesConfig = new CookiesConfigProperty {
            CookieBehavior = "cookieBehavior",

            // the properties below are optional
            Cookies = new [] { "cookies" }
        },
        EnableAcceptEncodingGzip = false,
        HeadersConfig = new HeadersConfigProperty {
            HeaderBehavior = "headerBehavior",

            // the properties below are optional
            Headers = new [] { "headers" }
        },
        QueryStringsConfig = new QueryStringsConfigProperty {
            QueryStringBehavior = "queryStringBehavior",

            // the properties below are optional
            QueryStrings = new [] { "queryStrings" }
        },

        // the properties below are optional
        EnableAcceptEncodingBrotli = false
    },

    // the properties below are optional
    Comment = "comment"
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

cachePolicyConfigProperty := &CachePolicyConfigProperty{
	DefaultTtl: jsii.Number(123),
	MaxTtl: jsii.Number(123),
	MinTtl: jsii.Number(123),
	Name: jsii.String("name"),
	ParametersInCacheKeyAndForwardedToOrigin: &ParametersInCacheKeyAndForwardedToOriginProperty{
		CookiesConfig: &CookiesConfigProperty{
			CookieBehavior: jsii.String("cookieBehavior"),

			// the properties below are optional
			Cookies: []*string{
				jsii.String("cookies"),
			},
		},
		EnableAcceptEncodingGzip: jsii.Boolean(false),
		HeadersConfig: &HeadersConfigProperty{
			HeaderBehavior: jsii.String("headerBehavior"),

			// the properties below are optional
			Headers: []*string{
				jsii.String("headers"),
			},
		},
		QueryStringsConfig: &QueryStringsConfigProperty{
			QueryStringBehavior: jsii.String("queryStringBehavior"),

			// the properties below are optional
			QueryStrings: []*string{
				jsii.String("queryStrings"),
			},
		},

		// the properties below are optional
		EnableAcceptEncodingBrotli: jsii.Boolean(false),
	},

	// the properties below are optional
	Comment: jsii.String("comment"),
}

Properties ​

commentoptionalstringcommentoptionalstrcommentoptionalStringCommentoptionalstringCommentoptional*string #
A comment to describe the cache policy.

The comment cannot be longer than 128 characters.

defaultTtlnumberdefault_ttlint | floatdefaultTtlNumberDefaultTtldoubleDefaultTtl*float64 required #
The default amount of time, in seconds, that you want objects to stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated.
notes

CloudFront uses this value as the object's time to live (TTL) only when the origin does not send Cache-Control or Expires headers with the object. For more information, see Managing How Long Content Stays in an Edge Cache (Expiration) in the Amazon CloudFront Developer Guide .

The default value for this field is 86400 seconds (one day). If the value of MinTTL is more than 86400 seconds, then the default value for this field is the same as the value of MinTTL .

maxTtlnumbermax_ttlint | floatmaxTtlNumberMaxTtldoubleMaxTtl*float64 required #
The maximum amount of time, in seconds, that objects stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated.
notes

CloudFront uses this value only when the origin sends Cache-Control or Expires headers with the object. For more information, see Managing How Long Content Stays in an Edge Cache (Expiration) in the Amazon CloudFront Developer Guide .

The default value for this field is 31536000 seconds (one year). If the value of MinTTL or DefaultTTL is more than 31536000 seconds, then the default value for this field is the same as the value of DefaultTTL .

minTtlnumbermin_ttlint | floatminTtlNumberMinTtldoubleMinTtl*float64 required #
The minimum amount of time, in seconds, that you want objects to stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated.

For more information, see Managing How Long Content Stays in an Edge Cache (Expiration) in the Amazon CloudFront Developer Guide .

namestringnamestrnameStringNamestringName*string required #
A unique name to identify the cache policy.
parametersInCacheKeyAndForwardedToOriginIResolvable | CfnCachePolicy.ParametersInCacheKeyAndForwardedToOriginPropertyparameters_in_cache_key_and_forwarded_to_origintyping.Union[IResolvable, ParametersInCacheKeyAndForwardedToOriginProperty]parametersInCacheKeyAndForwardedToOriginIResolvableParametersInCacheKeyAndForwardedToOriginIResolvableParametersInCacheKeyAndForwardedToOrigininterface{} required #
The HTTP headers, cookies, and URL query strings to include in the cache key.

The values included in the cache key are also included in requests that CloudFront sends to the origin.