# AddBehaviorOptions

Options for adding a new behavior to a Distribution.

- Source: [`aws-cloudfront/lib/distribution.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts#L1133)
- Type last changed: v2.273.0 · 8 Oct 2026

## Example

```ts
// Add a behavior to a Distribution after initial creation.
declare const myBucket: s3.Bucket;
declare const myWebDistribution: cloudfront.Distribution;
myWebDistribution.addBehavior('/images/*.jpg', new origins.S3Origin(myBucket), {
  viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
});
```

## Properties

- `allowedMethods`: [AllowedMethods](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.AllowedMethods.html) = AllowedMethods.ALLOW_GET_HEAD — HTTP methods to allow for this behavior.

- `cachedMethods`: [CachedMethods](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.CachedMethods.html) = CachedMethods.CACHE_GET_HEAD — HTTP methods to cache for this behavior.

- `cachePolicy`: [ICachePolicyRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.ICachePolicyRef.html) = CachePolicy.CACHING_OPTIMIZED — The cache policy for this behavior.

  The cache policy determines what values are included in the cache key,
  and the time-to-live (TTL) values for the cache.

- `compress`: boolean = true — Whether you want CloudFront to automatically compress certain files for this cache behavior.

  See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compressed-content-cloudfront-file-types
  for file types CloudFront will compress.

- `edgeLambdas`: [EdgeLambda](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.EdgeLambda.html)[] — The Lambda@Edge functions to invoke before serving the contents.

  **Default:** no Lambda functions will be invoked

- `enableGrpc`: boolean = false — Enables your CloudFront distribution to receive gRPC requests and to proxy them directly to your origins.

  If the `enableGrpc` is set to true, the following restrictions apply:
  - The `allowedMethods` property must be `AllowedMethods.ALLOW_ALL` to include POST method because gRPC only supports POST method.
  - The `httpVersion` property must be `HttpVersion.HTTP2` or `HttpVersion.HTTP2_AND_3` because gRPC only supports versions including HTTP/2.
  - The `edgeLambdas` property can't be specified because gRPC is not supported with Lambda@Edge.

- `functionAssociations`: [FunctionAssociation](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.FunctionAssociation.html)[] — The CloudFront functions to invoke before serving the contents.

  **Default:** no functions will be invoked

- `originRequestPolicy`: [IOriginRequestPolicyRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.IOriginRequestPolicyRef.html) = none — The origin request policy for this behavior.

  The origin request policy determines which values (e.g., headers, cookies)
  are included in requests that CloudFront sends to the origin.

- `realtimeLogConfig`: [IRealtimeLogConfigRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.IRealtimeLogConfigRef.html) = none — The real-time log configuration to be attached to this cache behavior.

- `responseHeadersPolicy`: [IResponseHeadersPolicyRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.IResponseHeadersPolicyRef.html) = none — The response headers policy for this behavior.

  The response headers policy determines which headers are included in responses

- `smoothStreaming`: boolean = false — Set this to true to indicate you want to distribute media files in the Microsoft Smooth Streaming format using this behavior.

- `trustedKeyGroups`: [IKeyGroupRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_cloudfront.IKeyGroupRef.html)[] — A list of Key Groups that CloudFront can use to validate signed URLs or signed cookies.

  **Default:** no KeyGroups are associated with cache behavior

- `viewerProtocolPolicy`: [ViewerProtocolPolicy](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.ViewerProtocolPolicy.html) — The protocol that viewers can use to access the files controlled by this behavior.

  **Default:** ViewerProtocolPolicy.REDIRECT_TO_HTTPS if the `@aws-cdk/aws-cloudfront:defaultViewerProtocolPolicyRedirectToHttps` feature flag is enabled, otherwise ViewerProtocolPolicy.ALLOW_ALL
