Skip to content
v2.273.0

Behavior Struct ​

A CloudFront behavior wrapper.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_cloudfront as cloudfront } from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';
import { aws_cloudfront as interfaces_cloudfront } from 'aws-cdk-lib/interfaces';

declare const functionRef: interfaces_cloudfront.IFunctionRef;
declare const keyGroupRef: interfaces_cloudfront.IKeyGroupRef;
declare const version: lambda.Version;
const behavior: cloudfront.Behavior = {
  allowedMethods: cloudfront.CloudFrontAllowedMethods.GET_HEAD,
  cachedMethods: cloudfront.CloudFrontAllowedCachedMethods.GET_HEAD,
  compress: false,
  defaultTtl: cdk.Duration.minutes(30),
  forwardedValues: {
    queryString: false,

    // the properties below are optional
    cookies: {
      forward: 'forward',

      // the properties below are optional
      whitelistedNames: ['whitelistedNames'],
    },
    headers: ['headers'],
    queryStringCacheKeys: ['queryStringCacheKeys'],
  },
  functionAssociations: [{
    eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
    function: functionRef,
  }],
  isDefaultBehavior: false,
  lambdaFunctionAssociations: [{
    eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
    lambdaFunction: version,

    // the properties below are optional
    includeBody: false,
  }],
  maxTtl: cdk.Duration.minutes(30),
  minTtl: cdk.Duration.minutes(30),
  pathPattern: 'pathPattern',
  trustedKeyGroups: [keyGroupRef],
  trustedSigners: ['trustedSigners'],
  viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.HTTPS_ONLY,
};

Properties ​

allowedMethodsCloudFrontAllowedMethodsallowed_methodsCloudFrontAllowedMethodsallowedMethodsCloudFrontAllowedMethodsAllowedMethodsCloudFrontAllowedMethodsAllowedMethodsCloudFrontAllowedMethods= GET_HEAD#
The method this CloudFront distribution responds do.
Which methods are cached by CloudFront by default.
compressbooleancompressboolcompressBooleanCompressboolCompress*bool= true#
If CloudFront should automatically compress some content types.
defaultTtlDurationdefault_ttlDurationdefaultTtlDurationDefaultTtlDurationDefaultTtlDuration= 86400 (1 day)#
The default amount of time CloudFront will cache an object.

This value applies only when your custom origin does not add HTTP headers, such as Cache-Control max-age, Cache-Control s-maxage, and Expires to objects.

forwardedValuesCfnDistribution.ForwardedValuesPropertyforwarded_valuesForwardedValuesPropertyforwardedValuesForwardedValuesPropertyForwardedValuesForwardedValuesPropertyForwardedValuesForwardedValuesProperty= none (no cookies - no headers)#
The values CloudFront will forward to the origin when making a request.
functionAssociationsFunctionAssociation[]function_associationstyping.List[FunctionAssociation]functionAssociationsList<FunctionAssociation>FunctionAssociationsFunctionAssociation[]FunctionAssociations*[]FunctionAssociation= no functions will be invoked#
The CloudFront functions to invoke before serving the contents.
isDefaultBehaviorbooleanis_default_behaviorboolisDefaultBehaviorBooleanIsDefaultBehaviorboolIsDefaultBehavior*bool#
If this behavior is the default behavior for the distribution.

You must specify exactly one default distribution per CloudFront distribution. The default behavior is allowed to omit the "path" property.

lambdaFunctionAssociationsLambdaFunctionAssociation[]lambda_function_associationstyping.List[LambdaFunctionAssociation]lambdaFunctionAssociationsList<LambdaFunctionAssociation>LambdaFunctionAssociationsLambdaFunctionAssociation[]LambdaFunctionAssociations*[]LambdaFunctionAssociation= No lambda function associated#
Declares associated lambda@edge functions for this distribution behaviour.
maxTtlDurationmax_ttlDurationmaxTtlDurationMaxTtlDurationMaxTtlDuration= Duration.seconds(31536000) (one …#
The max amount of time you want objects to stay in the cache before CloudFront queries your origin.
default

Default: Duration.seconds(31536000) (one year)

minTtlDurationmin_ttlDurationminTtlDurationMinTtlDurationMinTtlDuration#
The minimum amount of time that you want objects to stay in the cache before CloudFront queries your origin.
pathPatternstringpath_patternstrpathPatternStringPathPatternstringPathPattern*string#
The path this behavior responds to.

Required for all non-default behaviors. (The default behavior implicitly has "*" as the path pattern. )

trustedKeyGroupsIKeyGroupRef[]trusted_key_groupstyping.List[IKeyGroupRef]trustedKeyGroupsList<IKeyGroupRef>TrustedKeyGroupsIKeyGroupRef[]TrustedKeyGroups*[]IKeyGroupRef= no KeyGroups are associated with…#
A list of Key Groups that CloudFront can use to validate signed URLs or signed cookies.
default

Default: no KeyGroups are associated with cache behavior

trustedSignersstring[]trusted_signerstyping.List[str]trustedSignersList<String>TrustedSignersstring[]TrustedSigners*[]*stringdeprecated#
- We recommend using trustedKeyGroups instead of trustedSigners.

The signers are the account IDs that are allowed to sign cookies/presigned URLs for this distribution.

If you pass a non empty value, all requests for this behavior must be signed (no public access will be allowed)

viewerProtocolPolicyViewerProtocolPolicyviewer_protocol_policyViewerProtocolPolicyviewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicy= the distribution wide viewer pro…#
The viewer policy for this behavior.
default

Default: the distribution wide viewer protocol policy will be used