UNPKG

19.7 kBTypeScriptView Raw
1import * as acm from '@aws-cdk/aws-certificatemanager';
2import * as lambda from '@aws-cdk/aws-lambda';
3import * as s3 from '@aws-cdk/aws-s3';
4import { IResource, Resource, Duration } from '@aws-cdk/core';
5import { Construct } from 'constructs';
6import { ICachePolicy } from './cache-policy';
7import { FunctionAssociation } from './function';
8import { GeoRestriction } from './geo-restriction';
9import { IKeyGroup } from './key-group';
10import { IOrigin } from './origin';
11import { IOriginRequestPolicy } from './origin-request-policy';
12import { IResponseHeadersPolicy } from './response-headers-policy';
13/**
14 * Interface for CloudFront distributions
15 */
16export interface IDistribution extends IResource {
17 /**
18 * The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
19 *
20 * @attribute
21 * @deprecated - Use `distributionDomainName` instead.
22 */
23 readonly domainName: string;
24 /**
25 * The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
26 *
27 * @attribute
28 */
29 readonly distributionDomainName: string;
30 /**
31 * The distribution ID for this distribution.
32 *
33 * @attribute
34 */
35 readonly distributionId: string;
36}
37/**
38 * Attributes used to import a Distribution.
39 */
40export interface DistributionAttributes {
41 /**
42 * The generated domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
43 *
44 * @attribute
45 */
46 readonly domainName: string;
47 /**
48 * The distribution ID for this distribution.
49 *
50 * @attribute
51 */
52 readonly distributionId: string;
53}
54/**
55 * Properties for a Distribution
56 */
57export interface DistributionProps {
58 /**
59 * The default behavior for the distribution.
60 */
61 readonly defaultBehavior: BehaviorOptions;
62 /**
63 * Additional behaviors for the distribution, mapped by the pathPattern that specifies which requests to apply the behavior to.
64 *
65 * @default - no additional behaviors are added.
66 */
67 readonly additionalBehaviors?: Record<string, BehaviorOptions>;
68 /**
69 * A certificate to associate with the distribution. The certificate must be located in N. Virginia (us-east-1).
70 *
71 * @default - the CloudFront wildcard certificate (*.cloudfront.net) will be used.
72 */
73 readonly certificate?: acm.ICertificate;
74 /**
75 * Any comments you want to include about the distribution.
76 *
77 * @default - no comment
78 */
79 readonly comment?: string;
80 /**
81 * The object that you want CloudFront to request from your origin (for example, index.html)
82 * when a viewer requests the root URL for your distribution. If no default object is set, the
83 * request goes to the origin's root (e.g., example.com/).
84 *
85 * @default - no default root object
86 */
87 readonly defaultRootObject?: string;
88 /**
89 * Alternative domain names for this distribution.
90 *
91 * If you want to use your own domain name, such as www.example.com, instead of the cloudfront.net domain name,
92 * you can add an alternate domain name to your distribution. If you attach a certificate to the distribution,
93 * you must add (at least one of) the domain names of the certificate to this list.
94 *
95 * @default - The distribution will only support the default generated name (e.g., d111111abcdef8.cloudfront.net)
96 */
97 readonly domainNames?: string[];
98 /**
99 * Enable or disable the distribution.
100 *
101 * @default true
102 */
103 readonly enabled?: boolean;
104 /**
105 * Whether CloudFront will respond to IPv6 DNS requests with an IPv6 address.
106 *
107 * If you specify false, CloudFront responds to IPv6 DNS requests with the DNS response code NOERROR and with no IP addresses.
108 * This allows viewers to submit a second request, for an IPv4 address for your distribution.
109 *
110 * @default true
111 */
112 readonly enableIpv6?: boolean;
113 /**
114 * Enable access logging for the distribution.
115 *
116 * @default - false, unless `logBucket` is specified.
117 */
118 readonly enableLogging?: boolean;
119 /**
120 * Controls the countries in which your content is distributed.
121 *
122 * @default - No geographic restrictions
123 */
124 readonly geoRestriction?: GeoRestriction;
125 /**
126 * Specify the maximum HTTP version that you want viewers to use to communicate with CloudFront.
127 *
128 * For viewers and CloudFront to use HTTP/2, viewers must support TLS 1.2 or later, and must support server name identification (SNI).
129 *
130 * @default HttpVersion.HTTP2
131 */
132 readonly httpVersion?: HttpVersion;
133 /**
134 * The Amazon S3 bucket to store the access logs in.
135 *
136 * @default - A bucket is created if `enableLogging` is true
137 */
138 readonly logBucket?: s3.IBucket;
139 /**
140 * Specifies whether you want CloudFront to include cookies in access logs
141 *
142 * @default false
143 */
144 readonly logIncludesCookies?: boolean;
145 /**
146 * An optional string that you want CloudFront to prefix to the access log filenames for this distribution.
147 *
148 * @default - no prefix
149 */
150 readonly logFilePrefix?: string;
151 /**
152 * The price class that corresponds with the maximum price that you want to pay for CloudFront service.
153 * If you specify PriceClass_All, CloudFront responds to requests for your objects from all CloudFront edge locations.
154 * If you specify a price class other than PriceClass_All, CloudFront serves your objects from the CloudFront edge location
155 * that has the lowest latency among the edge locations in your price class.
156 *
157 * @default PriceClass.PRICE_CLASS_ALL
158 */
159 readonly priceClass?: PriceClass;
160 /**
161 * Unique identifier that specifies the AWS WAF web ACL to associate with this CloudFront distribution.
162 *
163 * To specify a web ACL created using the latest version of AWS WAF, use the ACL ARN, for example
164 * `arn:aws:wafv2:us-east-1:123456789012:global/webacl/ExampleWebACL/473e64fd-f30b-4765-81a0-62ad96dd167a`.
165 * To specify a web ACL created using AWS WAF Classic, use the ACL ID, for example `473e64fd-f30b-4765-81a0-62ad96dd167a`.
166 *
167 * @see https://docs.aws.amazon.com/waf/latest/developerguide/what-is-aws-waf.html
168 * @see https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateDistribution.html#API_CreateDistribution_RequestParameters.
169 *
170 * @default - No AWS Web Application Firewall web access control list (web ACL).
171 */
172 readonly webAclId?: string;
173 /**
174 * How CloudFront should handle requests that are not successful (e.g., PageNotFound).
175 *
176 * @default - No custom error responses.
177 */
178 readonly errorResponses?: ErrorResponse[];
179 /**
180 * The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections.
181 *
182 * CloudFront serves your objects only to browsers or devices that support at
183 * least the SSL version that you specify.
184 *
185 * @default - SecurityPolicyProtocol.TLS_V1_2_2021 if the '@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021' feature flag is set; otherwise, SecurityPolicyProtocol.TLS_V1_2_2019.
186 */
187 readonly minimumProtocolVersion?: SecurityPolicyProtocol;
188 /**
189 * The SSL method CloudFront will use for your distribution.
190 *
191 * Server Name Indication (SNI) - is an extension to the TLS computer networking protocol by which a client indicates
192 * which hostname it is attempting to connect to at the start of the handshaking process. This allows a server to present
193 * multiple certificates on the same IP address and TCP port number and hence allows multiple secure (HTTPS) websites
194 * (or any other service over TLS) to be served by the same IP address without requiring all those sites to use the same certificate.
195 *
196 * CloudFront can use SNI to host multiple distributions on the same IP - which a large majority of clients will support.
197 *
198 * If your clients cannot support SNI however - CloudFront can use dedicated IPs for your distribution - but there is a prorated monthly charge for
199 * using this feature. By default, we use SNI - but you can optionally enable dedicated IPs (VIP).
200 *
201 * See the CloudFront SSL for more details about pricing : https://aws.amazon.com/cloudfront/custom-ssl-domains/
202 *
203 * @default SSLMethod.SNI
204 */
205 readonly sslSupportMethod?: SSLMethod;
206}
207/**
208 * A CloudFront distribution with associated origin(s) and caching behavior(s).
209 */
210export declare class Distribution extends Resource implements IDistribution {
211 /**
212 * Creates a Distribution construct that represents an external (imported) distribution.
213 */
214 static fromDistributionAttributes(scope: Construct, id: string, attrs: DistributionAttributes): IDistribution;
215 readonly domainName: string;
216 readonly distributionDomainName: string;
217 readonly distributionId: string;
218 private readonly defaultBehavior;
219 private readonly additionalBehaviors;
220 private readonly boundOrigins;
221 private readonly originGroups;
222 private readonly errorResponses;
223 private readonly certificate?;
224 constructor(scope: Construct, id: string, props: DistributionProps);
225 /**
226 * Adds a new behavior to this distribution for the given pathPattern.
227 *
228 * @param pathPattern the path pattern (e.g., 'images/*') that specifies which requests to apply the behavior to.
229 * @param origin the origin to use for this behavior
230 * @param behaviorOptions the options for the behavior at this path.
231 */
232 addBehavior(pathPattern: string, origin: IOrigin, behaviorOptions?: AddBehaviorOptions): void;
233 private addOrigin;
234 private addOriginGroup;
235 private renderOrigins;
236 private renderOriginGroups;
237 private renderCacheBehaviors;
238 private renderErrorResponses;
239 private renderLogging;
240 private renderRestrictions;
241 private renderViewerCertificate;
242}
243/** Maximum HTTP version to support */
244export declare enum HttpVersion {
245 /** HTTP 1.1 */
246 HTTP1_1 = "http1.1",
247 /** HTTP 2 */
248 HTTP2 = "http2"
249}
250/**
251 * The price class determines how many edge locations CloudFront will use for your distribution.
252 * See https://aws.amazon.com/cloudfront/pricing/ for full list of supported regions.
253 */
254export declare enum PriceClass {
255 /** USA, Canada, Europe, & Israel */
256 PRICE_CLASS_100 = "PriceClass_100",
257 /** PRICE_CLASS_100 + South Africa, Kenya, Middle East, Japan, Singapore, South Korea, Taiwan, Hong Kong, & Philippines */
258 PRICE_CLASS_200 = "PriceClass_200",
259 /** All locations */
260 PRICE_CLASS_ALL = "PriceClass_All"
261}
262/**
263 * How HTTPs should be handled with your distribution.
264 */
265export declare enum ViewerProtocolPolicy {
266 /** HTTPS only */
267 HTTPS_ONLY = "https-only",
268 /** Will redirect HTTP requests to HTTPS */
269 REDIRECT_TO_HTTPS = "redirect-to-https",
270 /** Both HTTP and HTTPS supported */
271 ALLOW_ALL = "allow-all"
272}
273/**
274 * Defines what protocols CloudFront will use to connect to an origin.
275 */
276export declare enum OriginProtocolPolicy {
277 /** Connect on HTTP only */
278 HTTP_ONLY = "http-only",
279 /** Connect with the same protocol as the viewer */
280 MATCH_VIEWER = "match-viewer",
281 /** Connect on HTTPS only */
282 HTTPS_ONLY = "https-only"
283}
284/**
285 * The SSL method CloudFront will use for your distribution.
286 *
287 * Server Name Indication (SNI) - is an extension to the TLS computer networking protocol by which a client indicates
288 * which hostname it is attempting to connect to at the start of the handshaking process. This allows a server to present
289 * multiple certificates on the same IP address and TCP port number and hence allows multiple secure (HTTPS) websites
290 * (or any other service over TLS) to be served by the same IP address without requiring all those sites to use the same certificate.
291 *
292 * CloudFront can use SNI to host multiple distributions on the same IP - which a large majority of clients will support.
293 *
294 * If your clients cannot support SNI however - CloudFront can use dedicated IPs for your distribution - but there is a prorated monthly charge for
295 * using this feature. By default, we use SNI - but you can optionally enable dedicated IPs (VIP).
296 *
297 * See the CloudFront SSL for more details about pricing : https://aws.amazon.com/cloudfront/custom-ssl-domains/
298 *
299 */
300export declare enum SSLMethod {
301 SNI = "sni-only",
302 VIP = "vip"
303}
304/**
305 * The minimum version of the SSL protocol that you want CloudFront to use for HTTPS connections.
306 * CloudFront serves your objects only to browsers or devices that support at least the SSL version that you specify.
307 */
308export declare enum SecurityPolicyProtocol {
309 SSL_V3 = "SSLv3",
310 TLS_V1 = "TLSv1",
311 TLS_V1_2016 = "TLSv1_2016",
312 TLS_V1_1_2016 = "TLSv1.1_2016",
313 TLS_V1_2_2018 = "TLSv1.2_2018",
314 TLS_V1_2_2019 = "TLSv1.2_2019",
315 TLS_V1_2_2021 = "TLSv1.2_2021"
316}
317/**
318 * The HTTP methods that the Behavior will accept requests on.
319 */
320export declare class AllowedMethods {
321 /** HEAD and GET */
322 static readonly ALLOW_GET_HEAD: AllowedMethods;
323 /** HEAD, GET, and OPTIONS */
324 static readonly ALLOW_GET_HEAD_OPTIONS: AllowedMethods;
325 /** All supported HTTP methods */
326 static readonly ALLOW_ALL: AllowedMethods;
327 /** HTTP methods supported */
328 readonly methods: string[];
329 private constructor();
330}
331/**
332 * The HTTP methods that the Behavior will cache requests on.
333 */
334export declare class CachedMethods {
335 /** HEAD and GET */
336 static readonly CACHE_GET_HEAD: CachedMethods;
337 /** HEAD, GET, and OPTIONS */
338 static readonly CACHE_GET_HEAD_OPTIONS: CachedMethods;
339 /** HTTP methods supported */
340 readonly methods: string[];
341 private constructor();
342}
343/**
344 * Options for configuring custom error responses.
345 */
346export interface ErrorResponse {
347 /**
348 * The minimum amount of time, in seconds, that you want CloudFront to cache the HTTP status code specified in ErrorCode.
349 *
350 * @default - the default caching TTL behavior applies
351 */
352 readonly ttl?: Duration;
353 /**
354 * The HTTP status code for which you want to specify a custom error page and/or a caching duration.
355 */
356 readonly httpStatus: number;
357 /**
358 * The HTTP status code that you want CloudFront to return to the viewer along with the custom error page.
359 *
360 * If you specify a value for `responseHttpStatus`, you must also specify a value for `responsePagePath`.
361 *
362 * @default - the error code will be returned as the response code.
363 */
364 readonly responseHttpStatus?: number;
365 /**
366 * The path to the custom error page that you want CloudFront to return to a viewer when your origin returns the
367 * `httpStatus`, for example, /4xx-errors/403-forbidden.html
368 *
369 * @default - the default CloudFront response is shown.
370 */
371 readonly responsePagePath?: string;
372}
373/**
374 * The type of events that a Lambda@Edge function can be invoked in response to.
375 */
376export declare enum LambdaEdgeEventType {
377 /**
378 * The origin-request specifies the request to the
379 * origin location (e.g. S3)
380 */
381 ORIGIN_REQUEST = "origin-request",
382 /**
383 * The origin-response specifies the response from the
384 * origin location (e.g. S3)
385 */
386 ORIGIN_RESPONSE = "origin-response",
387 /**
388 * The viewer-request specifies the incoming request
389 */
390 VIEWER_REQUEST = "viewer-request",
391 /**
392 * The viewer-response specifies the outgoing response
393 */
394 VIEWER_RESPONSE = "viewer-response"
395}
396/**
397 * Represents a Lambda function version and event type when using Lambda@Edge.
398 * The type of the {@link AddBehaviorOptions.edgeLambdas} property.
399 */
400export interface EdgeLambda {
401 /**
402 * The version of the Lambda function that will be invoked.
403 *
404 * **Note**: it's not possible to use the '$LATEST' function version for Lambda@Edge!
405 */
406 readonly functionVersion: lambda.IVersion;
407 /** The type of event in response to which should the function be invoked. */
408 readonly eventType: LambdaEdgeEventType;
409 /**
410 * Allows a Lambda function to have read access to the body content.
411 * Only valid for "request" event types (`ORIGIN_REQUEST` or `VIEWER_REQUEST`).
412 * See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html
413 *
414 * @default false
415 */
416 readonly includeBody?: boolean;
417}
418/**
419 * Options for adding a new behavior to a Distribution.
420 */
421export interface AddBehaviorOptions {
422 /**
423 * HTTP methods to allow for this behavior.
424 *
425 * @default AllowedMethods.ALLOW_GET_HEAD
426 */
427 readonly allowedMethods?: AllowedMethods;
428 /**
429 * HTTP methods to cache for this behavior.
430 *
431 * @default CachedMethods.CACHE_GET_HEAD
432 */
433 readonly cachedMethods?: CachedMethods;
434 /**
435 * The cache policy for this behavior. The cache policy determines what values are included in the cache key,
436 * and the time-to-live (TTL) values for the cache.
437 *
438 * @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html.
439 * @default CachePolicy.CACHING_OPTIMIZED
440 */
441 readonly cachePolicy?: ICachePolicy;
442 /**
443 * Whether you want CloudFront to automatically compress certain files for this cache behavior.
444 * See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compressed-content-cloudfront-file-types
445 * for file types CloudFront will compress.
446 *
447 * @default true
448 */
449 readonly compress?: boolean;
450 /**
451 * The origin request policy for this behavior. The origin request policy determines which values (e.g., headers, cookies)
452 * are included in requests that CloudFront sends to the origin.
453 *
454 * @default - none
455 */
456 readonly originRequestPolicy?: IOriginRequestPolicy;
457 /**
458 * The response headers policy for this behavior. The response headers policy determines which headers are included in responses
459 *
460 * @default - none
461 */
462 readonly responseHeadersPolicy?: IResponseHeadersPolicy;
463 /**
464 * Set this to true to indicate you want to distribute media files in the Microsoft Smooth Streaming format using this behavior.
465 *
466 * @default false
467 */
468 readonly smoothStreaming?: boolean;
469 /**
470 * The protocol that viewers can use to access the files controlled by this behavior.
471 *
472 * @default ViewerProtocolPolicy.ALLOW_ALL
473 */
474 readonly viewerProtocolPolicy?: ViewerProtocolPolicy;
475 /**
476 * The CloudFront functions to invoke before serving the contents.
477 *
478 * @default - no functions will be invoked
479 */
480 readonly functionAssociations?: FunctionAssociation[];
481 /**
482 * The Lambda@Edge functions to invoke before serving the contents.
483 *
484 * @default - no Lambda functions will be invoked
485 * @see https://aws.amazon.com/lambda/edge
486 */
487 readonly edgeLambdas?: EdgeLambda[];
488 /**
489 * A list of Key Groups that CloudFront can use to validate signed URLs or signed cookies.
490 *
491 * @default - no KeyGroups are associated with cache behavior
492 * @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html
493 */
494 readonly trustedKeyGroups?: IKeyGroup[];
495}
496/**
497 * Options for creating a new behavior.
498 */
499export interface BehaviorOptions extends AddBehaviorOptions {
500 /**
501 * The origin that you want CloudFront to route requests to when they match this behavior.
502 */
503 readonly origin: IOrigin;
504}
505
\No newline at end of file