See: Description
| Interface | Description |
|---|---|
| HttpOriginProps |
(experimental) Properties for an Origin backed by an S3 website-configured bucket, load balancer, or custom HTTP server.
|
| LoadBalancerV2OriginProps |
(experimental) Properties for an Origin backed by a v2 load balancer.
|
| OriginGroupProps |
(experimental) Construction properties for
OriginGroup. |
| S3OriginProps |
(experimental) Properties to use to customize an S3 Origin.
|
| Class | Description |
|---|---|
| HttpOrigin |
(experimental) An Origin for an HTTP server or S3 bucket configured for website hosting.
|
| HttpOrigin.Builder |
(experimental) A fluent builder for
HttpOrigin. |
| HttpOriginProps.Builder |
A builder for
HttpOriginProps |
| HttpOriginProps.Jsii$Proxy |
An implementation for
HttpOriginProps |
| LoadBalancerV2Origin |
(experimental) An Origin for a v2 load balancer.
|
| LoadBalancerV2Origin.Builder |
(experimental) A fluent builder for
LoadBalancerV2Origin. |
| LoadBalancerV2OriginProps.Builder |
A builder for
LoadBalancerV2OriginProps |
| LoadBalancerV2OriginProps.Jsii$Proxy |
An implementation for
LoadBalancerV2OriginProps |
| OriginGroup |
(experimental) An Origin that represents a group.
|
| OriginGroup.Builder |
(experimental) A fluent builder for
OriginGroup. |
| OriginGroupProps.Builder |
A builder for
OriginGroupProps |
| OriginGroupProps.Jsii$Proxy |
An implementation for
OriginGroupProps |
| S3Origin |
(experimental) An Origin that is backed by an S3 bucket.
|
| S3Origin.Builder |
(experimental) A fluent builder for
S3Origin. |
| S3OriginProps.Builder |
A builder for
S3OriginProps |
| S3OriginProps.Jsii$Proxy |
An implementation for
S3OriginProps |
---
This library contains convenience methods for defining origins for a CloudFront distribution. You can use this library to create origins from S3 buckets, Elastic Load Balancing v2 load balancers, or any other domain name.
An S3 bucket can be added as an origin. If the bucket is configured as a website endpoint, the distribution can use S3 redirects and S3 custom error documents.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import software.amazon.awscdk.aws_cloudfront;
import software.amazon.awscdk.aws_cloudfront_origins;
Bucket myBucket = new Bucket(this, "myBucket");
new Distribution(this, "myDist", new DistributionProps()
.defaultBehavior(new BehaviorOptions().origin(new S3Origin(myBucket))));
The above will treat the bucket differently based on if IBucket.isWebsite is set or not. If the bucket is configured as a website, the bucket is
treated as an HTTP origin, and the built-in S3 redirects and error pages can be used. Otherwise, the bucket is handled as a bucket origin and
CloudFront's redirect and error handling will be used. In the latter case, the Origin will create an origin access identity and grant it access to the
underlying bucket. This can be used in conjunction with a bucket that is not public to require that your users access your content using CloudFront
URLs and not S3 URLs directly. Alternatively, a custom origin access identity can be passed to the S3 origin in the properties.
An Elastic Load Balancing (ELB) v2 load balancer may be used as an origin. In order for a load balancer to serve as an origin, it must be publicly
accessible (internetFacing is true). Both Application and Network load balancers are supported.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import software.amazon.awscdk.aws_ec2;
import software.amazon.awscdk.aws_elasticloadbalancingv2;
Vpc vpc = new Vpc(...);
// Create an application load balancer in a VPC. 'internetFacing' must be 'true'
// for CloudFront to access the load balancer and use it as an origin.
ApplicationLoadBalancer lb = new ApplicationLoadBalancer(this, "LB", new ApplicationLoadBalancerProps()
.vpc(vpc)
.internetFacing(true));
Distribution.Builder.create(this, "myDist")
.defaultBehavior(Map.of("origin", new LoadBalancerV2Origin(lb)))
.build();
The origin can also be customized to respond on different ports, have different connection properties, etc.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object origin = LoadBalancerV2Origin.Builder.create(loadBalancer)
.connectionAttempts(3)
.connectionTimeout(Duration.seconds(5))
.protocolPolicy(cloudfront.OriginProtocolPolicy.getMATCH_VIEWER())
.build();
Origins can also be created from any other HTTP endpoint, given the domain name, and optionally, other origin properties.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Distribution.Builder.create(this, "myDist")
.defaultBehavior(Map.of("origin", new HttpOrigin("www.example.com")))
.build();
See the documentation of @aws-cdk/aws-cloudfront for more information.
You can set up CloudFront with origin failover for scenarios that require high availability.
To get started, you create an origin group with two origins: a primary and a secondary.
If the primary origin is unavailable, or returns specific HTTP response status codes that indicate a failure,
CloudFront automatically switches to the secondary origin.
You achieve that behavior in the CDK using the OriginGroup class:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Distribution.Builder.create(this, "myDist")
.defaultBehavior(Map.of(
"origin", OriginGroup.Builder.create()
.primaryOrigin(new S3Origin(myBucket))
.fallbackOrigin(new HttpOrigin("www.example.com"))
// optional, defaults to: 500, 502, 503 and 504
.fallbackStatusCodes(asList(404))
.build()))
.build();
Copyright © 2021. All rights reserved.