Class CloudFrontWebDistribution

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.core.Construct
software.amazon.awscdk.core.Resource
software.amazon.awscdk.services.cloudfront.CloudFrontWebDistribution
All Implemented Interfaces:
IConstruct, IDependable, IResource, IDistribution, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:43.666Z") @Stability(Stable) public class CloudFrontWebDistribution extends Resource implements IDistribution
Amazon CloudFront is a global content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to your viewers with low latency and high transfer speeds.

CloudFront fronts user provided content and caches it at edge locations across the world.

Here's how you can use this construct:

 Bucket sourceBucket = new Bucket(this, "Bucket");
 CloudFrontWebDistribution distribution = CloudFrontWebDistribution.Builder.create(this, "MyDistribution")
         .originConfigs(List.of(SourceConfiguration.builder()
                 .s3OriginSource(S3OriginConfig.builder()
                         .s3BucketSource(sourceBucket)
                         .build())
                 .behaviors(List.of(Behavior.builder().isDefaultBehavior(true).build()))
                 .build()))
         .build();
 

This will create a CloudFront distribution that uses your S3Bucket as it's origin.

You can customize the distribution using additional properties from the CloudFrontWebDistributionProps interface.

Example:

 Bucket sourceBucket;
 ViewerCertificate viewerCertificate = ViewerCertificate.fromIamCertificate("MYIAMROLEIDENTIFIER", ViewerCertificateOptions.builder()
         .aliases(List.of("MYALIAS"))
         .build());
 CloudFrontWebDistribution.Builder.create(this, "MyCfWebDistribution")
         .originConfigs(List.of(SourceConfiguration.builder()
                 .s3OriginSource(S3OriginConfig.builder()
                         .s3BucketSource(sourceBucket)
                         .build())
                 .behaviors(List.of(Behavior.builder().isDefaultBehavior(true).build()))
                 .build()))
         .viewerCertificate(viewerCertificate)
         .build();
 
  • Constructor Details

    • CloudFrontWebDistribution

      protected CloudFrontWebDistribution(software.amazon.jsii.JsiiObjectRef objRef)
    • CloudFrontWebDistribution

      protected CloudFrontWebDistribution(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CloudFrontWebDistribution

      @Stability(Stable) public CloudFrontWebDistribution(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull CloudFrontWebDistributionProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromDistributionAttributes

      @Stability(Stable) @NotNull public static IDistribution fromDistributionAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull CloudFrontWebDistributionAttributes attrs)
      Creates a construct that represents an external (imported) distribution.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      attrs - This parameter is required.
    • getDistributionDomainName

      @Stability(Stable) @NotNull public String getDistributionDomainName()
      The domain name created by CloudFront for this distribution.

      If you are using aliases for your distribution, this is the domainName your DNS records should point to. (In Route53, you could create an ALIAS record to this value, for example.)

      Specified by:
      getDistributionDomainName in interface IDistribution
    • getDistributionId

      @Stability(Stable) @NotNull public String getDistributionId()
      The distribution ID for this distribution.
      Specified by:
      getDistributionId in interface IDistribution
    • getDomainName

      @Stability(Deprecated) @Deprecated @NotNull public String getDomainName()
      Deprecated.
      • Use distributionDomainName instead.
      (deprecated) The domain name created by CloudFront for this distribution.

      If you are using aliases for your distribution, this is the domainName your DNS records should point to. (In Route53, you could create an ALIAS record to this value, for example.)

      Specified by:
      getDomainName in interface IDistribution
    • getLoggingBucket

      @Stability(Stable) @Nullable public IBucket getLoggingBucket()
      The logging bucket for this CloudFront distribution.

      If logging is not enabled for this distribution - this property will be undefined.