AddBehaviorOptions

class aws_cdk.aws_cloudfront.AddBehaviorOptions(*, allowed_methods=None, cached_methods=None, cache_policy=None, compress=None, edge_lambdas=None, function_associations=None, origin_request_policy=None, realtime_log_config=None, response_headers_policy=None, smooth_streaming=None, trusted_key_groups=None, viewer_protocol_policy=None)

Bases: object

Options for adding a new behavior to a Distribution.

Parameters:
  • allowed_methods (Optional[AllowedMethods]) – HTTP methods to allow for this behavior. Default: AllowedMethods.ALLOW_GET_HEAD

  • cached_methods (Optional[CachedMethods]) – HTTP methods to cache for this behavior. Default: CachedMethods.CACHE_GET_HEAD

  • cache_policy (Optional[ICachePolicy]) – 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. Default: CachePolicy.CACHING_OPTIMIZED

  • compress (Optional[bool]) – 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. Default: true

  • edge_lambdas (Optional[Sequence[Union[EdgeLambda, Dict[str, Any]]]]) – The Lambda@Edge functions to invoke before serving the contents. Default: - no Lambda functions will be invoked

  • function_associations (Optional[Sequence[Union[FunctionAssociation, Dict[str, Any]]]]) – The CloudFront functions to invoke before serving the contents. Default: - no functions will be invoked

  • origin_request_policy (Optional[IOriginRequestPolicy]) – 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. Default: - none

  • realtime_log_config (Optional[IRealtimeLogConfig]) – The real-time log configuration to be attached to this cache behavior. Default: - none

  • response_headers_policy (Optional[IResponseHeadersPolicy]) – The response headers policy for this behavior. The response headers policy determines which headers are included in responses Default: - none

  • smooth_streaming (Optional[bool]) – Set this to true to indicate you want to distribute media files in the Microsoft Smooth Streaming format using this behavior. Default: false

  • trusted_key_groups (Optional[Sequence[IKeyGroup]]) – A list of Key Groups that CloudFront can use to validate signed URLs or signed cookies. Default: - no KeyGroups are associated with cache behavior

  • viewer_protocol_policy (Optional[ViewerProtocolPolicy]) – The protocol that viewers can use to access the files controlled by this behavior. Default: ViewerProtocolPolicy.ALLOW_ALL

ExampleMetadata:

infused

Example:

# Add a behavior to a Distribution after initial creation.
# my_bucket: s3.Bucket
# my_web_distribution: cloudfront.Distribution

my_web_distribution.add_behavior("/images/*.jpg", origins.S3Origin(my_bucket),
    viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS
)

Attributes

allowed_methods

HTTP methods to allow for this behavior.

Default:

AllowedMethods.ALLOW_GET_HEAD

cache_policy

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.

Default:

CachePolicy.CACHING_OPTIMIZED

See:

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

cached_methods

HTTP methods to cache for this behavior.

Default:

CachedMethods.CACHE_GET_HEAD

compress

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.

Default:

true

edge_lambdas

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

Default:
  • no Lambda functions will be invoked

See:

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

function_associations

The CloudFront functions to invoke before serving the contents.

Default:
  • no functions will be invoked

origin_request_policy

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.

Default:
  • none

realtime_log_config

The real-time log configuration to be attached to this cache behavior.

Default:
  • none

response_headers_policy

The response headers policy for this behavior.

The response headers policy determines which headers are included in responses

Default:
  • none

smooth_streaming

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

Default:

false

trusted_key_groups

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

Default:
  • no KeyGroups are associated with cache behavior

See:

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

viewer_protocol_policy

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

Default:

ViewerProtocolPolicy.ALLOW_ALL