Skip to content
v2.275.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 ​

allowedMethodsoptionalCloudFrontAllowedMethodsallowed_methodsoptionalCloudFrontAllowedMethodsallowedMethodsoptionalCloudFrontAllowedMethodsAllowedMethodsoptionalCloudFrontAllowedMethodsAllowedMethodsoptionalCloudFrontAllowedMethods= GET_HEAD#
The method this CloudFront distribution responds do.
cachedMethodsoptionalCloudFrontAllowedCachedMethodscached_methodsoptionalCloudFrontAllowedCachedMethodscachedMethodsoptionalCloudFrontAllowedCachedMethodsCachedMethodsoptionalCloudFrontAllowedCachedMethodsCachedMethodsoptionalCloudFrontAllowedCachedMethods= GET_HEAD#
Which methods are cached by CloudFront by default.
compressoptionalbooleancompressoptionalboolcompressoptionalBooleanCompressoptionalboolCompressoptional*bool= true#
If CloudFront should automatically compress some content types.
defaultTtloptionalDurationdefault_ttloptionalDurationdefaultTtloptionalDurationDefaultTtloptionalDurationDefaultTtloptionalDuration#
The default amount of time CloudFront will cache an object.

Default: 86400 (1 day)

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.

forwardedValuesoptionalCfnDistribution.ForwardedValuesPropertyforwarded_valuesoptionalForwardedValuesPropertyforwardedValuesoptionalForwardedValuesPropertyForwardedValuesoptionalForwardedValuesPropertyForwardedValuesoptionalForwardedValuesProperty#
The values CloudFront will forward to the origin when making a request.

Default: none (no cookies - no headers)

functionAssociationsoptionalFunctionAssociation[]function_associationsoptionaltyping.List[FunctionAssociation]functionAssociationsoptionalList<FunctionAssociation>FunctionAssociationsoptionalFunctionAssociation[]FunctionAssociationsoptional*[]FunctionAssociation#
The CloudFront functions to invoke before serving the contents.

Default: no functions will be invoked

isDefaultBehavioroptionalbooleanis_default_behavioroptionalboolisDefaultBehavioroptionalBooleanIsDefaultBehavioroptionalboolIsDefaultBehavioroptional*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.

lambdaFunctionAssociationsoptionalLambdaFunctionAssociation[]lambda_function_associationsoptionaltyping.List[LambdaFunctionAssociation]lambdaFunctionAssociationsoptionalList<LambdaFunctionAssociation>LambdaFunctionAssociationsoptionalLambdaFunctionAssociation[]LambdaFunctionAssociationsoptional*[]LambdaFunctionAssociation#
Declares associated lambda@edge functions for this distribution behaviour.

Default: No lambda function associated

maxTtloptionalDurationmax_ttloptionalDurationmaxTtloptionalDurationMaxTtloptionalDurationMaxTtloptionalDuration#
The max amount of time you want objects to stay in the cache before CloudFront queries your origin.

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

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

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

trustedKeyGroupsoptionalIKeyGroupRef[]trusted_key_groupsoptionaltyping.List[IKeyGroupRef]trustedKeyGroupsoptionalList<IKeyGroupRef>TrustedKeyGroupsoptionalIKeyGroupRef[]TrustedKeyGroupsoptional*[]IKeyGroupRef#
A list of Key Groups that CloudFront can use to validate signed URLs or signed cookies.

Default: no KeyGroups are associated with cache behavior

trustedSignersoptionalstring[]trusted_signersoptionaltyping.List[str]trustedSignersoptionalList<String>TrustedSignersoptionalstring[]TrustedSignersoptional*[]*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)

viewerProtocolPolicyoptionalViewerProtocolPolicyviewer_protocol_policyoptionalViewerProtocolPolicyviewerProtocolPolicyoptionalViewerProtocolPolicyViewerProtocolPolicyoptionalViewerProtocolPolicyViewerProtocolPolicyoptionalViewerProtocolPolicy#
The viewer policy for this behavior.

Default: the distribution wide viewer protocol policy will be used