package
1.204.0-devpreview
Repository: https://github.com/aws/aws-cdk-go.git
Documentation: pkg.go.dev

# README

Amazon CloudFront Construct Library

Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users. CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you're serving with CloudFront, the user is routed to the edge location that provides the lowest latency, so that content is delivered with the best possible performance.

Distribution API

The Distribution API is currently being built to replace the existing CloudFrontWebDistribution API. The Distribution API is optimized for the most common use cases of CloudFront distributions (e.g., single origin and behavior, few customizations) while still providing the ability for more advanced use cases. The API focuses on simplicity for the common use cases, and convenience methods for creating the behaviors and origins necessary for more complex use cases.

Creating a distribution

CloudFront distributions deliver your content from one or more origins; an origin is the location where you store the original version of your content. Origins can be created from S3 buckets or a custom origin (HTTP server). Constructs to define origins are in the @aws-cdk/aws-cloudfront-origins module.

Each distribution has a default behavior which applies to all requests to that distribution, and routes requests to a primary origin. Additional behaviors may be specified for an origin with a given URL path pattern. Behaviors allow routing with multiple origins, controlling which HTTP methods to support, whether to require users to use HTTPS, and what query strings or cookies to forward to your origin, among other settings.

From an S3 Bucket

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.

// Creates a distribution from an S3 bucket.
myBucket := s3.NewBucket(this, jsii.String("myBucket"))
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(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.

ELBv2 Load Balancer

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.

// Creates a distribution from an ELBv2 load balancer
var vpc 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.
lb := elbv2.NewApplicationLoadBalancer(this, jsii.String("LB"), &ApplicationLoadBalancerProps{
	Vpc: Vpc,
	InternetFacing: jsii.Boolean(true),
})
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewLoadBalancerV2Origin(lb),
	},
})

From an HTTP endpoint

Origins can also be created from any other HTTP endpoint, given the domain name, and optionally, other origin properties.

// Creates a distribution from an HTTP endpoint
// Creates a distribution from an HTTP endpoint
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewHttpOrigin(jsii.String("www.example.com")),
	},
})

Domain Names and Certificates

When you create a distribution, CloudFront assigns a domain name for the distribution, for example: d111111abcdef8.cloudfront.net; this value can be retrieved from distribution.distributionDomainName. CloudFront distributions use a default certificate (*.cloudfront.net) to support HTTPS by default. If you want to use your own domain name, such as www.example.com, you must associate a certificate with your distribution that contains your domain name, and provide one (or more) domain names from the certificate for the distribution.

The certificate must be present in the AWS Certificate Manager (ACM) service in the US East (N. Virginia) region; the certificate may either be created by ACM, or created elsewhere and imported into ACM. When a certificate is used, the distribution will support HTTPS connections from SNI only and a minimum protocol version of TLSv1.2_2021 if the @aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021 feature flag is set, and TLSv1.2_2019 otherwise.

// To use your own domain name in a Distribution, you must associate a certificate
import acm "github.com/aws/aws-cdk-go/awscdk"
import route53 "github.com/aws/aws-cdk-go/awscdk"

var hostedZone hostedZone

var myBucket bucket

myCertificate := acm.NewDnsValidatedCertificate(this, jsii.String("mySiteCert"), &DnsValidatedCertificateProps{
	DomainName: jsii.String("www.example.com"),
	HostedZone: HostedZone,
})
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(myBucket),
	},
	DomainNames: []*string{
		jsii.String("www.example.com"),
	},
	Certificate: myCertificate,
})

However, you can customize the minimum protocol version for the certificate while creating the distribution using minimumProtocolVersion property.

// Create a Distribution with a custom domain name and a minimum protocol version.
var myBucket bucket

cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(myBucket),
	},
	DomainNames: []*string{
		jsii.String("www.example.com"),
	},
	MinimumProtocolVersion: cloudfront.SecurityPolicyProtocol_TLS_V1_2016,
	SslSupportMethod: cloudfront.SSLMethod_SNI,
})

Multiple Behaviors & Origins

Each distribution has a default behavior which applies to all requests to that distribution; additional behaviors may be specified for a given URL path pattern. Behaviors allow routing with multiple origins, controlling which HTTP methods to support, whether to require users to use HTTPS, and what query strings or cookies to forward to your origin, among others.

The properties of the default behavior can be adjusted as part of the distribution creation. The following example shows configuring the HTTP methods and viewer protocol policy of the cache.

// Create a Distribution with configured HTTP methods and viewer protocol policy of the cache.
var myBucket bucket

myWebDistribution := cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(myBucket),
		AllowedMethods: cloudfront.AllowedMethods_ALLOW_ALL(),
		ViewerProtocolPolicy: cloudfront.ViewerProtocolPolicy_REDIRECT_TO_HTTPS,
	},
})

Additional behaviors can be specified at creation, or added after the initial creation. Each additional behavior is associated with an origin, and enable customization for a specific set of resources based on a URL path pattern. For example, we can add a behavior to myWebDistribution to override the default viewer protocol policy for all of the images.

// Add a behavior to a Distribution after initial creation.
var myBucket bucket
var myWebDistribution distribution

myWebDistribution.AddBehavior(jsii.String("/images/*.jpg"), origins.NewS3Origin(myBucket), &AddBehaviorOptions{
	ViewerProtocolPolicy: cloudfront.ViewerProtocolPolicy_REDIRECT_TO_HTTPS,
})

These behaviors can also be specified at distribution creation time.

// Create a Distribution with additional behaviors at creation time.
var myBucket bucket

bucketOrigin := origins.NewS3Origin(myBucket)
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		AllowedMethods: cloudfront.AllowedMethods_ALLOW_ALL(),
		ViewerProtocolPolicy: cloudfront.ViewerProtocolPolicy_REDIRECT_TO_HTTPS,
	},
	AdditionalBehaviors: map[string]behaviorOptions{
		"/images/*.jpg": &behaviorOptions{
			"origin": bucketOrigin,
			"viewerProtocolPolicy": cloudfront.ViewerProtocolPolicy_REDIRECT_TO_HTTPS,
		},
	},
})

Customizing Cache Keys and TTLs with Cache Policies

You can use a cache policy to improve your cache hit ratio by controlling the values (URL query strings, HTTP headers, and cookies) that are included in the cache key, and/or adjusting how long items remain in the cache via the time-to-live (TTL) settings. CloudFront provides some predefined cache policies, known as managed policies, for common use cases. You can use these managed policies, or you can create your own cache policy that’s specific to your needs. See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html for more details.

// Using an existing cache policy for a Distribution
var bucketOrigin s3Origin

cloudfront.NewDistribution(this, jsii.String("myDistManagedPolicy"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		CachePolicy: cloudfront.CachePolicy_CACHING_OPTIMIZED(),
	},
})
// Creating a custom cache policy for a Distribution -- all parameters optional
var bucketOrigin s3Origin

myCachePolicy := cloudfront.NewCachePolicy(this, jsii.String("myCachePolicy"), &CachePolicyProps{
	CachePolicyName: jsii.String("MyPolicy"),
	Comment: jsii.String("A default policy"),
	DefaultTtl: awscdk.Duration_Days(jsii.Number(2)),
	MinTtl: awscdk.Duration_Minutes(jsii.Number(1)),
	MaxTtl: awscdk.Duration_*Days(jsii.Number(10)),
	CookieBehavior: cloudfront.CacheCookieBehavior_All(),
	HeaderBehavior: cloudfront.CacheHeaderBehavior_AllowList(jsii.String("X-CustomHeader")),
	QueryStringBehavior: cloudfront.CacheQueryStringBehavior_DenyList(jsii.String("username")),
	EnableAcceptEncodingGzip: jsii.Boolean(true),
	EnableAcceptEncodingBrotli: jsii.Boolean(true),
})
cloudfront.NewDistribution(this, jsii.String("myDistCustomPolicy"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		CachePolicy: myCachePolicy,
	},
})

Customizing Origin Requests with Origin Request Policies

When CloudFront makes a request to an origin, the URL path, request body (if present), and a few standard headers are included. Other information from the viewer request, such as URL query strings, HTTP headers, and cookies, is not included in the origin request by default. You can use an origin request policy to control the information that’s included in an origin request. CloudFront provides some predefined origin request policies, known as managed policies, for common use cases. You can use these managed policies, or you can create your own origin request policy that’s specific to your needs. See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html for more details.

// Using an existing origin request policy for a Distribution
var bucketOrigin s3Origin

cloudfront.NewDistribution(this, jsii.String("myDistManagedPolicy"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		OriginRequestPolicy: cloudfront.OriginRequestPolicy_CORS_S3_ORIGIN(),
	},
})
// Creating a custom origin request policy for a Distribution -- all parameters optional
var bucketOrigin s3Origin

myOriginRequestPolicy := cloudfront.NewOriginRequestPolicy(this, jsii.String("OriginRequestPolicy"), &OriginRequestPolicyProps{
	OriginRequestPolicyName: jsii.String("MyPolicy"),
	Comment: jsii.String("A default policy"),
	CookieBehavior: cloudfront.OriginRequestCookieBehavior_None(),
	HeaderBehavior: cloudfront.OriginRequestHeaderBehavior_All(jsii.String("CloudFront-Is-Android-Viewer")),
	QueryStringBehavior: cloudfront.OriginRequestQueryStringBehavior_AllowList(jsii.String("username")),
})

cloudfront.NewDistribution(this, jsii.String("myDistCustomPolicy"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		OriginRequestPolicy: myOriginRequestPolicy,
	},
})

Customizing Response Headers with Response Headers Policies

You can configure CloudFront to add one or more HTTP headers to the responses that it sends to viewers (web browsers or other clients), without making any changes to the origin or writing any code. To specify the headers that CloudFront adds to HTTP responses, you use a response headers policy. CloudFront adds the headers regardless of whether it serves the object from the cache or has to retrieve the object from the origin. If the origin response includes one or more of the headers that’s in a response headers policy, the policy can specify whether CloudFront uses the header it received from the origin or overwrites it with the one in the policy. See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-response-headers.html

// Using an existing managed response headers policy
var bucketOrigin s3Origin

cloudfront.NewDistribution(this, jsii.String("myDistManagedPolicy"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		ResponseHeadersPolicy: cloudfront.ResponseHeadersPolicy_CORS_ALLOW_ALL_ORIGINS(),
	},
})

// Creating a custom response headers policy -- all parameters optional
myResponseHeadersPolicy := cloudfront.NewResponseHeadersPolicy(this, jsii.String("ResponseHeadersPolicy"), &ResponseHeadersPolicyProps{
	ResponseHeadersPolicyName: jsii.String("MyPolicy"),
	Comment: jsii.String("A default policy"),
	CorsBehavior: &ResponseHeadersCorsBehavior{
		AccessControlAllowCredentials: jsii.Boolean(false),
		AccessControlAllowHeaders: []*string{
			jsii.String("X-Custom-Header-1"),
			jsii.String("X-Custom-Header-2"),
		},
		AccessControlAllowMethods: []*string{
			jsii.String("GET"),
			jsii.String("POST"),
		},
		AccessControlAllowOrigins: []*string{
			jsii.String("*"),
		},
		AccessControlExposeHeaders: []*string{
			jsii.String("X-Custom-Header-1"),
			jsii.String("X-Custom-Header-2"),
		},
		AccessControlMaxAge: awscdk.Duration_Seconds(jsii.Number(600)),
		OriginOverride: jsii.Boolean(true),
	},
	CustomHeadersBehavior: &ResponseCustomHeadersBehavior{
		CustomHeaders: []responseCustomHeader{
			&responseCustomHeader{
				Header: jsii.String("X-Amz-Date"),
				Value: jsii.String("some-value"),
				Override: jsii.Boolean(true),
			},
			&responseCustomHeader{
				Header: jsii.String("X-Amz-Security-Token"),
				Value: jsii.String("some-value"),
				Override: jsii.Boolean(false),
			},
		},
	},
	SecurityHeadersBehavior: &ResponseSecurityHeadersBehavior{
		ContentSecurityPolicy: &ResponseHeadersContentSecurityPolicy{
			ContentSecurityPolicy: jsii.String("default-src https:;"),
			Override: jsii.Boolean(true),
		},
		ContentTypeOptions: &ResponseHeadersContentTypeOptions{
			Override: jsii.Boolean(true),
		},
		FrameOptions: &ResponseHeadersFrameOptions{
			FrameOption: cloudfront.HeadersFrameOption_DENY,
			Override: jsii.Boolean(true),
		},
		ReferrerPolicy: &ResponseHeadersReferrerPolicy{
			ReferrerPolicy: cloudfront.HeadersReferrerPolicy_NO_REFERRER,
			Override: jsii.Boolean(true),
		},
		StrictTransportSecurity: &ResponseHeadersStrictTransportSecurity{
			AccessControlMaxAge: awscdk.Duration_*Seconds(jsii.Number(600)),
			IncludeSubdomains: jsii.Boolean(true),
			Override: jsii.Boolean(true),
		},
		XssProtection: &ResponseHeadersXSSProtection{
			Protection: jsii.Boolean(true),
			ModeBlock: jsii.Boolean(true),
			ReportUri: jsii.String("https://example.com/csp-report"),
			Override: jsii.Boolean(true),
		},
	},
})
cloudfront.NewDistribution(this, jsii.String("myDistCustomPolicy"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: bucketOrigin,
		ResponseHeadersPolicy: myResponseHeadersPolicy,
	},
})

Validating signed URLs or signed cookies with Trusted Key Groups

CloudFront Distribution supports validating signed URLs or signed cookies using key groups. When a cache behavior contains trusted key groups, CloudFront requires signed URLs or signed cookies for all requests that match the cache behavior.

// Validating signed URLs or signed cookies with Trusted Key Groups

// public key in PEM format
var publicKey string

pubKey := cloudfront.NewPublicKey(this, jsii.String("MyPubKey"), &PublicKeyProps{
	EncodedKey: publicKey,
})

keyGroup := cloudfront.NewKeyGroup(this, jsii.String("MyKeyGroup"), &KeyGroupProps{
	Items: []iPublicKey{
		pubKey,
	},
})

cloudfront.NewDistribution(this, jsii.String("Dist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewHttpOrigin(jsii.String("www.example.com")),
		TrustedKeyGroups: []iKeyGroup{
			keyGroup,
		},
	},
})

Lambda@Edge

Lambda@Edge is an extension of AWS Lambda, a compute service that lets you execute functions that customize the content that CloudFront delivers. You can author Node.js or Python functions in the US East (N. Virginia) region, and then execute them in AWS locations globally that are closer to the viewer, without provisioning or managing servers. Lambda@Edge functions are associated with a specific behavior and event type. Lambda@Edge can be used to rewrite URLs, alter responses based on headers or cookies, or authorize requests based on headers or authorization tokens.

The following shows a Lambda@Edge function added to the default behavior and triggered on every request:

var myBucket bucket
// A Lambda@Edge function added to default behavior of a Distribution
// and triggered on every request
myFunc := experimental.NewEdgeFunction(this, jsii.String("MyFunction"), &EdgeFunctionProps{
	Runtime: lambda.Runtime_NODEJS_14_X(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("lambda-handler"))),
})
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(myBucket),
		EdgeLambdas: []edgeLambda{
			&edgeLambda{
				FunctionVersion: myFunc.currentVersion,
				EventType: cloudfront.LambdaEdgeEventType_VIEWER_REQUEST,
			},
		},
	},
})

Note: Lambda@Edge functions must be created in the us-east-1 region, regardless of the region of the CloudFront distribution and stack. To make it easier to request functions for Lambda@Edge, the EdgeFunction construct can be used. The EdgeFunction construct will automatically request a function in us-east-1, regardless of the region of the current stack. EdgeFunction has the same interface as Function and can be created and used interchangeably. Please note that using EdgeFunction requires that the us-east-1 region has been bootstrapped. See https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html for more about bootstrapping regions.

If the stack is in us-east-1, a "normal" lambda.Function can be used instead of an EdgeFunction.

// Using a lambda Function instead of an EdgeFunction for stacks in `us-east-`.
myFunc := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
	Runtime: lambda.Runtime_NODEJS_14_X(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("lambda-handler"))),
})

If the stack is not in us-east-1, and you need references from different applications on the same account, you can also set a specific stack ID for each Lambda@Edge.

// Setting stackIds for EdgeFunctions that can be referenced from different applications
// on the same account.
myFunc1 := experimental.NewEdgeFunction(this, jsii.String("MyFunction1"), &EdgeFunctionProps{
	Runtime: lambda.Runtime_NODEJS_14_X(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("lambda-handler1"))),
	StackId: jsii.String("edge-lambda-stack-id-1"),
})

myFunc2 := experimental.NewEdgeFunction(this, jsii.String("MyFunction2"), &EdgeFunctionProps{
	Runtime: lambda.Runtime_NODEJS_14_X(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_*FromAsset(path.join(__dirname, jsii.String("lambda-handler2"))),
	StackId: jsii.String("edge-lambda-stack-id-2"),
})

Lambda@Edge functions can also be associated with additional behaviors, either at or after Distribution creation time.

// Associating a Lambda@Edge function with additional behaviors.

var myFunc edgeFunction
// assigning at Distribution creation
var myBucket bucket

myOrigin := origins.NewS3Origin(myBucket)
myDistribution := cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: myOrigin,
	},
	AdditionalBehaviors: map[string]behaviorOptions{
		"images/*": &behaviorOptions{
			"origin": myOrigin,
			"edgeLambdas": []EdgeLambda{
				&EdgeLambda{
					"functionVersion": myFunc.currentVersion,
					"eventType": cloudfront.LambdaEdgeEventType_ORIGIN_REQUEST,
					"includeBody": jsii.Boolean(true),
				},
			},
		},
	},
})

// assigning after creation
myDistribution.AddBehavior(jsii.String("images/*"), myOrigin, &AddBehaviorOptions{
	EdgeLambdas: []edgeLambda{
		&edgeLambda{
			FunctionVersion: myFunc.currentVersion,
			EventType: cloudfront.LambdaEdgeEventType_VIEWER_RESPONSE,
		},
	},
})

Adding an existing Lambda@Edge function created in a different stack to a CloudFront distribution.

// Adding an existing Lambda@Edge function created in a different stack
// to a CloudFront distribution.
var s3Bucket bucket

functionVersion := lambda.Version_FromVersionArn(this, jsii.String("Version"), jsii.String("arn:aws:lambda:us-east-1:123456789012:function:functionName:1"))

cloudfront.NewDistribution(this, jsii.String("distro"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(s3Bucket),
		EdgeLambdas: []edgeLambda{
			&edgeLambda{
				FunctionVersion: *FunctionVersion,
				EventType: cloudfront.LambdaEdgeEventType_VIEWER_REQUEST,
			},
		},
	},
})

CloudFront Function

You can also deploy CloudFront functions and add them to a CloudFront distribution.

var s3Bucket bucket
// Add a cloudfront Function to a Distribution
cfFunction := cloudfront.NewFunction(this, jsii.String("Function"), &FunctionProps{
	Code: cloudfront.FunctionCode_FromInline(jsii.String("function handler(event) { return event.request }")),
})
cloudfront.NewDistribution(this, jsii.String("distro"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(s3Bucket),
		FunctionAssociations: []functionAssociation{
			&functionAssociation{
				Function: cfFunction,
				EventType: cloudfront.FunctionEventType_VIEWER_REQUEST,
			},
		},
	},
})

It will auto-generate the name of the function and deploy it to the live stage.

Additionally, you can load the function's code from a file using the FunctionCode.fromFile() method.

Logging

You can configure CloudFront to create log files that contain detailed information about every user request that CloudFront receives. The logs can go to either an existing bucket, or a bucket will be created for you.

// Configure logging for Distributions

// Simplest form - creates a new bucket and logs to it.
// Configure logging for Distributions
// Simplest form - creates a new bucket and logs to it.
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewHttpOrigin(jsii.String("www.example.com")),
	},
	EnableLogging: jsii.Boolean(true),
})

// You can optionally log to a specific bucket, configure whether cookies are logged, and give the log files a prefix.
// You can optionally log to a specific bucket, configure whether cookies are logged, and give the log files a prefix.
cloudfront.NewDistribution(this, jsii.String("myDist"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewHttpOrigin(jsii.String("www.example.com")),
	},
	EnableLogging: jsii.Boolean(true),
	 // Optional, this is implied if logBucket is specified
	LogBucket: s3.NewBucket(this, jsii.String("LogBucket")),
	LogFilePrefix: jsii.String("distribution-access-logs/"),
	LogIncludesCookies: jsii.Boolean(true),
})

Importing Distributions

Existing distributions can be imported as well; note that like most imported constructs, an imported distribution cannot be modified. However, it can be used as a reference for other higher-level constructs.

// Using a reference to an imported Distribution
distribution := cloudfront.Distribution_FromDistributionAttributes(this, jsii.String("ImportedDist"), &DistributionAttributes{
	DomainName: jsii.String("d111111abcdef8.cloudfront.net"),
	DistributionId: jsii.String("012345ABCDEF"),
})

Migrating from the original CloudFrontWebDistribution to the newer Distribution construct

It's possible to migrate a distribution from the original to the modern API. The changes necessary are the following:

The Distribution

Replace new CloudFrontWebDistribution with new Distribution. Some configuration properties have been changed:

Old APINew API
originConfigsdefaultBehavior; use additionalBehaviors if necessary
viewerCertificatecertificate; use domainNames for aliases
errorConfigurationserrorResponses
loggingConfigenableLogging; configure with logBucket logFilePrefix and logIncludesCookies
viewerProtocolPolicyremoved; set on each behavior instead. default changed from REDIRECT_TO_HTTPS to ALLOW_ALL

After switching constructs, you need to maintain the same logical ID for the underlying CfnDistribution if you wish to avoid the deletion and recreation of your distribution. To do this, use escape hatches to override the logical ID created by the new Distribution construct with the logical ID created by the old construct.

Example:

var sourceBucket bucket


myDistribution := cloudfront.NewDistribution(this, jsii.String("MyCfWebDistribution"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(sourceBucket),
	},
})
cfnDistribution := myDistribution.Node.defaultChild.(cfnDistribution)
cfnDistribution.OverrideLogicalId(jsii.String("MyDistributionCFDistribution3H55TI9Q"))

Behaviors

The modern API makes use of the CloudFront Origins module to easily configure your origin. Replace your origin configuration with the relevant CloudFront Origins class. For example, here's a behavior with an S3 origin:

var sourceBucket bucket
var oai originAccessIdentity


cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyCfWebDistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: sourceBucket,
				OriginAccessIdentity: oai,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
})

Becomes:

var sourceBucket bucket


distribution := cloudfront.NewDistribution(this, jsii.String("MyCfWebDistribution"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(sourceBucket),
	},
})

In the original API all behaviors are defined in the originConfigs property. The new API is optimized for a single origin and behavior, so the default behavior and additional behaviors will be defined separately.

var sourceBucket bucket
var oai originAccessIdentity


cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyCfWebDistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: sourceBucket,
				OriginAccessIdentity: oai,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
		&sourceConfiguration{
			CustomOriginSource: &CustomOriginConfig{
				DomainName: jsii.String("MYALIAS"),
			},
			Behaviors: []*behavior{
				&behavior{
					PathPattern: jsii.String("/somewhere"),
				},
			},
		},
	},
})

Becomes:

var sourceBucket bucket


distribution := cloudfront.NewDistribution(this, jsii.String("MyCfWebDistribution"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(sourceBucket),
	},
	AdditionalBehaviors: map[string]behaviorOptions{
		"/somewhere": &behaviorOptions{
			"origin": origins.NewHttpOrigin(jsii.String("MYALIAS")),
		},
	},
})

Certificates

If you are using an ACM certificate, you can pass the certificate directly to the certificate prop. Any aliases used before in the ViewerCertificate class should be passed in to the domainNames prop in the modern API.

import acm "github.com/aws/aws-cdk-go/awscdk"
var certificate certificate
var sourceBucket bucket


viewerCertificate := cloudfront.ViewerCertificate_FromAcmCertificate(certificate, &ViewerCertificateOptions{
	Aliases: []*string{
		jsii.String("MYALIAS"),
	},
})

cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyCfWebDistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: sourceBucket,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
	ViewerCertificate: viewerCertificate,
})

Becomes:

import acm "github.com/aws/aws-cdk-go/awscdk"
var certificate certificate
var sourceBucket bucket


distribution := cloudfront.NewDistribution(this, jsii.String("MyCfWebDistribution"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(sourceBucket),
	},
	DomainNames: []*string{
		jsii.String("MYALIAS"),
	},
	Certificate: certificate,
})

IAM certificates aren't directly supported by the new API, but can be easily configured through escape hatches

var sourceBucket bucket

viewerCertificate := cloudfront.ViewerCertificate_FromIamCertificate(jsii.String("MYIAMROLEIDENTIFIER"), &ViewerCertificateOptions{
	Aliases: []*string{
		jsii.String("MYALIAS"),
	},
})

cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyCfWebDistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: sourceBucket,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
	ViewerCertificate: viewerCertificate,
})

Becomes:

var sourceBucket bucket

distribution := cloudfront.NewDistribution(this, jsii.String("MyCfWebDistribution"), &DistributionProps{
	DefaultBehavior: &BehaviorOptions{
		Origin: origins.NewS3Origin(sourceBucket),
	},
	DomainNames: []*string{
		jsii.String("MYALIAS"),
	},
})

cfnDistribution := distribution.Node.defaultChild.(cfnDistribution)

cfnDistribution.AddPropertyOverride(jsii.String("ViewerCertificate.IamCertificateId"), jsii.String("MYIAMROLEIDENTIFIER"))
cfnDistribution.AddPropertyOverride(jsii.String("ViewerCertificate.SslSupportMethod"), jsii.String("sni-only"))

Other changes

A number of default settings have changed on the new API when creating a new distribution, behavior, and origin. After making the major changes needed for the migration, run cdk diff to see what settings have changed. If no changes are desired during migration, you will at the least be able to use escape hatches to override what the CDK synthesizes, if you can't change the properties directly.

CloudFrontWebDistribution API

The CloudFrontWebDistribution construct is the original construct written for working with CloudFront distributions. Users are encouraged to use the newer Distribution instead, as it has a simpler interface and receives new features faster.

Example usage:

// Using a CloudFrontWebDistribution construct.

var sourceBucket bucket

distribution := cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyDistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: sourceBucket,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
})

Viewer certificate

By default, CloudFront Web Distributions will answer HTTPS requests with CloudFront's default certificate, only containing the distribution domainName (e.g. d111111abcdef8.cloudfront.net). You can customize the viewer certificate property to provide a custom certificate and/or list of domain name aliases to fit your needs.

See Using Alternate Domain Names and HTTPS in the CloudFront User Guide.

Default certificate

You can customize the default certificate aliases. This is intended to be used in combination with CNAME records in your DNS zone.

Example:

s3BucketSource := s3.NewBucket(this, jsii.String("Bucket"))

distribution := cloudfront.NewCloudFrontWebDistribution(this, jsii.String("AnAmazingWebsiteProbably"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: *S3BucketSource,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
	ViewerCertificate: cloudfront.ViewerCertificate_FromCloudFrontDefaultCertificate(jsii.String("www.example.com")),
})

ACM certificate

You can change the default certificate by one stored AWS Certificate Manager, or ACM. Those certificate can either be generated by AWS, or purchased by another CA imported into ACM.

For more information, see the aws-certificatemanager module documentation or Importing Certificates into AWS Certificate Manager in the AWS Certificate Manager User Guide.

Example:

s3BucketSource := s3.NewBucket(this, jsii.String("Bucket"))

certificate := certificatemanager.NewCertificate(this, jsii.String("Certificate"), &CertificateProps{
	DomainName: jsii.String("example.com"),
	SubjectAlternativeNames: []*string{
		jsii.String("*.example.com"),
	},
})

distribution := cloudfront.NewCloudFrontWebDistribution(this, jsii.String("AnAmazingWebsiteProbably"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: *S3BucketSource,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
	ViewerCertificate: cloudfront.ViewerCertificate_FromAcmCertificate(certificate, &ViewerCertificateOptions{
		Aliases: []*string{
			jsii.String("example.com"),
			jsii.String("www.example.com"),
		},
		SecurityPolicy: cloudfront.SecurityPolicyProtocol_TLS_V1,
		 // default
		SslMethod: cloudfront.SSLMethod_SNI,
	}),
})

IAM certificate

You can also import a certificate into the IAM certificate store.

See Importing an SSL/TLS Certificate in the CloudFront User Guide.

Example:

s3BucketSource := s3.NewBucket(this, jsii.String("Bucket"))

distribution := cloudfront.NewCloudFrontWebDistribution(this, jsii.String("AnAmazingWebsiteProbably"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: *S3BucketSource,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
	ViewerCertificate: cloudfront.ViewerCertificate_FromIamCertificate(jsii.String("certificateId"), &ViewerCertificateOptions{
		Aliases: []*string{
			jsii.String("example.com"),
		},
		SecurityPolicy: cloudfront.SecurityPolicyProtocol_SSL_V3,
		 // default
		SslMethod: cloudfront.SSLMethod_SNI,
	}),
})

Trusted Key Groups

CloudFront Web Distributions supports validating signed URLs or signed cookies using key groups. When a cache behavior contains trusted key groups, CloudFront requires signed URLs or signed cookies for all requests that match the cache behavior.

Example:

// Using trusted key groups for Cloudfront Web Distributions.
var sourceBucket bucket
var publicKey string

pubKey := cloudfront.NewPublicKey(this, jsii.String("MyPubKey"), &PublicKeyProps{
	EncodedKey: publicKey,
})

keyGroup := cloudfront.NewKeyGroup(this, jsii.String("MyKeyGroup"), &KeyGroupProps{
	Items: []iPublicKey{
		pubKey,
	},
})

cloudfront.NewCloudFrontWebDistribution(this, jsii.String("AnAmazingWebsiteProbably"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: sourceBucket,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
					TrustedKeyGroups: []iKeyGroup{
						keyGroup,
					},
				},
			},
		},
	},
})

Restrictions

CloudFront supports adding restrictions to your distribution.

See Restricting the Geographic Distribution of Your Content in the CloudFront User Guide.

Example:

// Adding restrictions to a Cloudfront Web Distribution.
var sourceBucket bucket

cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyDistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: sourceBucket,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
	GeoRestriction: cloudfront.GeoRestriction_Allowlist(jsii.String("US"), jsii.String("GB")),
})

Connection behaviors between CloudFront and your origin

CloudFront provides you even more control over the connection behaviors between CloudFront and your origin. You can now configure the number of connection attempts CloudFront will make to your origin and the origin connection timeout for each attempt.

See Origin Connection Attempts

See Origin Connection Timeout

Example usage:

// Configuring connection behaviors between Cloudfront and your origin
distribution := cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyDistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			ConnectionAttempts: jsii.Number(3),
			ConnectionTimeout: awscdk.Duration_Seconds(jsii.Number(10)),
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
})

Origin Fallback

In case the origin source is not available and answers with one of the specified status codes the failover origin source will be used.

// Configuring origin fallback options for the CloudFrontWebDistribution
// Configuring origin fallback options for the CloudFrontWebDistribution
cloudfront.NewCloudFrontWebDistribution(this, jsii.String("ADistribution"), &CloudFrontWebDistributionProps{
	OriginConfigs: []sourceConfiguration{
		&sourceConfiguration{
			S3OriginSource: &S3OriginConfig{
				S3BucketSource: s3.Bucket_FromBucketName(this, jsii.String("aBucket"), jsii.String("myoriginbucket")),
				OriginPath: jsii.String("/"),
				OriginHeaders: map[string]*string{
					"myHeader": jsii.String("42"),
				},
				OriginShieldRegion: jsii.String("us-west-2"),
			},
			FailoverS3OriginSource: &S3OriginConfig{
				S3BucketSource: s3.Bucket_*FromBucketName(this, jsii.String("aBucketFallback"), jsii.String("myoriginbucketfallback")),
				OriginPath: jsii.String("/somewhere"),
				OriginHeaders: map[string]*string{
					"myHeader2": jsii.String("21"),
				},
				OriginShieldRegion: jsii.String("us-east-1"),
			},
			FailoverCriteriaStatusCodes: []failoverStatusCode{
				cloudfront.*failoverStatusCode_INTERNAL_SERVER_ERROR,
			},
			Behaviors: []behavior{
				&behavior{
					IsDefaultBehavior: jsii.Boolean(true),
				},
			},
		},
	},
})

KeyGroup & PublicKey API

You can create a key group to use with CloudFront signed URLs and signed cookies You can add public keys to use with CloudFront features such as signed URLs, signed cookies, and field-level encryption.

The following example command uses OpenSSL to generate an RSA key pair with a length of 2048 bits and save to the file named private_key.pem.

openssl genrsa -out private_key.pem 2048

The resulting file contains both the public and the private key. The following example command extracts the public key from the file named private_key.pem and stores it in public_key.pem.

openssl rsa -pubout -in private_key.pem -out public_key.pem

Note: Don't forget to copy/paste the contents of public_key.pem file including -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- lines into encodedKey parameter when creating a PublicKey.

Example:

// Create a key group to use with CloudFront signed URLs and signed cookies.
// Create a key group to use with CloudFront signed URLs and signed cookies.
cloudfront.NewKeyGroup(this, jsii.String("MyKeyGroup"), &KeyGroupProps{
	Items: []iPublicKey{
		cloudfront.NewPublicKey(this, jsii.String("MyPublicKey"), &PublicKeyProps{
			EncodedKey: jsii.String("..."),
		}),
	},
})

See:

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
All cookies in viewer requests are included in the cache key and are automatically included in requests that CloudFront sends to the origin.
Only the provided `cookies` are included in the cache key and automatically included in requests that CloudFront sends to the origin.
All cookies except the provided `cookies` are included in the cache key and automatically included in requests that CloudFront sends to the origin.
Cookies in viewer requests are not included in the cache key and are not automatically included in requests that CloudFront sends to the origin.
No description provided by the author
No description provided by the author
Listed headers are included in the cache key and are automatically included in requests that CloudFront sends to the origin.
HTTP headers are not included in the cache key and are not automatically included in requests that CloudFront sends to the origin.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Imports a Cache Policy from its id.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
All query strings in viewer requests are included in the cache key and are automatically included in requests that CloudFront sends to the origin.
Only the provided `queryStrings` are included in the cache key and automatically included in requests that CloudFront sends to the origin.
All query strings except the provided `queryStrings` are included in the cache key and automatically included in requests that CloudFront sends to the origin.
Query strings in viewer requests are not included in the cache key and are not automatically included in requests that CloudFront sends to the origin.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
No description provided by the author
Returns `true` if a construct is a stack element (i.e.
Check whether the given construct is a CfnResource.
Return whether the given object is a Construct.
Creates a construct that represents an external (imported) distribution.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
Creates a Distribution construct that represents an external (imported) distribution.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
Imports a function by its name and ARN.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
Code from external file for function.
Inline code for function.
Allow specific countries which you want CloudFront to distribute your content.
DEPRECATED.
Deny specific countries which you don't want CloudFront to distribute your content.
DEPRECATED.
Imports a Key Group from its id.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
Experimental.
Experimental.
Create a new `AWS::CloudFront::CachePolicy`.
Create a new `AWS::CloudFront::CachePolicy`.
Create a new `AWS::CloudFront::CloudFrontOriginAccessIdentity`.
Create a new `AWS::CloudFront::CloudFrontOriginAccessIdentity`.
Create a new `AWS::CloudFront::ContinuousDeploymentPolicy`.
Create a new `AWS::CloudFront::ContinuousDeploymentPolicy`.
Create a new `AWS::CloudFront::Distribution`.
Create a new `AWS::CloudFront::Distribution`.
Create a new `AWS::CloudFront::Function`.
Create a new `AWS::CloudFront::Function`.
Create a new `AWS::CloudFront::KeyGroup`.
Create a new `AWS::CloudFront::KeyGroup`.
Create a new `AWS::CloudFront::MonitoringSubscription`.
Create a new `AWS::CloudFront::MonitoringSubscription`.
Create a new `AWS::CloudFront::OriginAccessControl`.
Create a new `AWS::CloudFront::OriginAccessControl`.
Create a new `AWS::CloudFront::OriginRequestPolicy`.
Create a new `AWS::CloudFront::OriginRequestPolicy`.
Create a new `AWS::CloudFront::PublicKey`.
Create a new `AWS::CloudFront::PublicKey`.
Create a new `AWS::CloudFront::RealtimeLogConfig`.
Create a new `AWS::CloudFront::RealtimeLogConfig`.
Create a new `AWS::CloudFront::ResponseHeadersPolicy`.
Create a new `AWS::CloudFront::ResponseHeadersPolicy`.
Create a new `AWS::CloudFront::StreamingDistribution`.
Create a new `AWS::CloudFront::StreamingDistribution`.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Creates a OriginAccessIdentity by providing the OriginAccessIdentityName.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
All cookies in viewer requests are included in requests that CloudFront sends to the origin.
Only the provided `cookies` are included in requests that CloudFront sends to the origin.
Cookies in viewer requests are not included in requests that CloudFront sends to the origin.
All HTTP headers in viewer requests are included in requests that CloudFront sends to the origin.
Listed headers are included in requests that CloudFront sends to the origin.
HTTP headers are not included in requests that CloudFront sends to the origin.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Imports a Origin Request Policy from its id.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
No description provided by the author
All query strings in viewer requests are included in requests that CloudFront sends to the origin.
Only the provided `queryStrings` are included in requests that CloudFront sends to the origin.
Query strings in viewer requests are not included in requests that CloudFront sends to the origin.
Imports a Public Key from its id.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Import an existing Response Headers Policy from its ID.
Return whether the given object is a Construct.
Check whether the given construct is a Resource.
No description provided by the author
Generate an AWS Certificate Manager (ACM) viewer certificate configuration.
Generate a viewer certifcate configuration using the CloudFront default certificate (e.g.
Generate an IAM viewer certificate configuration.

# Constants

Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Bad Gateway (502).
Forbidden (403).
Gateway Timeout (504).
Internal Server Error (500).
Not found (404).
Service Unavailable (503).
The viewer-request specifies the incoming request.
The viewer-response specifies the outgoing response.
The page can only be displayed in a frame on the same origin as the page itself.
The page can only be displayed in a frame on the specified origin.
The referrer policy is not set.
The referrer policy is no-referrer-when-downgrade.
The referrer policy is origin.
The referrer policy is origin-when-cross-origin.
The referrer policy is same-origin.
The referrer policy is strict-origin.
The referrer policy is strict-origin-when-cross-origin.
The referrer policy is unsafe-url.
HTTP 1.1.
HTTP 2.
The origin-request specifies the request to the origin location (e.g.
The origin-response specifies the response from the origin location (e.g.
The viewer-request specifies the incoming request.
The viewer-response specifies the outgoing response.
Connect on HTTP only.
Connect on HTTPS only.
Connect with the same protocol as the viewer.
Experimental.
Experimental.
Experimental.
Experimental.
USA, Canada, Europe, & Israel.
PRICE_CLASS_100 + South Africa, Kenya, Middle East, Japan, Singapore, South Korea, Taiwan, Hong Kong, & Philippines.
All locations.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Experimental.
Both HTTP and HTTPS supported.
HTTPS only.
Will redirect HTTP requests to HTTPS.

# Structs

Options for adding a new behavior to a Distribution.
Configuration for custom domain names.
A CloudFront behavior wrapper.
Options for creating a new behavior.
Properties for creating a Cache Policy.
A cache policy configuration.
An object that determines whether any cookies in viewer requests (and if so, which cookies) are included in the cache key and in requests that CloudFront sends to the origin.
An object that determines whether any HTTP headers (and if so, which headers) are included in the cache key and in requests that CloudFront sends to the origin.
This object determines the values that CloudFront includes in the cache key.
An object that determines whether any URL query strings in viewer requests (and if so, which query strings) are included in the cache key and in requests that CloudFront sends to the origin.
Properties for defining a `CfnCachePolicy`.
Origin access identity configuration.
Properties for defining a `CfnCloudFrontOriginAccessIdentity`.
Contains the configuration for a continuous deployment policy.
Session stickiness provides the ability to define multiple requests from a single viewer as a single session.
Determines which HTTP requests are sent to the staging distribution.
This configuration determines the percentage of HTTP requests that are sent to the staging distribution.
The traffic configuration of your continuous deployment.
Properties for defining a `CfnContinuousDeploymentPolicy`.
A complex type that describes how CloudFront processes requests.
This field is deprecated.
A complex type that controls:.
A custom origin.
A complex type that describes the default cache behavior if you don't specify a `CacheBehavior` element or if request URLs don't match any of the values of `PathPattern` in `CacheBehavior` elements.
A distribution configuration.
This field is deprecated.
A CloudFront function that is associated with a cache behavior in a CloudFront distribution.
A complex type that controls the countries in which your content is distributed.
A complex type that contains a Lambda@Edge function association.
Example: // The code below shows an example of how to instantiate this type.
Example: // The code below shows an example of how to instantiate this type.
A complex type that controls whether access logs are written for the distribution.
A complex type that contains `HeaderName` and `HeaderValue` elements, if any, for this distribution.
A complex data type that includes information about the failover criteria for an origin group, including the status codes for which CloudFront will failover from the primary origin to the second origin.
An origin in an origin group.
A complex data type for the origins included in an origin group.
An origin group includes two origins (a primary origin and a second origin to failover to) and a failover criteria that you specify.
A complex data type for the origin groups specified for a distribution.
An origin.
CloudFront Origin Shield.
A complex type that identifies ways in which you want to restrict distribution of your content.
A complex type that contains information about the Amazon S3 origin.
A complex data type for the status codes that you specify that, when returned by a primary origin, trigger CloudFront to failover to a second origin.
A complex type that determines the distribution's SSL/TLS configuration for communicating with viewers.
Properties for defining a `CfnDistribution`.
Contains configuration information about a CloudFront function.
Contains metadata about a CloudFront function.
Properties for defining a `CfnFunction`.
A key group configuration.
Properties for defining a `CfnKeyGroup`.
A monitoring subscription.
A subscription configuration for additional CloudWatch metrics.
Properties for defining a `CfnMonitoringSubscription`.
Creates a new origin access control in CloudFront.
Properties for defining a `CfnOriginAccessControl`.
An object that determines whether any cookies in viewer requests (and if so, which cookies) are included in requests that CloudFront sends to the origin.
An object that determines whether any HTTP headers (and if so, which headers) are included in requests that CloudFront sends to the origin.
An origin request policy configuration.
An object that determines whether any URL query strings in viewer requests (and if so, which query strings) are included in requests that CloudFront sends to the origin.
Properties for defining a `CfnOriginRequestPolicy`.
Configuration information about a public key that you can use with [signed URLs and signed cookies](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html) , or with [field-level encryption](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/field-level-encryption.html) .
Properties for defining a `CfnPublicKey`.
Contains information about the Amazon Kinesis data stream where you are sending real-time log data in a real-time log configuration.
Contains information about the Amazon Kinesis data stream where you are sending real-time log data.
Properties for defining a `CfnRealtimeLogConfig`.
A list of HTTP header names that CloudFront includes as values for the `Access-Control-Allow-Headers` HTTP response header.
A list of HTTP methods that CloudFront includes as values for the `Access-Control-Allow-Methods` HTTP response header.
A list of origins (domain names) that CloudFront can use as the value for the `Access-Control-Allow-Origin` HTTP response header.
A list of HTTP headers that CloudFront includes as values for the `Access-Control-Expose-Headers` HTTP response header.
The policy directives and their values that CloudFront includes as values for the `Content-Security-Policy` HTTP response header.
Determines whether CloudFront includes the `X-Content-Type-Options` HTTP response header with its value set to `nosniff` .
A configuration for a set of HTTP response headers that are used for cross-origin resource sharing (CORS).
An HTTP response header name and its value.
A list of HTTP response header names and their values.
Determines whether CloudFront includes the `X-Frame-Options` HTTP response header and the header's value.
Determines whether CloudFront includes the `Referrer-Policy` HTTP response header and the header's value.
The name of an HTTP header that CloudFront removes from HTTP responses to requests that match the cache behavior that this response headers policy is attached to.
A list of HTTP header names that CloudFront removes from HTTP responses to requests that match the cache behavior that this response headers policy is attached to.
A response headers policy configuration.
A configuration for a set of security-related HTTP response headers.
A configuration for enabling the `Server-Timing` header in HTTP responses sent from CloudFront.
Determines whether CloudFront includes the `Strict-Transport-Security` HTTP response header and the header's value.
Determines whether CloudFront includes the `X-XSS-Protection` HTTP response header and the header's value.
Properties for defining a `CfnResponseHeadersPolicy`.
A complex type that controls whether access logs are written for the streaming distribution.
A complex type that contains information about the Amazon S3 bucket from which you want CloudFront to get your media files for distribution.
The RTMP distribution's configuration information.
A list of AWS accounts whose public keys CloudFront can use to verify the signatures of signed URLs and signed cookies.
Properties for defining a `CfnStreamingDistribution`.
Attributes used to import a Distribution.
Example: var sourceBucket bucket viewerCertificate := cloudfront.ViewerCertificate_FromIamCertificate(jsii.String("MYIAMROLEIDENTIFIER"), &ViewerCertificateOptions{ Aliases: []*string{ jsii.String("MYALIAS"), }, }) cloudfront.NewCloudFrontWebDistribution(this, jsii.String("MyCfWebDistribution"), &CloudFrontWebDistributionProps{ OriginConfigs: []sourceConfiguration{ &sourceConfiguration{ S3OriginSource: &S3OriginConfig{ S3BucketSource: sourceBucket, }, Behaviors: []behavior{ &behavior{ IsDefaultBehavior: jsii.Boolean(true), }, }, }, }, ViewerCertificate: viewerCertificate, }) Experimental.
A custom origin configuration.
Attributes used to import a Distribution.
Properties for a Distribution.
Represents a Lambda function version and event type when using Lambda@Edge.
Options for configuring custom error responses.
Options when reading the function's code from an external file.
Represents a CloudFront function and event type when using CF Functions.
Attributes of an existing CloudFront Function to import it.
Properties for creating a CloudFront Function.
Properties for creating a Public Key.
Example: // The code below shows an example of how to instantiate this type.
Logging configuration for incoming requests.
Properties of CloudFront OriginAccessIdentity.
The struct returned from {@link IOrigin.bind}.
Options passed to Origin.bind().
The failover configuration used for Origin Groups, returned in {@link OriginBindConfig.failoverConfig}.
Options to define an Origin.
Properties to define an Origin.
Properties for creating a Origin Request Policy.
Properties for creating a Public Key.
An HTTP response header name and its value.
Configuration for a set of HTTP response headers that are sent for requests that match a cache behavior that’s associated with this response headers policy.
The policy directives and their values that CloudFront includes as values for the Content-Security-Policy HTTP response header.
Determines whether CloudFront includes the X-Content-Type-Options HTTP response header with its value set to nosniff.
Configuration for a set of HTTP response headers that are used for cross-origin resource sharing (CORS).
Determines whether CloudFront includes the X-Frame-Options HTTP response header and the header’s value.
Properties for creating a Response Headers Policy.
Determines whether CloudFront includes the Referrer-Policy HTTP response header and the header’s value.
Determines whether CloudFront includes the Strict-Transport-Security HTTP response header and the header’s value.
Determines whether CloudFront includes the X-XSS-Protection HTTP response header and the header’s value.
Configuration for a set of security-related HTTP response headers.
S3 origin configuration for CloudFront.
A source configuration is a wrapper for CloudFront origins and behaviors.
Example: s3BucketSource := s3.NewBucket(this, jsii.String("Bucket")) distribution := cloudfront.NewCloudFrontWebDistribution(this, jsii.String("AnAmazingWebsiteProbably"), &CloudFrontWebDistributionProps{ OriginConfigs: []sourceConfiguration{ &sourceConfiguration{ S3OriginSource: &S3OriginConfig{ S3BucketSource: *S3BucketSource, }, Behaviors: []behavior{ &behavior{ IsDefaultBehavior: jsii.Boolean(true), }, }, }, }, ViewerCertificate: cloudfront.ViewerCertificate_FromIamCertificate(jsii.String("certificateId"), &ViewerCertificateOptions{ Aliases: []*string{ jsii.String("example.com"), }, SecurityPolicy: cloudfront.SecurityPolicyProtocol_SSL_V3, // default SslMethod: cloudfront.SSLMethod_SNI, }), }) Experimental.

# Interfaces

The HTTP methods that the Behavior will accept requests on.
Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin.
The HTTP methods that the Behavior will cache requests on.
Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.
A Cache Policy configuration.
Determines whether any URL query strings in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin.
A CloudFormation `AWS::CloudFront::CachePolicy`.
A CloudFormation `AWS::CloudFront::CloudFrontOriginAccessIdentity`.
A CloudFormation `AWS::CloudFront::ContinuousDeploymentPolicy`.
A CloudFormation `AWS::CloudFront::Distribution`.
A CloudFormation `AWS::CloudFront::Function`.
A CloudFormation `AWS::CloudFront::KeyGroup`.
A CloudFormation `AWS::CloudFront::MonitoringSubscription`.
A CloudFormation `AWS::CloudFront::OriginAccessControl`.
A CloudFormation `AWS::CloudFront::OriginRequestPolicy`.
A CloudFormation `AWS::CloudFront::PublicKey`.
A CloudFormation `AWS::CloudFront::RealtimeLogConfig`.
A CloudFormation `AWS::CloudFront::ResponseHeadersPolicy`.
A CloudFormation `AWS::CloudFront::StreamingDistribution`.
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.
A CloudFront distribution with associated origin(s) and caching behavior(s).
A CloudFront Function.
Represents the function's source code.
Controls the countries in which content is distributed.
Represents a Cache Policy.
Interface for CloudFront distributions.
Represents a CloudFront Function.
Represents a Key Group.
Represents the concept of a CloudFront Origin.
Interface for CloudFront OriginAccessIdentity.
Represents a Origin Request Policy.
Represents a Public Key.
Represents a response headers policy.
A Key Group configuration.
An origin access identity is a special CloudFront user that you can associate with Amazon S3 origins, so that you can secure all or just some of your Amazon S3 content.
Represents a distribution origin, that describes the Amazon S3 bucket, HTTP server (for example, a web server), Amazon MediaStore, or other server from which CloudFront gets your files.
Determines whether any cookies in viewer requests (and if so, which cookies) are included in requests that CloudFront sends to the origin.
Determines whether any HTTP headers (and if so, which headers) are included in requests that CloudFront sends to the origin.
A Origin Request Policy configuration.
Determines whether any URL query strings in viewer requests (and if so, which query strings) are included in requests that CloudFront sends to the origin.
A Public Key Configuration.
A Response Headers Policy configuration.
Viewer certificate configuration class.

# Type aliases

Enums for the methods CloudFront can cache.
An enum for the supported methods to a CloudFront distribution.
HTTP status code to failover to second origin.
The type of events that a CloudFront function can be invoked in response to.
Enum representing possible values of the X-Frame-Options HTTP response header.
Enum representing possible values of the Referrer-Policy HTTP response header.
Maximum HTTP version to support.
The type of events that a Lambda@Edge function can be invoked in response to.
Defines what protocols CloudFront will use to connect to an origin.
Experimental.
The price class determines how many edge locations CloudFront will use for your distribution.
The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections.
The SSL method CloudFront will use for your distribution.
How HTTPs should be handled with your distribution.