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.89.0 (build 2f74b3e)", date="2023-11-02T10:21:15.061Z") @Stability(Stable) public class Distribution extends Resource implements IDistribution
A CloudFront distribution with associated origin(s) and caching behavior(s).

Example:

 Bucket s3Bucket;
 // Add a cloudfront Function to a Distribution
 Function cfFunction = Function.Builder.create(this, "Function")
         .code(FunctionCode.fromInline("function handler(event) { return event.request }"))
         .build();
 Distribution.Builder.create(this, "distro")
         .defaultBehavior(BehaviorOptions.builder()
                 .origin(new S3Origin(s3Bucket))
                 .functionAssociations(List.of(FunctionAssociation.builder()
                         .function(cfFunction)
                         .eventType(FunctionEventType.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.
    • 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.