BehaviorOptions Struct
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 }'),
runtime: cloudfront.FunctionRuntime.JS_2_0,
});
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
allowedMethodsAllowedMethodsallowed_methodsAllowedMethodsallowedMethodsAllowedMethodsAllowedMethodsAllowedMethodsAllowedMethodsAllowedMethods= AllowedMethods.ALLOW_GET_HEAD#cachedMethodsCachedMethodscached_methodsCachedMethodscachedMethodsCachedMethodsCachedMethodsCachedMethodsCachedMethodsCachedMethods= CachedMethods.CACHE_GET_HEAD#cachePolicyICachePolicyRefcache_policyICachePolicyRefcachePolicyICachePolicyRefCachePolicyICachePolicyRefCachePolicyICachePolicyRef= CachePolicy.CACHING_OPTIMIZED#The cache policy determines what values are included in the cache key, and the time-to-live (TTL) values for the cache.
See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compressed-content-cloudfront-file-types for file types CloudFront will compress.
edgeLambdasEdgeLambda[]edge_lambdastyping.List[EdgeLambda]edgeLambdasList<EdgeLambda>EdgeLambdasEdgeLambda[]EdgeLambdas*[]EdgeLambda= no Lambda functions will be invo…#default
Default: no Lambda functions will be invoked
notes
If the enableGrpc is set to true, the following restrictions apply:
- The
allowedMethodsproperty must beAllowedMethods.ALLOW_ALLto include POST method because gRPC only supports POST method. - The
httpVersionproperty must beHttpVersion.HTTP2orHttpVersion.HTTP2_AND_3because gRPC only supports versions including HTTP/2. - The
edgeLambdasproperty 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#originRequestPolicyIOriginRequestPolicyReforigin_request_policyIOriginRequestPolicyReforiginRequestPolicyIOriginRequestPolicyRefOriginRequestPolicyIOriginRequestPolicyRefOriginRequestPolicyIOriginRequestPolicyRef= none#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#responseHeadersPolicyIResponseHeadersPolicyRefresponse_headers_policyIResponseHeadersPolicyRefresponseHeadersPolicyIResponseHeadersPolicyRefResponseHeadersPolicyIResponseHeadersPolicyRefResponseHeadersPolicyIResponseHeadersPolicyRef= none#The response headers policy determines which headers are included in responses
smoothStreamingbooleansmooth_streamingboolsmoothStreamingBooleanSmoothStreamingboolSmoothStreaming*bool= false#trustedKeyGroupsIKeyGroupRef[]trusted_key_groupstyping.List[IKeyGroupRef]trustedKeyGroupsList<IKeyGroupRef>TrustedKeyGroupsIKeyGroupRef[]TrustedKeyGroups*[]IKeyGroupRef= no KeyGroups are associated with…#default
Default: no KeyGroups are associated with cache behavior
viewerProtocolPolicyViewerProtocolPolicyviewer_protocol_policyViewerProtocolPolicyviewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicyViewerProtocolPolicy= ViewerProtocolPolicy.REDIRECT_TO…#default
Default: ViewerProtocolPolicy.REDIRECT_TO_HTTPS if the @aws-cdk/aws-cloudfront:defaultViewerProtocolPolicyRedirectToHttps feature flag is enabled, otherwise ViewerProtocolPolicy.ALLOW_ALL