aws-cdk-lib.aws_cloudfront.CacheCookieBehavior

class CacheCookieBehavior

LanguageType name
.NETAmazon.CDK.AWS.CloudFront.CacheCookieBehavior
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#CacheCookieBehavior
Javasoftware.amazon.awscdk.services.cloudfront.CacheCookieBehavior
Pythonaws_cdk.aws_cloudfront.CacheCookieBehavior
TypeScript (source)aws-cdk-lib » aws_cloudfront » 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.

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
behaviorstringThe behavior of cookies: allow all, none, an allow list, or a deny list.
cookies?string[]The cookies to allow or deny, if the behavior is an allow or deny list.

behavior

Type: string

The behavior of cookies: allow all, none, an allow list, or a deny list.


cookies?

Type: string[] (optional)

The cookies to allow or deny, if the behavior is an allow or deny list.

Methods

NameDescription
static all()All cookies in viewer requests are included in the cache key and are automatically included in requests that CloudFront sends to the origin.
static allowList(...cookies)Only the provided cookies are included in the cache key and automatically included in requests that CloudFront sends to the origin.
static denyList(...cookies)All cookies except the provided cookies are included in the cache key and automatically included in requests that CloudFront sends to the origin.
static none()Cookies in viewer requests are not included in the cache key and are not automatically included in requests that CloudFront sends to the origin.

static all()

public static all(): CacheCookieBehavior

Returns

  • CacheCookieBehavior

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


static allowList(...cookies)

public static allowList(...cookies: string[]): CacheCookieBehavior

Parameters

  • cookies string

Returns

  • CacheCookieBehavior

Only the provided cookies are included in the cache key and automatically included in requests that CloudFront sends to the origin.


static denyList(...cookies)

public static denyList(...cookies: string[]): CacheCookieBehavior

Parameters

  • cookies string

Returns

  • CacheCookieBehavior

All cookies except the provided cookies are included in the cache key and automatically included in requests that CloudFront sends to the origin.


static none()

public static none(): CacheCookieBehavior

Returns

  • CacheCookieBehavior

Cookies in viewer requests are not included in the cache key and are not automatically included in requests that CloudFront sends to the origin.