Show / Hide Table of Contents

Class Distribution

A CloudFront distribution with associated origin(s) and caching behavior(s).

Inheritance
object
Resource
Distribution
Implements
IDistribution
IResource
IDistributionRef
IConstruct
IDependable
IEnvironmentAware
Inherited Members
Resource.IsOwnedResource(IConstruct)
Resource.IsResource(IConstruct)
Resource.ApplyRemovalPolicy(RemovalPolicy)
Resource.GeneratePhysicalName()
Resource.GetResourceArnAttribute(string, IArnComponents)
Resource.GetResourceNameAttribute(string)
Resource.Env
Resource.PhysicalName
Resource.Stack
Namespace: Amazon.CDK.AWS.CloudFront
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Distribution : Resource, IDistribution, IResource, IDistributionRef, IConstruct, IDependable, IEnvironmentAware
Syntax (vb)
Public Class Distribution Inherits Resource Implements IDistribution, IResource, IDistributionRef, IConstruct, IDependable, IEnvironmentAware
Remarks

ExampleMetadata: infused

Examples
Bucket s3Bucket;
            // Add a cloudfront Function to a Distribution
            var cfFunction = new Function(this, "Function", new FunctionProps {
                Code = FunctionCode.FromInline("function handler(event) { return event.request }"),
                Runtime = FunctionRuntime.JS_2_0
            });
            new Distribution(this, "distro", new DistributionProps {
                DefaultBehavior = new BehaviorOptions {
                    Origin = new S3Origin(s3Bucket),
                    FunctionAssociations = new [] { new FunctionAssociation {
                        Function = cfFunction,
                        EventType = FunctionEventType.VIEWER_REQUEST
                    } }
                }
            });

Synopsis

Constructors

Distribution(Construct, string, IDistributionProps)

A CloudFront distribution with associated origin(s) and caching behavior(s).

Properties

DistributionArn

The distribution ARN for this distribution.

DistributionDomainName

The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.

DistributionId

The distribution ID for this distribution.

DistributionRef

A reference to a Distribution resource.

DomainName

The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.

PROPERTY_INJECTION_ID

Uniquely identifies this class.

Methods

AddBehavior(string, IOrigin, IAddBehaviorOptions?)

Adds a new behavior to this distribution for the given pathPattern.

AttachWebAclId(string)

Attach WAF WebACL to this CloudFront distribution.

FromDistributionAttributes(Construct, string, IDistributionAttributes)

Creates a Distribution construct that represents an external (imported) distribution.

Grant(IGrantable, params string[])

Adds an IAM policy statement associated with this distribution to an IAM principal's policy.

GrantCreateInvalidation(IGrantable)

Grant to create invalidations for this bucket to an IAM principal (Role/Group/User).

Metric(string, IMetricOptions?)

Return the given named metric for this Distribution.

Metric401ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 401.

Metric403ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 403.

Metric404ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 404.

Metric4xxErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx.

Metric502ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 502.

Metric503ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 503.

Metric504ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 504.

Metric5xxErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 5xx.

MetricBytesDownloaded(IMetricOptions?)

Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests.

MetricBytesUploaded(IMetricOptions?)

Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests.

MetricCacheHitRate(IMetricOptions?)

Metric for the percentage of all cacheable requests for which CloudFront served the content from its cache.

MetricOriginLatency(IMetricOptions?)

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.

MetricRequests(IMetricOptions?)

Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests.

MetricTotalErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx or 5xx.

Constructors

Distribution(Construct, string, IDistributionProps)

A CloudFront distribution with associated origin(s) and caching behavior(s).

public Distribution(Construct scope, string id, IDistributionProps props)
Parameters
scope Construct
id string
props IDistributionProps
Remarks

ExampleMetadata: infused

Examples
Bucket s3Bucket;
            // Add a cloudfront Function to a Distribution
            var cfFunction = new Function(this, "Function", new FunctionProps {
                Code = FunctionCode.FromInline("function handler(event) { return event.request }"),
                Runtime = FunctionRuntime.JS_2_0
            });
            new Distribution(this, "distro", new DistributionProps {
                DefaultBehavior = new BehaviorOptions {
                    Origin = new S3Origin(s3Bucket),
                    FunctionAssociations = new [] { new FunctionAssociation {
                        Function = cfFunction,
                        EventType = FunctionEventType.VIEWER_REQUEST
                    } }
                }
            });

Properties

DistributionArn

The distribution ARN for this distribution.

public virtual string DistributionArn { get; }
Property Value

string

Remarks

ExampleMetadata: infused

DistributionDomainName

The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.

public virtual string DistributionDomainName { get; }
Property Value

string

Remarks

ExampleMetadata: infused

DistributionId

The distribution ID for this distribution.

public virtual string DistributionId { get; }
Property Value

string

Remarks

ExampleMetadata: infused

DistributionRef

A reference to a Distribution resource.

public virtual IDistributionReference DistributionRef { get; }
Property Value

IDistributionReference

Remarks

ExampleMetadata: infused

DomainName

The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.

public virtual string DomainName { get; }
Property Value

string

Remarks

ExampleMetadata: infused

PROPERTY_INJECTION_ID

Uniquely identifies this class.

public static string PROPERTY_INJECTION_ID { get; }
Property Value

string

Remarks

ExampleMetadata: infused

Methods

AddBehavior(string, IOrigin, IAddBehaviorOptions?)

Adds a new behavior to this distribution for the given pathPattern.

public virtual void AddBehavior(string pathPattern, IOrigin origin, IAddBehaviorOptions? behaviorOptions = null)
Parameters
pathPattern string

the path pattern (e.g., 'images/*') that specifies which requests to apply the behavior to.

origin IOrigin

the origin to use for this behavior.

behaviorOptions IAddBehaviorOptions

the options for the behavior at this path.

Remarks

ExampleMetadata: infused

AttachWebAclId(string)

Attach WAF WebACL to this CloudFront distribution.

public virtual void AttachWebAclId(string webAclId)
Parameters
webAclId string

The WAF WebACL to associate with this distribution.

Remarks

WebACL must be in the us-east-1 region

FromDistributionAttributes(Construct, string, IDistributionAttributes)

Creates a Distribution construct that represents an external (imported) distribution.

public static IDistribution FromDistributionAttributes(Construct scope, string id, IDistributionAttributes attrs)
Parameters
scope Construct
id string
attrs IDistributionAttributes
Returns

IDistribution

Remarks

ExampleMetadata: infused

Grant(IGrantable, params string[])

Adds an IAM policy statement associated with this distribution to an IAM principal's policy.

public virtual Grant Grant(IGrantable identity, params string[] actions)
Parameters
identity IGrantable

The principal.

actions string[]

The set of actions to allow (i.e. "cloudfront:ListInvalidations").

Returns

Grant

Remarks

ExampleMetadata: infused

GrantCreateInvalidation(IGrantable)

Grant to create invalidations for this bucket to an IAM principal (Role/Group/User).

public virtual Grant GrantCreateInvalidation(IGrantable identity)
Parameters
identity IGrantable

The principal.

Returns

Grant

Remarks

ExampleMetadata: infused

Metric(string, IMetricOptions?)

Return the given named metric for this Distribution.

public virtual Metric Metric(string metricName, IMetricOptions? props = null)
Parameters
metricName string
props IMetricOptions
Returns

Metric

Remarks

ExampleMetadata: infused

Metric401ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 401.

public virtual Metric Metric401ErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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

Default: - average over 5 minutes

Metric403ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 403.

public virtual Metric Metric403ErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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

Default: - average over 5 minutes

Metric404ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 404.

public virtual Metric Metric404ErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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

Default: - average over 5 minutes

Metric4xxErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx.

public virtual Metric Metric4xxErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: - average over 5 minutes

Metric502ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 502.

public virtual Metric Metric502ErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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

Default: - average over 5 minutes

Metric503ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 503.

public virtual Metric Metric503ErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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

Default: - average over 5 minutes

Metric504ErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 504.

public virtual Metric Metric504ErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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

Default: - average over 5 minutes

Metric5xxErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 5xx.

public virtual Metric Metric5xxErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: - average over 5 minutes

MetricBytesDownloaded(IMetricOptions?)

Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests.

public virtual Metric MetricBytesDownloaded(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: - sum over 5 minutes

MetricBytesUploaded(IMetricOptions?)

Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests.

public virtual Metric MetricBytesUploaded(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: - sum over 5 minutes

MetricCacheHitRate(IMetricOptions?)

Metric for the percentage of all cacheable requests for which CloudFront served the content from its cache.

public virtual Metric MetricCacheHitRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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(IMetricOptions?)

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.

public virtual Metric MetricOriginLatency(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

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(IMetricOptions?)

Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests.

public virtual Metric MetricRequests(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: - sum over 5 minutes

MetricTotalErrorRate(IMetricOptions?)

Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx or 5xx.

public virtual Metric MetricTotalErrorRate(IMetricOptions? props = null)
Parameters
props IMetricOptions
Returns

Metric

Remarks

Default: - average over 5 minutes

Implements

IDistribution
IResource
IDistributionRef
Constructs.IConstruct
Constructs.IDependable
IEnvironmentAware
Back to top Generated by DocFX