Skip to content

Resource: awsCloudfrontCachePolicy

Example Usage

The following example below creates a CloudFront cache policy.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.cloudfrontCachePolicy.CloudfrontCachePolicy(this, "example", {
  comment: "test comment",
  defaultTtl: 50,
  maxTtl: 100,
  minTtl: 1,
  name: "example-policy",
  parametersInCacheKeyAndForwardedToOrigin: {
    cookiesConfig: {
      cookieBehavior: "whitelist",
      cookies: {
        items: ["example"],
      },
    },
    headersConfig: {
      headerBehavior: "whitelist",
      headers: {
        items: ["example"],
      },
    },
    queryStringsConfig: {
      queryStringBehavior: "whitelist",
      queryStrings: {
        items: ["example"],
      },
    },
  },
});

Argument Reference

The following arguments are supported:

  • name - (Required) A unique name to identify the cache policy.
  • minTtl - (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.
  • maxTtl - (Optional) 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.
  • defaultTtl - (Optional) 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.
  • comment - (Optional) A comment to describe the cache policy.
  • parametersInCacheKeyAndForwardedToOrigin - (Required) The HTTP headers, cookies, and URL query strings to include in the cache key. See Parameters In Cache Key And Forwarded To Origin for more information.

Parameters In Cache Key And Forwarded To Origin

  • cookiesConfig - (Required) Object that determines whether any cookies in viewer requests (and if so, which cookies) are included in the cache key and automatically included in requests that CloudFront sends to the origin. See Cookies Config for more information.
  • headersConfig - (Required) Object that determines whether any HTTP headers (and if so, which headers) are included in the cache key and automatically included in requests that CloudFront sends to the origin. See Headers Config for more information.
  • queryStringsConfig - (Required) Object that determines whether any URL query strings in viewer requests (and if so, which query strings) are included in the cache key and automatically included in requests that CloudFront sends to the origin. See Query String Config for more information.
  • enableAcceptEncodingBrotli - (Optional) A flag that can affect whether the Accept-Encoding HTTP header is included in the cache key and included in requests that CloudFront sends to the origin.
  • enableAcceptEncodingGzip - (Optional) A flag that can affect whether the Accept-Encoding HTTP header is included in the cache key and included in requests that CloudFront sends to the origin.

Cookies Config

  • cookieBehavior - (Required) Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin. Valid values are none, whitelist, allExcept, all.
  • cookies - (Optional) Object that contains a list of cookie names. See Items for more information.

Headers Config

  • headerBehavior - (Required) Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin. Valid values are none, whitelist.
  • headers - (Optional) Object that contains a list of header names. See Items for more information.

Query String Config

  • queryStringBehavior - (Required) Determines whether any URL query strings in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin. Valid values are none, whitelist, allExcept, all.
  • queryStrings - (Optional) Object that contains a list of query string names. See Items for more information.

Items

  • items - (Required) A list of item names (cookies, headers, or query strings).

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • etag - The current version of the cache policy.
  • id - The identifier for the cache policy.

Import

Cloudfront Cache Policies can be imported using the id, e.g.,

$ terraform import aws_cloudfront_cache_policy.policy 658327ea-f89d-4fab-a63d-7e88639e58f6