Skip to content
v2.273.0

AddBehaviorOptions Struct ​

Options for adding a new behavior to a Distribution.

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 ​

allowedMethodsAllowedMethodsallowed_methodsAllowedMethodsallowedMethodsAllowedMethodsAllowedMethodsAllowedMethodsAllowedMethodsAllowedMethods= AllowedMethods.ALLOW_GET_HEAD#
HTTP methods to allow for this behavior.
cachedMethodsCachedMethodscached_methodsCachedMethodscachedMethodsCachedMethodsCachedMethodsCachedMethodsCachedMethodsCachedMethods= CachedMethods.CACHE_GET_HEAD#
HTTP methods to cache for this behavior.
cachePolicyICachePolicyRefcache_policyICachePolicyRefcachePolicyICachePolicyRefCachePolicyICachePolicyRefCachePolicyICachePolicyRef= 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.

compressbooleancompressboolcompressBooleanCompressboolCompress*bool= true#
Whether you want CloudFront to automatically compress certain files for this cache behavior.
edgeLambdasEdgeLambda[]edge_lambdastyping.List[EdgeLambda]edgeLambdasList<EdgeLambda>EdgeLambdasEdgeLambda[]EdgeLambdas*[]EdgeLambda= no Lambda functions will be invo…#
The Lambda@Edge functions to invoke before serving the contents.
default

Default: no Lambda functions will be invoked

enableGrpcbooleanenable_grpcboolenableGrpcBooleanEnableGrpcboolEnableGrpc*bool= false#
Enables your CloudFront distribution to receive gRPC requests and to proxy them directly to your origins.
notes

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.
functionAssociationsFunctionAssociation[]function_associationstyping.List[FunctionAssociation]functionAssociationsList<FunctionAssociation>FunctionAssociationsFunctionAssociation[]FunctionAssociations*[]FunctionAssociation= no functions will be invoked#
The CloudFront functions to invoke before serving the contents.
originRequestPolicyIOriginRequestPolicyReforigin_request_policyIOriginRequestPolicyReforiginRequestPolicyIOriginRequestPolicyRefOriginRequestPolicyIOriginRequestPolicyRefOriginRequestPolicyIOriginRequestPolicyRef= 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.

realtimeLogConfigIRealtimeLogConfigRefrealtime_log_configIRealtimeLogConfigRefrealtimeLogConfigIRealtimeLogConfigRefRealtimeLogConfigIRealtimeLogConfigRefRealtimeLogConfigIRealtimeLogConfigRef= none#
The real-time log configuration to be attached to this cache behavior.
responseHeadersPolicyIResponseHeadersPolicyRefresponse_headers_policyIResponseHeadersPolicyRefresponseHeadersPolicyIResponseHeadersPolicyRefResponseHeadersPolicyIResponseHeadersPolicyRefResponseHeadersPolicyIResponseHeadersPolicyRef= none#
The response headers policy for this behavior.

The response headers policy determines which headers are included in responses

smoothStreamingbooleansmooth_streamingboolsmoothStreamingBooleanSmoothStreamingboolSmoothStreaming*bool= false#
Set this to true to indicate you want to distribute media files in the Microsoft Smooth Streaming format using this behavior.
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

viewerProtocolPolicyViewerProtocolPolicyviewer_protocol_policyViewerProtocolPolicyviewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicy= ViewerProtocolPolicy.REDIRECT_TO…#
The protocol that viewers can use to access the files controlled by this behavior.
default

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