SourceConfiguration

class aws_cdk.aws_cloudfront.SourceConfiguration(*, behaviors, connection_attempts=None, connection_timeout=None, custom_origin_source=None, failover_criteria_status_codes=None, failover_custom_origin_source=None, failover_s3_origin_source=None, origin_shield_region=None, s3_origin_source=None)

Bases: object

A source configuration is a wrapper for CloudFront origins and behaviors.

An origin is what CloudFront will “be in front of” - that is, CloudFront will pull it’s assets from an origin.

If you’re using s3 as a source - pass the s3Origin property, otherwise, pass the customOriginSource property.

One or the other must be passed, and it is invalid to pass both in the same SourceConfiguration.

Parameters:
  • behaviors (Sequence[Union[Behavior, Dict[str, Any]]]) – The behaviors associated with this source. At least one (default) behavior must be included.

  • connection_attempts (Union[int, float, None]) – The number of times that CloudFront attempts to connect to the origin. You can specify 1, 2, or 3 as the number of attempts. Default: 3

  • connection_timeout (Optional[Duration]) – The number of seconds that CloudFront waits when trying to establish a connection to the origin. You can specify a number of seconds between 1 and 10 (inclusive). Default: cdk.Duration.seconds(10)

  • custom_origin_source (Union[CustomOriginConfig, Dict[str, Any], None]) – A custom origin source - for all non-s3 sources.

  • failover_criteria_status_codes (Optional[Sequence[FailoverStatusCode]]) – HTTP status code to failover to second origin. Default: [500, 502, 503, 504]

  • failover_custom_origin_source (Union[CustomOriginConfig, Dict[str, Any], None]) – A custom origin source for failover in case the s3OriginSource returns invalid status code. Default: - no failover configuration

  • failover_s3_origin_source (Union[S3OriginConfig, Dict[str, Any], None]) – An s3 origin source for failover in case the s3OriginSource returns invalid status code. Default: - no failover configuration

  • origin_shield_region (Optional[str]) – When you enable Origin Shield in the AWS Region that has the lowest latency to your origin, you can get better network performance. Default: - origin shield not enabled

  • s3_origin_source (Union[S3OriginConfig, Dict[str, Any], None]) – An s3 origin source - if you’re using s3 for your assets.

ExampleMetadata:

fixture=_generated

Example:

# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_cloudfront as cloudfront
from aws_cdk import aws_lambda as lambda_
from aws_cdk import aws_s3 as s3

# bucket: s3.Bucket
# function_: cloudfront.Function
# key_group: cloudfront.KeyGroup
# origin_access_identity: cloudfront.OriginAccessIdentity
# version: lambda.Version

source_configuration = cloudfront.SourceConfiguration(
    behaviors=[cloudfront.Behavior(
        allowed_methods=cloudfront.CloudFrontAllowedMethods.GET_HEAD,
        cached_methods=cloudfront.CloudFrontAllowedCachedMethods.GET_HEAD,
        compress=False,
        default_ttl=cdk.Duration.minutes(30),
        forwarded_values=cloudfront.CfnDistribution.ForwardedValuesProperty(
            query_string=False,

            # the properties below are optional
            cookies=cloudfront.CfnDistribution.CookiesProperty(
                forward="forward",

                # the properties below are optional
                whitelisted_names=["whitelistedNames"]
            ),
            headers=["headers"],
            query_string_cache_keys=["queryStringCacheKeys"]
        ),
        function_associations=[cloudfront.FunctionAssociation(
            event_type=cloudfront.FunctionEventType.VIEWER_REQUEST,
            function=function_
        )],
        is_default_behavior=False,
        lambda_function_associations=[cloudfront.LambdaFunctionAssociation(
            event_type=cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
            lambda_function=version,

            # the properties below are optional
            include_body=False
        )],
        max_ttl=cdk.Duration.minutes(30),
        min_ttl=cdk.Duration.minutes(30),
        path_pattern="pathPattern",
        trusted_key_groups=[key_group],
        trusted_signers=["trustedSigners"],
        viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.HTTPS_ONLY
    )],

    # the properties below are optional
    connection_attempts=123,
    connection_timeout=cdk.Duration.minutes(30),
    custom_origin_source=cloudfront.CustomOriginConfig(
        domain_name="domainName",

        # the properties below are optional
        allowed_origin_sSLVersions=[cloudfront.OriginSslPolicy.SSL_V3],
        http_port=123,
        https_port=123,
        origin_headers={
            "origin_headers_key": "originHeaders"
        },
        origin_keepalive_timeout=cdk.Duration.minutes(30),
        origin_path="originPath",
        origin_protocol_policy=cloudfront.OriginProtocolPolicy.HTTP_ONLY,
        origin_read_timeout=cdk.Duration.minutes(30),
        origin_shield_region="originShieldRegion"
    ),
    failover_criteria_status_codes=[cloudfront.FailoverStatusCode.FORBIDDEN],
    failover_custom_origin_source=cloudfront.CustomOriginConfig(
        domain_name="domainName",

        # the properties below are optional
        allowed_origin_sSLVersions=[cloudfront.OriginSslPolicy.SSL_V3],
        http_port=123,
        https_port=123,
        origin_headers={
            "origin_headers_key": "originHeaders"
        },
        origin_keepalive_timeout=cdk.Duration.minutes(30),
        origin_path="originPath",
        origin_protocol_policy=cloudfront.OriginProtocolPolicy.HTTP_ONLY,
        origin_read_timeout=cdk.Duration.minutes(30),
        origin_shield_region="originShieldRegion"
    ),
    failover_s3_origin_source=cloudfront.S3OriginConfig(
        s3_bucket_source=bucket,

        # the properties below are optional
        origin_access_identity=origin_access_identity,
        origin_headers={
            "origin_headers_key": "originHeaders"
        },
        origin_path="originPath",
        origin_shield_region="originShieldRegion"
    ),
    origin_shield_region="originShieldRegion",
    s3_origin_source=cloudfront.S3OriginConfig(
        s3_bucket_source=bucket,

        # the properties below are optional
        origin_access_identity=origin_access_identity,
        origin_headers={
            "origin_headers_key": "originHeaders"
        },
        origin_path="originPath",
        origin_shield_region="originShieldRegion"
    )
)

Attributes

behaviors

The behaviors associated with this source.

At least one (default) behavior must be included.

connection_attempts

The number of times that CloudFront attempts to connect to the origin.

You can specify 1, 2, or 3 as the number of attempts.

Default:

3

connection_timeout

The number of seconds that CloudFront waits when trying to establish a connection to the origin.

You can specify a number of seconds between 1 and 10 (inclusive).

Default:

cdk.Duration.seconds(10)

custom_origin_source

A custom origin source - for all non-s3 sources.

failover_criteria_status_codes

HTTP status code to failover to second origin.

Default:

[500, 502, 503, 504]

failover_custom_origin_source

A custom origin source for failover in case the s3OriginSource returns invalid status code.

Default:
  • no failover configuration

failover_s3_origin_source

An s3 origin source for failover in case the s3OriginSource returns invalid status code.

Default:
  • no failover configuration

origin_shield_region

When you enable Origin Shield in the AWS Region that has the lowest latency to your origin, you can get better network performance.

Default:
  • origin shield not enabled

See:

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/origin-shield.html

s3_origin_source

An s3 origin source - if you’re using s3 for your assets.