@ts-cloud/core 0.16.15 → 0.16.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +136 -136
- package/dist/modules/cdn-failover.d.ts +97 -0
- package/dist/modules/cdn.d.ts +36 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/types.d.ts +19 -0
- package/package.json +2 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CloudFront origin failover (origin groups).
|
|
3
|
+
*
|
|
4
|
+
* An origin group pairs a primary origin with a secondary one. On a cache miss
|
|
5
|
+
* CloudFront asks the primary; when the primary returns one of the configured
|
|
6
|
+
* status codes, or cannot be reached (503) or times out (504), CloudFront
|
|
7
|
+
* retries the same request against the secondary.
|
|
8
|
+
*
|
|
9
|
+
* These are pure builders: they produce the `OriginGroups` block and check the
|
|
10
|
+
* constraints CloudFront enforces, so every distribution builder in ts-cloud
|
|
11
|
+
* emits the same shape. The block is identical in a CloudFormation
|
|
12
|
+
* `AWS::CloudFront::Distribution` and in the CloudFront API's
|
|
13
|
+
* `DistributionConfig`:
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* OriginGroups: {
|
|
17
|
+
* Quantity: 1,
|
|
18
|
+
* Items: [{
|
|
19
|
+
* Id,
|
|
20
|
+
* FailoverCriteria: { StatusCodes: { Quantity, Items: [500, 502, ...] } },
|
|
21
|
+
* Members: { Quantity: 2, Items: [{ OriginId: primary }, { OriginId: secondary }] },
|
|
22
|
+
* }],
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html
|
|
27
|
+
* @experimental Built against the AWS documentation; not yet exercised against a live distribution.
|
|
28
|
+
*/
|
|
29
|
+
/** Every status code CloudFront accepts as a failover criterion. */
|
|
30
|
+
export declare const CLOUDFRONT_FAILOVER_STATUS_CODES: readonly number[];
|
|
31
|
+
/** Server-side failures: what ts-cloud fails over on when no codes are given. */
|
|
32
|
+
export declare const DEFAULT_FAILOVER_STATUS_CODES: readonly number[];
|
|
33
|
+
/**
|
|
34
|
+
* The only methods a cache behavior may allow when it targets an origin group.
|
|
35
|
+
* CloudFront never fails over a write, so a behavior that accepts writes cannot
|
|
36
|
+
* point at a group.
|
|
37
|
+
*/
|
|
38
|
+
export declare const ORIGIN_GROUP_ALLOWED_METHODS: readonly string[];
|
|
39
|
+
/** Suffix appended to the primary origin id to name its origin group. */
|
|
40
|
+
export declare const ORIGIN_GROUP_ID_SUFFIX = "-failover-group";
|
|
41
|
+
export interface OriginGroupOptions {
|
|
42
|
+
/** Id of the origin CloudFront asks first. */
|
|
43
|
+
primaryOriginId: string;
|
|
44
|
+
/** Id of the origin CloudFront retries against when the primary fails. */
|
|
45
|
+
secondaryOriginId: string;
|
|
46
|
+
/** Status codes from the primary that trigger failover. @default [500, 502, 503, 504] */
|
|
47
|
+
statusCodes?: readonly number[];
|
|
48
|
+
/** Origin group id, which cache behaviors use as their `TargetOriginId`. @default `<primaryOriginId>-failover-group` */
|
|
49
|
+
groupId?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface CloudFrontOriginGroup {
|
|
52
|
+
Id: string;
|
|
53
|
+
FailoverCriteria: {
|
|
54
|
+
StatusCodes: {
|
|
55
|
+
Quantity: number;
|
|
56
|
+
Items: number[];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
Members: {
|
|
60
|
+
Quantity: number;
|
|
61
|
+
Items: Array<{
|
|
62
|
+
OriginId: string;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface CloudFrontOriginGroups {
|
|
67
|
+
Quantity: number;
|
|
68
|
+
Items: CloudFrontOriginGroup[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validate failover status codes and return them deduplicated and sorted.
|
|
72
|
+
* With no codes, returns {@link DEFAULT_FAILOVER_STATUS_CODES}.
|
|
73
|
+
*
|
|
74
|
+
* @throws when the list is empty or holds a code CloudFront does not accept.
|
|
75
|
+
*/
|
|
76
|
+
export declare function resolveFailoverStatusCodes(statusCodes?: readonly number[]): number[];
|
|
77
|
+
/** Build one origin group (primary first, secondary second). */
|
|
78
|
+
export declare function buildOriginGroup(options: OriginGroupOptions): CloudFrontOriginGroup;
|
|
79
|
+
/** Build a distribution's `OriginGroups` block holding a single failover group. */
|
|
80
|
+
export declare function buildOriginGroups(options: OriginGroupOptions): CloudFrontOriginGroups;
|
|
81
|
+
/**
|
|
82
|
+
* Throw unless a cache behavior that targets an origin group allows only
|
|
83
|
+
* GET, HEAD and OPTIONS.
|
|
84
|
+
*
|
|
85
|
+
* Accepts either the CloudFormation form (`['GET', 'HEAD']`) or the CloudFront
|
|
86
|
+
* API form (`{ Quantity, Items: [...] }`) of `AllowedMethods`.
|
|
87
|
+
*
|
|
88
|
+
* @param where Names the behavior in the error, e.g. `the default cache behavior`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function assertOriginGroupMethods(allowedMethods: readonly string[] | {
|
|
91
|
+
Items?: readonly string[];
|
|
92
|
+
} | undefined, where?: string): void;
|
|
93
|
+
/**
|
|
94
|
+
* Whether a domain is an S3 REST endpoint (and so takes an `S3OriginConfig`).
|
|
95
|
+
* S3 *website* endpoints only speak HTTP and are custom origins.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isS3RestEndpoint(domainName: string): boolean;
|
package/dist/modules/cdn.d.ts
CHANGED
|
@@ -11,6 +11,30 @@ export interface DistributionOptions {
|
|
|
11
11
|
edgeFunctions?: EdgeFunctionConfig[];
|
|
12
12
|
http3?: boolean;
|
|
13
13
|
comment?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Secondary origin CloudFront fails over to when the primary errors.
|
|
16
|
+
* Adds an origin group and points the default cache behavior at it.
|
|
17
|
+
* @experimental See {@link CDN.addOriginFailover}.
|
|
18
|
+
*/
|
|
19
|
+
failoverOrigin?: FailoverOriginConfig;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Secondary origin for CloudFront origin failover.
|
|
23
|
+
* @experimental Built against the AWS documentation; not yet exercised against a live distribution.
|
|
24
|
+
*/
|
|
25
|
+
export interface FailoverOriginConfig {
|
|
26
|
+
/** Domain of the secondary origin, e.g. a replica bucket in another region. */
|
|
27
|
+
domainName: string;
|
|
28
|
+
/** Origin kind. @default 's3' for an S3 REST endpoint, otherwise 'custom' */
|
|
29
|
+
type?: 's3' | 'alb' | 'custom';
|
|
30
|
+
/** Origin id for the secondary. @default 'FailoverOrigin' */
|
|
31
|
+
id?: string;
|
|
32
|
+
originPath?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Primary-origin status codes that trigger failover. Allowed: 400, 403, 404,
|
|
35
|
+
* 416, 429, 500, 502, 503, 504. @default [500, 502, 503, 504]
|
|
36
|
+
*/
|
|
37
|
+
statusCodes?: number[];
|
|
14
38
|
}
|
|
15
39
|
export interface OriginConfig {
|
|
16
40
|
type?: 's3' | 'alb' | 'custom';
|
|
@@ -48,6 +72,18 @@ export declare class CDN {
|
|
|
48
72
|
originAccessControl?: CloudFrontOriginAccessControl;
|
|
49
73
|
logicalId: string;
|
|
50
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Add CloudFront origin failover to a distribution: append the secondary
|
|
77
|
+
* origin, group it with the default cache behavior's current origin, and
|
|
78
|
+
* point that behavior at the group.
|
|
79
|
+
*
|
|
80
|
+
* CloudFront only fails over GET, HEAD and OPTIONS, and rejects an origin
|
|
81
|
+
* group behind a cache behavior that allows writes, so this throws if the
|
|
82
|
+
* default cache behavior allows any other method.
|
|
83
|
+
*
|
|
84
|
+
* @experimental Built against the AWS documentation; not yet exercised against a live distribution.
|
|
85
|
+
*/
|
|
86
|
+
static addOriginFailover(distribution: CloudFrontDistribution, failover: FailoverOriginConfig): CloudFrontDistribution;
|
|
51
87
|
/**
|
|
52
88
|
* Set custom domain on a distribution
|
|
53
89
|
*/
|
package/dist/modules/index.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -4129,6 +4129,25 @@ export interface CdnItemConfig {
|
|
|
4129
4129
|
originShield?: boolean;
|
|
4130
4130
|
/** AWS region used by Origin Shield. Defaults to the deployment region. */
|
|
4131
4131
|
originShieldRegion?: string;
|
|
4132
|
+
/**
|
|
4133
|
+
* Secondary origin CloudFront fails over to when {@link origin} errors,
|
|
4134
|
+
* e.g. a replica bucket in another region. Adds a CloudFront origin group
|
|
4135
|
+
* (primary + this origin) and serves the default cache behavior from it.
|
|
4136
|
+
* CloudFront only fails over GET, HEAD and OPTIONS requests. An S3 REST
|
|
4137
|
+
* endpoint becomes an S3 origin; any other host an HTTPS-only custom origin.
|
|
4138
|
+
*
|
|
4139
|
+
* @experimental Generated from the AWS documentation; not yet verified
|
|
4140
|
+
* against a live distribution.
|
|
4141
|
+
*/
|
|
4142
|
+
failoverOrigin?: string;
|
|
4143
|
+
/**
|
|
4144
|
+
* Status codes from {@link origin} that trigger failover to
|
|
4145
|
+
* {@link failoverOrigin}. CloudFront accepts 400, 403, 404, 416, 429, 500,
|
|
4146
|
+
* 502, 503 and 504; anything else throws at template generation.
|
|
4147
|
+
* @default [500, 502, 503, 504]
|
|
4148
|
+
* @experimental
|
|
4149
|
+
*/
|
|
4150
|
+
failoverStatusCodes?: number[];
|
|
4132
4151
|
/**
|
|
4133
4152
|
* Cache policy configuration
|
|
4134
4153
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-cloud/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.16",
|
|
5
5
|
"description": "Core CloudFormation generation library for ts-cloud",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typecheck": "tsc --noEmit"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ts-cloud/aws-types": "0.16.
|
|
34
|
+
"@ts-cloud/aws-types": "0.16.16"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^7.0.2"
|