Class Distribution

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

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-24T21:00:26.688Z") @Stability(Stable) public class Distribution extends Resource implements IDistribution
A CloudFront distribution with associated origin(s) and caching behavior(s).

Example:

 // Adding an existing Lambda@Edge function created in a different stack
 // to a CloudFront distribution.
 Bucket s3Bucket;
 IVersion functionVersion = Version.fromVersionArn(this, "Version", "arn:aws:lambda:us-east-1:123456789012:function:functionName:1");
 Distribution.Builder.create(this, "distro")
         .defaultBehavior(BehaviorOptions.builder()
                 .origin(new S3Origin(s3Bucket))
                 .edgeLambdas(List.of(EdgeLambda.builder()
                         .functionVersion(functionVersion)
                         .eventType(LambdaEdgeEventType.VIEWER_REQUEST)
                         .build()))
                 .build())
         .build();
 
  • Constructor Details

    • Distribution

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

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

      @Stability(Stable) public Distribution(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull DistributionProps 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 DistributionAttributes attrs)
      Creates a Distribution construct that represents an external (imported) distribution.

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

      @Stability(Stable) public void addBehavior(@NotNull String pathPattern, @NotNull IOrigin origin, @Nullable AddBehaviorOptions behaviorOptions)
      Adds a new behavior to this distribution for the given pathPattern.

      Parameters:
      pathPattern - the path pattern (e.g., 'images/*') that specifies which requests to apply the behavior to. This parameter is required.
      origin - the origin to use for this behavior. This parameter is required.
      behaviorOptions - the options for the behavior at this path.
    • addBehavior

      @Stability(Stable) public void addBehavior(@NotNull String pathPattern, @NotNull IOrigin origin)
      Adds a new behavior to this distribution for the given pathPattern.

      Parameters:
      pathPattern - the path pattern (e.g., 'images/*') that specifies which requests to apply the behavior to. This parameter is required.
      origin - the origin to use for this behavior. This parameter is required.
    • grant

      @Stability(Stable) @NotNull public Grant grant(@NotNull IGrantable identity, @NotNull @NotNull String... actions)
      Adds an IAM policy statement associated with this distribution to an IAM principal's policy.

      Specified by:
      grant in interface IDistribution
      Parameters:
      identity - The principal. This parameter is required.
      actions - The set of actions to allow (i.e. "cloudfront:ListInvalidations"). This parameter is required.
    • grantCreateInvalidation

      @Stability(Stable) @NotNull public Grant grantCreateInvalidation(@NotNull IGrantable identity)
      Grant to create invalidations for this bucket to an IAM principal (Role/Group/User).

      Specified by:
      grantCreateInvalidation in interface IDistribution
      Parameters:
      identity - The principal. This parameter is required.
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName, @Nullable MetricOptions props)
      Return the given named metric for this Distribution.

      Parameters:
      metricName - This parameter is required.
      props -
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName)
      Return the given named metric for this Distribution.

      Parameters:
      metricName - This parameter is required.
    • metric401ErrorRate

      @Stability(Stable) @NotNull public Metric metric401ErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 401.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric401ErrorRate

      @Stability(Stable) @NotNull public Metric metric401ErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 401.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metric403ErrorRate

      @Stability(Stable) @NotNull public Metric metric403ErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 403.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric403ErrorRate

      @Stability(Stable) @NotNull public Metric metric403ErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 403.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metric404ErrorRate

      @Stability(Stable) @NotNull public Metric metric404ErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 404.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric404ErrorRate

      @Stability(Stable) @NotNull public Metric metric404ErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 404.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metric4xxErrorRate

      @Stability(Stable) @NotNull public Metric metric4xxErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric4xxErrorRate

      @Stability(Stable) @NotNull public Metric metric4xxErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx.

      Default: - average over 5 minutes

    • metric502ErrorRate

      @Stability(Stable) @NotNull public Metric metric502ErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 502.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric502ErrorRate

      @Stability(Stable) @NotNull public Metric metric502ErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 502.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metric503ErrorRate

      @Stability(Stable) @NotNull public Metric metric503ErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 503.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric503ErrorRate

      @Stability(Stable) @NotNull public Metric metric503ErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 503.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metric504ErrorRate

      @Stability(Stable) @NotNull public Metric metric504ErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 504.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric504ErrorRate

      @Stability(Stable) @NotNull public Metric metric504ErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 504.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metric5xxErrorRate

      @Stability(Stable) @NotNull public Metric metric5xxErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 5xx.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metric5xxErrorRate

      @Stability(Stable) @NotNull public Metric metric5xxErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 5xx.

      Default: - average over 5 minutes

    • metricBytesDownloaded

      @Stability(Stable) @NotNull public Metric metricBytesDownloaded(@Nullable MetricOptions props)
      Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests.

      Default: - sum over 5 minutes

      Parameters:
      props -
    • metricBytesDownloaded

      @Stability(Stable) @NotNull public Metric metricBytesDownloaded()
      Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests.

      Default: - sum over 5 minutes

    • metricBytesUploaded

      @Stability(Stable) @NotNull public Metric metricBytesUploaded(@Nullable MetricOptions props)
      Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests.

      Default: - sum over 5 minutes

      Parameters:
      props -
    • metricBytesUploaded

      @Stability(Stable) @NotNull public Metric metricBytesUploaded()
      Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests.

      Default: - sum over 5 minutes

    • metricCacheHitRate

      @Stability(Stable) @NotNull public Metric metricCacheHitRate(@Nullable MetricOptions props)
      Metric for the percentage of all cacheable requests for which CloudFront served the content from its cache.

      HTTP POST and PUT requests, and errors, are not considered cacheable requests.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metricCacheHitRate

      @Stability(Stable) @NotNull public Metric metricCacheHitRate()
      Metric for the percentage of all cacheable requests for which CloudFront served the content from its cache.

      HTTP POST and PUT requests, and errors, are not considered cacheable requests.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metricOriginLatency

      @Stability(Stable) @NotNull public Metric metricOriginLatency(@Nullable MetricOptions props)
      Metric for the total time spent from when CloudFront receives a request to when it starts providing a response to the network (not the viewer), for requests that are served from the origin, not the CloudFront cache.

      This is also known as first byte latency, or time-to-first-byte.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metricOriginLatency

      @Stability(Stable) @NotNull public Metric metricOriginLatency()
      Metric for the total time spent from when CloudFront receives a request to when it starts providing a response to the network (not the viewer), for requests that are served from the origin, not the CloudFront cache.

      This is also known as first byte latency, or time-to-first-byte.

      To obtain this metric, you need to set publishAdditionalMetrics to true.

      Default: - average over 5 minutes

    • metricRequests

      @Stability(Stable) @NotNull public Metric metricRequests(@Nullable MetricOptions props)
      Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests.

      Default: - sum over 5 minutes

      Parameters:
      props -
    • metricRequests

      @Stability(Stable) @NotNull public Metric metricRequests()
      Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests.

      Default: - sum over 5 minutes

    • metricTotalErrorRate

      @Stability(Stable) @NotNull public Metric metricTotalErrorRate(@Nullable MetricOptions props)
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx or 5xx.

      Default: - average over 5 minutes

      Parameters:
      props -
    • metricTotalErrorRate

      @Stability(Stable) @NotNull public Metric metricTotalErrorRate()
      Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx or 5xx.

      Default: - average over 5 minutes

    • getDistributionDomainName

      @Stability(Stable) @NotNull public String getDistributionDomainName()
      The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
      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(Stable) @NotNull public String getDomainName()
      The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.