aws-cdk-lib.aws_cloudfront.BehaviorOptions

interface BehaviorOptions

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

Options for creating a new behavior.

Example

// Add a cloudfront Function to a Distribution
const cfFunction = new cloudfront.Function(this, 'Function', {
  code: cloudfront.FunctionCode.fromInline('function handler(event) { return event.request }'),
});

declare const s3Bucket: s3.Bucket;
new cloudfront.Distribution(this, 'distro', {
  defaultBehavior: {
    origin: new origins.S3Origin(s3Bucket),
    functionAssociations: [{
      function: cfFunction,
      eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
    }],
  },
});

Properties

NameTypeDescription
originIOriginThe origin that you want CloudFront to route requests to when they match this behavior.
allowedMethods?AllowedMethodsHTTP methods to allow for this behavior.
cachePolicy?ICachePolicyThe cache policy for this behavior.
cachedMethods?CachedMethodsHTTP methods to cache for this behavior.
compress?booleanWhether you want CloudFront to automatically compress certain files for this cache behavior.
edgeLambdas?EdgeLambda[]The Lambda@Edge functions to invoke before serving the contents.
functionAssociations?FunctionAssociation[]The CloudFront functions to invoke before serving the contents.
originRequestPolicy?IOriginRequestPolicyThe origin request policy for this behavior.
responseHeadersPolicy?IResponseHeadersPolicyThe response headers policy for this behavior.
smoothStreaming?booleanSet this to true to indicate you want to distribute media files in the Microsoft Smooth Streaming format using this behavior.
trustedKeyGroups?IKeyGroup[]A list of Key Groups that CloudFront can use to validate signed URLs or signed cookies.
viewerProtocolPolicy?ViewerProtocolPolicyThe protocol that viewers can use to access the files controlled by this behavior.

origin

Type: IOrigin

The origin that you want CloudFront to route requests to when they match this behavior.


allowedMethods?

Type: AllowedMethods (optional, default: AllowedMethods.ALLOW_GET_HEAD)

HTTP methods to allow for this behavior.


cachePolicy?

Type: ICachePolicy (optional, default: 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.

See also: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html.


cachedMethods?

Type: CachedMethods (optional, default: CachedMethods.CACHE_GET_HEAD)

HTTP methods to cache for this behavior.


compress?

Type: boolean (optional, default: 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?

Type: EdgeLambda[] (optional, default: no Lambda functions will be invoked)

The Lambda@Edge functions to invoke before serving the contents.

See also: https://aws.amazon.com/lambda/edge


functionAssociations?

Type: FunctionAssociation[] (optional, default: no functions will be invoked)

The CloudFront functions to invoke before serving the contents.


originRequestPolicy?

Type: IOriginRequestPolicy (optional, default: 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.


responseHeadersPolicy?

Type: IResponseHeadersPolicy (optional, default: none)

The response headers policy for this behavior.

The response headers policy determines which headers are included in responses


smoothStreaming?

Type: boolean (optional, default: false)

Set this to true to indicate you want to distribute media files in the Microsoft Smooth Streaming format using this behavior.


trustedKeyGroups?

Type: IKeyGroup[] (optional, default: no KeyGroups are associated with cache behavior)

A list of Key Groups that CloudFront can use to validate signed URLs or signed cookies.

See also: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html


viewerProtocolPolicy?

Type: ViewerProtocolPolicy (optional, default: ViewerProtocolPolicy.ALLOW_ALL)

The protocol that viewers can use to access the files controlled by this behavior.