S3Origin

class aws_cdk.aws_cloudfront_origins.S3Origin(bucket, *, origin_access_identity=None, origin_path=None, connection_attempts=None, connection_timeout=None, custom_headers=None, origin_shield_region=None)

Bases: object

An Origin that is backed by an S3 bucket.

If the bucket is configured for website hosting, this origin will be configured to use the bucket as an HTTP server origin and will use the bucket’s configured website redirects and error handling. Otherwise, the origin is created as a bucket origin and will use CloudFront’s redirect and error handling.

ExampleMetadata

infused

Example:

# Adding an existing Lambda@Edge function created in a different stack
# to a CloudFront distribution.
# s3_bucket: s3.Bucket

function_version = lambda_.Version.from_version_arn(self, "Version", "arn:aws:lambda:us-east-1:123456789012:function:functionName:1")

cloudfront.Distribution(self, "distro",
    default_behavior=cloudfront.BehaviorOptions(
        origin=origins.S3Origin(s3_bucket),
        edge_lambdas=[cloudfront.EdgeLambda(
            function_version=function_version,
            event_type=cloudfront.LambdaEdgeEventType.VIEWER_REQUEST
        )
        ]
    )
)
Parameters
  • bucket (IBucket) –

  • origin_access_identity (Optional[IOriginAccessIdentity]) – An optional Origin Access Identity of the origin identity cloudfront will use when calling your s3 bucket. Default: - An Origin Access Identity will be created.

  • origin_path (Optional[str]) – An optional path that CloudFront appends to the origin domain name when CloudFront requests content from the origin. Must begin, but not end, with ‘/’ (e.g., ‘/production/images’). Default: ‘/’

  • connection_attempts (Union[int, float, None]) – The number of times that CloudFront attempts to connect to the origin; valid values are 1, 2, or 3 attempts. Default: 3

  • connection_timeout (Optional[Duration]) – The number of seconds that CloudFront waits when trying to establish a connection to the origin. Valid values are 1-10 seconds, inclusive. Default: Duration.seconds(10)

  • custom_headers (Optional[Mapping[str, str]]) – A list of HTTP header names and values that CloudFront adds to requests it sends to the origin. Default: {}

  • 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

Methods

bind(scope, *, origin_id)

The method called when a given Origin is added (for the first time) to a Distribution.

Parameters
  • scope (Construct) –

  • origin_id (str) – The identifier of this Origin, as assigned by the Distribution this Origin has been used added to.

Return type

OriginBindConfig