aws-cdk-lib.aws_cloudfront.CacheHeaderBehavior

class CacheHeaderBehavior

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

Determines whether any HTTP headers 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
behaviorstringIf no headers will be passed, or an allow list of headers.
headers?string[]The headers for the allow/deny list, if applicable.

behavior

Type: string

If no headers will be passed, or an allow list of headers.


headers?

Type: string[] (optional)

The headers for the allow/deny list, if applicable.

Methods

NameDescription
static allowList(...headers)Listed headers are included in the cache key and are automatically included in requests that CloudFront sends to the origin.
static none()HTTP headers are not included in the cache key and are not automatically included in requests that CloudFront sends to the origin.

static allowList(...headers)

public static allowList(...headers: string[]): CacheHeaderBehavior

Parameters

  • headers string

Returns

  • CacheHeaderBehavior

Listed headers are included in the cache key and are automatically included in requests that CloudFront sends to the origin.


static none()

public static none(): CacheHeaderBehavior

Returns

  • CacheHeaderBehavior

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