@composurecdk/cloudfront 0.4.4 → 0.4.5
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/README.md +53 -0
- package/dist/alarm-config.d.ts +6 -2
- package/dist/alarm-config.d.ts.map +1 -1
- package/dist/cloudfront-alarm-builder.d.ts +133 -0
- package/dist/cloudfront-alarm-builder.d.ts.map +1 -0
- package/dist/cloudfront-alarm-builder.js +131 -0
- package/dist/cloudfront-alarm-builder.js.map +1 -0
- package/dist/distribution-builder.d.ts +57 -27
- package/dist/distribution-builder.d.ts.map +1 -1
- package/dist/distribution-builder.js +4 -34
- package/dist/distribution-builder.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/resolve-behaviors.d.ts +9 -8
- package/dist/resolve-behaviors.d.ts.map +1 -1
- package/dist/resolve-behaviors.js +7 -5
- package/dist/resolve-behaviors.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -177,6 +177,59 @@ for (const alarm of Object.values(result.alarms)) {
|
|
|
177
177
|
}
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
+
## Cross-region alarm builder
|
|
181
|
+
|
|
182
|
+
CloudFront emits all metrics to `us-east-1` only. CloudWatch alarms are regional, so alarms created in any other region never fire — they exist but receive no data. When the distribution lives in a stack outside `us-east-1`, use `createCloudFrontAlarmBuilder` to put the alarms in a separate `us-east-1` stack.
|
|
183
|
+
|
|
184
|
+
The standalone builder reads the distribution's result (including the inline-function entries) and produces the same alarm surface — distribution-level recommended alarms, per-function recommended alarms, and any custom `addAlarm` alarms.
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
import { compose, ref } from "@composurecdk/core";
|
|
188
|
+
import {
|
|
189
|
+
createDistributionBuilder,
|
|
190
|
+
createCloudFrontAlarmBuilder,
|
|
191
|
+
type DistributionBuilderResult,
|
|
192
|
+
} from "@composurecdk/cloudfront";
|
|
193
|
+
|
|
194
|
+
compose(
|
|
195
|
+
{
|
|
196
|
+
cdn: createDistributionBuilder()
|
|
197
|
+
.origin(siteOrigin)
|
|
198
|
+
.defaultBehavior({
|
|
199
|
+
functions: [{ eventType: FunctionEventType.VIEWER_REQUEST, code }],
|
|
200
|
+
})
|
|
201
|
+
.recommendedAlarms(false), // suppress all alarms in the dist's own stack
|
|
202
|
+
|
|
203
|
+
cdnAlarms: createCloudFrontAlarmBuilder()
|
|
204
|
+
.distribution(ref<DistributionBuilderResult>("cdn"))
|
|
205
|
+
.recommendedAlarms({ errorRate: { threshold: 2 } })
|
|
206
|
+
.addAlarm("custom4xx", (a) =>
|
|
207
|
+
a
|
|
208
|
+
.metric(
|
|
209
|
+
() =>
|
|
210
|
+
new Metric({
|
|
211
|
+
namespace: "AWS/CloudFront",
|
|
212
|
+
metricName: "4xxErrorRate",
|
|
213
|
+
statistic: "Average",
|
|
214
|
+
}),
|
|
215
|
+
)
|
|
216
|
+
.threshold(5)
|
|
217
|
+
.greaterThan(),
|
|
218
|
+
),
|
|
219
|
+
},
|
|
220
|
+
{ cdn: [], cdnAlarms: ["cdn"] },
|
|
221
|
+
)
|
|
222
|
+
.withStacks({
|
|
223
|
+
cdn: siteStack, // e.g. eu-west-2
|
|
224
|
+
cdnAlarms: usEast1Stack, // typically your existing certStack
|
|
225
|
+
})
|
|
226
|
+
.build(app, "App");
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Set `crossRegionReferences: true` on both stacks so CDK can export `DistributionId` from the site stack and import it in the alarm stack.
|
|
230
|
+
|
|
231
|
+
`recommendedAlarms: false` on `createDistributionBuilder` is the master kill switch for both distribution-level and per-function recommended alarms. Custom alarms added via `addAlarm` are unaffected — call `.addAlarm()` on the standalone alarm builder if you want those to live in the us-east-1 stack too.
|
|
232
|
+
|
|
180
233
|
## Examples
|
|
181
234
|
|
|
182
235
|
- [StaticWebsiteStack](../examples/src/static-website/app.ts) — S3 + CloudFront static website with OAC, error pages, and content deployment
|
package/dist/alarm-config.d.ts
CHANGED
|
@@ -55,8 +55,12 @@ export interface DistributionAlarmConfig {
|
|
|
55
55
|
*/
|
|
56
56
|
export interface FunctionAlarmConfig {
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
* this function. Individual alarms can also be disabled via their
|
|
58
|
+
* Per-function switch: set to `false` to disable all recommended alarms
|
|
59
|
+
* for this one function. Individual alarms can also be disabled via their
|
|
60
|
+
* own entry. The global kill switch is
|
|
61
|
+
* {@link DistributionBuilderProps.recommendedAlarms} `: false` on the
|
|
62
|
+
* surrounding distribution builder, which suppresses every recommended
|
|
63
|
+
* alarm regardless of per-function settings.
|
|
60
64
|
* @default true
|
|
61
65
|
*/
|
|
62
66
|
enabled?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alarm-config.d.ts","sourceRoot":"","sources":["../src/alarm-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEhC;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACrC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,mBAAmB;IAClC
|
|
1
|
+
{"version":3,"file":"alarm-config.d.ts","sourceRoot":"","sources":["../src/alarm-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEhC;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACrC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEtC;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEvC;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACjC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type Distribution } from "aws-cdk-lib/aws-cloudfront";
|
|
2
|
+
import { type Alarm } from "aws-cdk-lib/aws-cloudwatch";
|
|
3
|
+
import { type IConstruct } from "constructs";
|
|
4
|
+
import { type IBuilder, type Lifecycle, type Resolvable } from "@composurecdk/core";
|
|
5
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
6
|
+
import type { DistributionAlarmConfig } from "./alarm-config.js";
|
|
7
|
+
import type { DistributionBuilderResult } from "./distribution-builder.js";
|
|
8
|
+
/**
|
|
9
|
+
* Configuration properties for {@link createCloudFrontAlarmBuilder}.
|
|
10
|
+
*
|
|
11
|
+
* The standalone alarm builder mirrors the alarm surface that
|
|
12
|
+
* {@link createDistributionBuilder} creates by default. It exists so that
|
|
13
|
+
* alarms can be created in a different stack from the distribution itself —
|
|
14
|
+
* specifically a `us-east-1` stack, since CloudFront emits all metrics there
|
|
15
|
+
* regardless of the distribution's stack region.
|
|
16
|
+
*/
|
|
17
|
+
export interface CloudFrontAlarmBuilderProps {
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for AWS-recommended CloudWatch alarms — distribution-level
|
|
20
|
+
* (5xx error rate, origin latency) and per-function (execution errors,
|
|
21
|
+
* validation errors, throttles).
|
|
22
|
+
*
|
|
23
|
+
* Mirrors {@link DistributionBuilderProps.recommendedAlarms}. Set to
|
|
24
|
+
* `false` to disable all recommended alarms; per-function alarms further
|
|
25
|
+
* respect each function's own {@link InlineFunctionDefinition.recommendedAlarms}
|
|
26
|
+
* value. Custom alarms added via {@link ICloudFrontAlarmBuilder.addAlarm}
|
|
27
|
+
* are unaffected.
|
|
28
|
+
*
|
|
29
|
+
* No alarm actions are configured by default. Use `alarmActionsPolicy` (or
|
|
30
|
+
* an `afterBuild` hook) to wire SNS or other actions onto the resulting
|
|
31
|
+
* alarms.
|
|
32
|
+
*
|
|
33
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#CloudFront
|
|
34
|
+
*/
|
|
35
|
+
recommendedAlarms?: DistributionAlarmConfig | false;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The build output of an {@link ICloudFrontAlarmBuilder}.
|
|
39
|
+
*/
|
|
40
|
+
export interface CloudFrontAlarmBuilderResult {
|
|
41
|
+
/**
|
|
42
|
+
* The CloudWatch alarms created by this builder, keyed by alarm name. Uses
|
|
43
|
+
* the same key scheme as {@link DistributionBuilderResult.alarms}.
|
|
44
|
+
*/
|
|
45
|
+
alarms: Record<string, Alarm>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A fluent builder for CloudFront-related CloudWatch alarms, decoupled from
|
|
49
|
+
* the distribution itself. Use this when the distribution lives in a stack
|
|
50
|
+
* outside `us-east-1` — route this builder's component into a us-east-1
|
|
51
|
+
* stack via `compose().withStacks()` so the alarms land where CloudFront
|
|
52
|
+
* actually emits metrics.
|
|
53
|
+
*
|
|
54
|
+
* @see {@link createCloudFrontAlarmBuilder}
|
|
55
|
+
*/
|
|
56
|
+
export type ICloudFrontAlarmBuilder = IBuilder<CloudFrontAlarmBuilderProps, CloudFrontAlarmBuilder>;
|
|
57
|
+
/**
|
|
58
|
+
* Shared alarm-assembly used by both {@link createDistributionBuilder} (in its
|
|
59
|
+
* own stack) and {@link createCloudFrontAlarmBuilder} (typically in a separate
|
|
60
|
+
* `us-east-1` stack). Materializes the recommended distribution-level alarms,
|
|
61
|
+
* the recommended per-function alarms, and any user-supplied custom alarms,
|
|
62
|
+
* emits the region warning if the resulting scope is not in `us-east-1`, and
|
|
63
|
+
* creates the alarm constructs.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildCloudFrontAlarms(scope: IConstruct, id: string, target: Pick<DistributionBuilderResult, "distribution" | "functions">, options?: {
|
|
68
|
+
recommendedAlarms?: DistributionAlarmConfig | false;
|
|
69
|
+
customAlarms?: AlarmDefinitionBuilder<Distribution>[];
|
|
70
|
+
}): Record<string, Alarm>;
|
|
71
|
+
declare class CloudFrontAlarmBuilder implements Lifecycle<CloudFrontAlarmBuilderResult> {
|
|
72
|
+
#private;
|
|
73
|
+
props: Partial<CloudFrontAlarmBuilderProps>;
|
|
74
|
+
/**
|
|
75
|
+
* Sets the distribution to alarm on. Pass the result of
|
|
76
|
+
* {@link createDistributionBuilder} (or a {@link Ref} to it). The builder
|
|
77
|
+
* reads the distribution and any inline-function metadata from the result.
|
|
78
|
+
*
|
|
79
|
+
* Pair with `compose().withStacks()` to route this component into a
|
|
80
|
+
* `us-east-1` stack while the distribution itself lives elsewhere — set
|
|
81
|
+
* `crossRegionReferences: true` on both stacks so CDK can wire the
|
|
82
|
+
* `DistributionId` reference automatically.
|
|
83
|
+
*/
|
|
84
|
+
distribution(distribution: Resolvable<DistributionBuilderResult>): this;
|
|
85
|
+
/**
|
|
86
|
+
* Adds a custom alarm against the distribution. The configure callback
|
|
87
|
+
* receives a fresh {@link AlarmDefinitionBuilder} pre-set with the alarm's
|
|
88
|
+
* key; configure metric, threshold, comparison and any other options.
|
|
89
|
+
*
|
|
90
|
+
* The created alarm is materialized in this builder's stack — useful for
|
|
91
|
+
* cross-region setups where you want all CloudFront alarms to live with the
|
|
92
|
+
* recommended ones.
|
|
93
|
+
*/
|
|
94
|
+
addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<Distribution>) => AlarmDefinitionBuilder<Distribution>): this;
|
|
95
|
+
build(scope: IConstruct, id: string, context?: Record<string, object>): CloudFrontAlarmBuilderResult;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new {@link ICloudFrontAlarmBuilder} for materializing CloudFront
|
|
99
|
+
* alarms in a stack separate from the distribution itself.
|
|
100
|
+
*
|
|
101
|
+
* The recommended use is multi-region deployments: the distribution lives in
|
|
102
|
+
* the site's stack (often outside `us-east-1` for latency or compliance
|
|
103
|
+
* reasons), and CloudFront alarms must live in a `us-east-1` stack so they
|
|
104
|
+
* can read the metrics CloudFront emits there.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* compose(
|
|
109
|
+
* {
|
|
110
|
+
* cdn: createDistributionBuilder()
|
|
111
|
+
* .origin(...)
|
|
112
|
+
* .defaultBehavior({ functions: [{ eventType, code }] })
|
|
113
|
+
* .recommendedAlarms(false), // suppress alarms in the dist's own stack
|
|
114
|
+
*
|
|
115
|
+
* cdnAlarms: createCloudFrontAlarmBuilder()
|
|
116
|
+
* .distribution(ref<DistributionBuilderResult>("cdn"))
|
|
117
|
+
* .recommendedAlarms({ errorRate: { threshold: 2 } }),
|
|
118
|
+
* },
|
|
119
|
+
* { cdn: [], cdnAlarms: ["cdn"] },
|
|
120
|
+
* )
|
|
121
|
+
* .withStacks({
|
|
122
|
+
* cdn: siteStack, // eu-west-2
|
|
123
|
+
* cdnAlarms: certStack, // us-east-1 (existing ACM stack)
|
|
124
|
+
* })
|
|
125
|
+
* .build(app, "App");
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* Set `crossRegionReferences: true` on both stacks so CDK can export the
|
|
129
|
+
* `DistributionId` from the site stack and import it in the alarm stack.
|
|
130
|
+
*/
|
|
131
|
+
export declare function createCloudFrontAlarmBuilder(): ICloudFrontAlarmBuilder;
|
|
132
|
+
export {};
|
|
133
|
+
//# sourceMappingURL=cloudfront-alarm-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudfront-alarm-builder.d.ts","sourceRoot":"","sources":["../src/cloudfront-alarm-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAExD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,SAAS,EAEd,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,sBAAsB,EAAgB,MAAM,0BAA0B,CAAC;AAChF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAGjE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAE3E;;;;;;;;GAQG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;;;;;;;;;;;;;OAgBG;IACH,iBAAiB,CAAC,EAAE,uBAAuB,GAAG,KAAK,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC,2BAA2B,EAAE,sBAAsB,CAAC,CAAC;AAsBpG;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,IAAI,CAAC,yBAAyB,EAAE,cAAc,GAAG,WAAW,CAAC,EACrE,OAAO,GAAE;IACP,iBAAiB,CAAC,EAAE,uBAAuB,GAAG,KAAK,CAAC;IACpD,YAAY,CAAC,EAAE,sBAAsB,CAAC,YAAY,CAAC,EAAE,CAAC;CAClD,GACL,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAyBvB;AAED,cAAM,sBAAuB,YAAW,SAAS,CAAC,4BAA4B,CAAC;;IAC7E,KAAK,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAM;IAIjD;;;;;;;;;OASG;IACH,YAAY,CAAC,YAAY,EAAE,UAAU,CAAC,yBAAyB,CAAC,GAAG,IAAI;IAKvE;;;;;;;;OAQG;IACH,QAAQ,CACN,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,CACT,KAAK,EAAE,sBAAsB,CAAC,YAAY,CAAC,KACxC,sBAAsB,CAAC,YAAY,CAAC,GACxC,IAAI;IAKP,KAAK,CACH,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,4BAA4B;CAehC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,4BAA4B,IAAI,uBAAuB,CAEtE"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Annotations, Stack, Token } from "aws-cdk-lib";
|
|
2
|
+
import { Builder, resolve, } from "@composurecdk/core";
|
|
3
|
+
import { AlarmDefinitionBuilder, createAlarms } from "@composurecdk/cloudwatch";
|
|
4
|
+
import { resolveDistributionAlarmDefinitions } from "./distribution-alarms.js";
|
|
5
|
+
import { resolveBehaviorFunctionAlarmDefinitions } from "./behavior-function-alarms.js";
|
|
6
|
+
/**
|
|
7
|
+
* CloudFront metrics are emitted in `us-east-1` only. CloudWatch alarms are
|
|
8
|
+
* regional, so alarms created in any other region will never receive data.
|
|
9
|
+
* Warn (don't error) when alarms are being created outside `us-east-1`,
|
|
10
|
+
* unless the region is an unresolved token (env-agnostic stack — user knows
|
|
11
|
+
* best).
|
|
12
|
+
*/
|
|
13
|
+
function warnIfNotUsEast1(scope) {
|
|
14
|
+
const region = Stack.of(scope).region;
|
|
15
|
+
if (Token.isUnresolved(region))
|
|
16
|
+
return;
|
|
17
|
+
if (region === "us-east-1")
|
|
18
|
+
return;
|
|
19
|
+
Annotations.of(scope).addWarningV2("@composurecdk/cloudfront:alarm-region", `CloudFront metrics are emitted in us-east-1 only, but this stack is deployed ` +
|
|
20
|
+
`in "${region}". CloudWatch alarms created here will not fire. Deploy the ` +
|
|
21
|
+
`stack in us-east-1, or use createCloudFrontAlarmBuilder() routed to a ` +
|
|
22
|
+
`us-east-1 stack via compose().withStacks().`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Shared alarm-assembly used by both {@link createDistributionBuilder} (in its
|
|
26
|
+
* own stack) and {@link createCloudFrontAlarmBuilder} (typically in a separate
|
|
27
|
+
* `us-east-1` stack). Materializes the recommended distribution-level alarms,
|
|
28
|
+
* the recommended per-function alarms, and any user-supplied custom alarms,
|
|
29
|
+
* emits the region warning if the resulting scope is not in `us-east-1`, and
|
|
30
|
+
* creates the alarm constructs.
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export function buildCloudFrontAlarms(scope, id, target, options = {}) {
|
|
35
|
+
const recommended = options.recommendedAlarms;
|
|
36
|
+
const recommendedDefs = recommended === false || recommended?.enabled === false
|
|
37
|
+
? []
|
|
38
|
+
: [
|
|
39
|
+
...resolveDistributionAlarmDefinitions(target.distribution, recommended),
|
|
40
|
+
...Object.values(target.functions).flatMap((entry) => resolveBehaviorFunctionAlarmDefinitions(entry.pathPattern, entry.eventType, entry.function, entry.recommendedAlarms)),
|
|
41
|
+
];
|
|
42
|
+
const customAlarmDefs = options.customAlarms?.map((b) => b.resolve(target.distribution)) ?? [];
|
|
43
|
+
const allAlarmDefs = [...recommendedDefs, ...customAlarmDefs];
|
|
44
|
+
if (allAlarmDefs.length > 0) {
|
|
45
|
+
warnIfNotUsEast1(scope);
|
|
46
|
+
}
|
|
47
|
+
return createAlarms(scope, id, allAlarmDefs);
|
|
48
|
+
}
|
|
49
|
+
class CloudFrontAlarmBuilder {
|
|
50
|
+
props = {};
|
|
51
|
+
#distribution;
|
|
52
|
+
#customAlarms = [];
|
|
53
|
+
/**
|
|
54
|
+
* Sets the distribution to alarm on. Pass the result of
|
|
55
|
+
* {@link createDistributionBuilder} (or a {@link Ref} to it). The builder
|
|
56
|
+
* reads the distribution and any inline-function metadata from the result.
|
|
57
|
+
*
|
|
58
|
+
* Pair with `compose().withStacks()` to route this component into a
|
|
59
|
+
* `us-east-1` stack while the distribution itself lives elsewhere — set
|
|
60
|
+
* `crossRegionReferences: true` on both stacks so CDK can wire the
|
|
61
|
+
* `DistributionId` reference automatically.
|
|
62
|
+
*/
|
|
63
|
+
distribution(distribution) {
|
|
64
|
+
this.#distribution = distribution;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Adds a custom alarm against the distribution. The configure callback
|
|
69
|
+
* receives a fresh {@link AlarmDefinitionBuilder} pre-set with the alarm's
|
|
70
|
+
* key; configure metric, threshold, comparison and any other options.
|
|
71
|
+
*
|
|
72
|
+
* The created alarm is materialized in this builder's stack — useful for
|
|
73
|
+
* cross-region setups where you want all CloudFront alarms to live with the
|
|
74
|
+
* recommended ones.
|
|
75
|
+
*/
|
|
76
|
+
addAlarm(key, configure) {
|
|
77
|
+
this.#customAlarms.push(configure(new AlarmDefinitionBuilder(key)));
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
build(scope, id, context) {
|
|
81
|
+
if (!this.#distribution) {
|
|
82
|
+
throw new Error(`CloudFrontAlarmBuilder "${id}" requires a distribution. ` +
|
|
83
|
+
`Call .distribution() with a DistributionBuilderResult or a Ref to one.`);
|
|
84
|
+
}
|
|
85
|
+
const distribution = resolve(this.#distribution, context ?? {});
|
|
86
|
+
return {
|
|
87
|
+
alarms: buildCloudFrontAlarms(scope, id, distribution, {
|
|
88
|
+
recommendedAlarms: this.props.recommendedAlarms,
|
|
89
|
+
customAlarms: this.#customAlarms,
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new {@link ICloudFrontAlarmBuilder} for materializing CloudFront
|
|
96
|
+
* alarms in a stack separate from the distribution itself.
|
|
97
|
+
*
|
|
98
|
+
* The recommended use is multi-region deployments: the distribution lives in
|
|
99
|
+
* the site's stack (often outside `us-east-1` for latency or compliance
|
|
100
|
+
* reasons), and CloudFront alarms must live in a `us-east-1` stack so they
|
|
101
|
+
* can read the metrics CloudFront emits there.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* compose(
|
|
106
|
+
* {
|
|
107
|
+
* cdn: createDistributionBuilder()
|
|
108
|
+
* .origin(...)
|
|
109
|
+
* .defaultBehavior({ functions: [{ eventType, code }] })
|
|
110
|
+
* .recommendedAlarms(false), // suppress alarms in the dist's own stack
|
|
111
|
+
*
|
|
112
|
+
* cdnAlarms: createCloudFrontAlarmBuilder()
|
|
113
|
+
* .distribution(ref<DistributionBuilderResult>("cdn"))
|
|
114
|
+
* .recommendedAlarms({ errorRate: { threshold: 2 } }),
|
|
115
|
+
* },
|
|
116
|
+
* { cdn: [], cdnAlarms: ["cdn"] },
|
|
117
|
+
* )
|
|
118
|
+
* .withStacks({
|
|
119
|
+
* cdn: siteStack, // eu-west-2
|
|
120
|
+
* cdnAlarms: certStack, // us-east-1 (existing ACM stack)
|
|
121
|
+
* })
|
|
122
|
+
* .build(app, "App");
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* Set `crossRegionReferences: true` on both stacks so CDK can export the
|
|
126
|
+
* `DistributionId` from the site stack and import it in the alarm stack.
|
|
127
|
+
*/
|
|
128
|
+
export function createCloudFrontAlarmBuilder() {
|
|
129
|
+
return Builder(CloudFrontAlarmBuilder);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=cloudfront-alarm-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudfront-alarm-builder.js","sourceRoot":"","sources":["../src/cloudfront-alarm-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EACL,OAAO,EAGP,OAAO,GAER,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEhF,OAAO,EAAE,mCAAmC,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,uCAAuC,EAAE,MAAM,+BAA+B,CAAC;AAuDxF;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,KAAiB;IACzC,MAAM,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC;QAAE,OAAO;IACvC,IAAI,MAAM,KAAK,WAAW;QAAE,OAAO;IACnC,WAAW,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,YAAY,CAChC,uCAAuC,EACvC,+EAA+E;QAC7E,OAAO,MAAM,8DAA8D;QAC3E,wEAAwE;QACxE,6CAA6C,CAChD,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAiB,EACjB,EAAU,EACV,MAAqE,EACrE,UAGI,EAAE;IAEN,MAAM,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAC9C,MAAM,eAAe,GACnB,WAAW,KAAK,KAAK,IAAI,WAAW,EAAE,OAAO,KAAK,KAAK;QACrD,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC;YACE,GAAG,mCAAmC,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC;YACxE,GAAG,MAAM,CAAC,MAAM,CAAC,M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ACD,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;QAChE,OAAO;YACL,MAAM,EAAE,qBAAqB,CAAC,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE;gBACrD,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB;gBAC/C,YAAY,EAAE,IAAI,CAAC,aAAa;aACjC,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO,OAAO,CAAsD,sBAAsB,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -6,6 +6,30 @@ import { type IConstruct } from "constructs";
|
|
|
6
6
|
import { type IBuilder, type Lifecycle, type Resolvable } from "@composurecdk/core";
|
|
7
7
|
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
8
8
|
import type { DistributionAlarmConfig, FunctionAlarmConfig } from "./alarm-config.js";
|
|
9
|
+
/**
|
|
10
|
+
* Per-function metadata exposed on {@link DistributionBuilderResult.functions}.
|
|
11
|
+
* Bundles the CDK construct with the behavior context the builder used to
|
|
12
|
+
* create it. Consumers (notably {@link createCloudFrontAlarmBuilder}) use the
|
|
13
|
+
* `pathPattern`, `eventType`, and `recommendedAlarms` fields to reproduce the
|
|
14
|
+
* same recommended alarms in a different stack.
|
|
15
|
+
*/
|
|
16
|
+
export interface FunctionEntry {
|
|
17
|
+
/** The CloudFront Function created by the distribution builder. */
|
|
18
|
+
function: CfFunction;
|
|
19
|
+
/**
|
|
20
|
+
* The behavior the function is attached to. `null` for the default behavior;
|
|
21
|
+
* otherwise the path pattern (e.g. `"/api/*"`).
|
|
22
|
+
*/
|
|
23
|
+
pathPattern: string | null;
|
|
24
|
+
/** The viewer event the function handles. */
|
|
25
|
+
eventType: FunctionEventType;
|
|
26
|
+
/**
|
|
27
|
+
* The {@link InlineFunctionDefinition.recommendedAlarms} value the user
|
|
28
|
+
* supplied for this function. Omitted entirely when the user did not
|
|
29
|
+
* provide one — consumers should treat that as "use defaults".
|
|
30
|
+
*/
|
|
31
|
+
recommendedAlarms?: FunctionAlarmConfig | false;
|
|
32
|
+
}
|
|
9
33
|
/**
|
|
10
34
|
* A CloudFront Function declared inline on a cache behavior. The distribution
|
|
11
35
|
* builder creates the underlying {@link CfFunction} construct and wires it
|
|
@@ -139,40 +163,44 @@ export interface DistributionBuilderProps extends Omit<DistributionProps, "defau
|
|
|
139
163
|
* Configuration for AWS-recommended CloudWatch alarms at the **distribution**
|
|
140
164
|
* level (5xx error rate, origin latency).
|
|
141
165
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
166
|
+
* Per-function alarm shapes (`FunctionExecutionErrors`,
|
|
167
|
+
* `FunctionValidationErrors`, `FunctionThrottles`) are configured per
|
|
168
|
+
* function via {@link InlineFunctionDefinition.recommendedAlarms}, because
|
|
169
|
+
* their correct disposition depends on the behavior the function is
|
|
170
|
+
* attached to. The kill switch below (`recommendedAlarms: false`) still
|
|
171
|
+
* applies to function alarms — see below.
|
|
147
172
|
*
|
|
148
173
|
* **Region requirement:** CloudFront metrics are emitted in `us-east-1`
|
|
149
|
-
* only. CloudWatch alarms are regional, so
|
|
150
|
-
* builder
|
|
151
|
-
*
|
|
152
|
-
*
|
|
174
|
+
* only. CloudWatch alarms are regional, so every alarm created by this
|
|
175
|
+
* builder will only fire if the containing stack is deployed in
|
|
176
|
+
* `us-east-1`. The builder emits a synth-time warning if this isn't the
|
|
177
|
+
* case. For multi-region deployments, set `recommendedAlarms: false` here
|
|
178
|
+
* and use {@link createCloudFrontAlarmBuilder} routed to a `us-east-1`
|
|
179
|
+
* stack via `compose().withStacks()`.
|
|
153
180
|
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
181
|
+
* Set to `false` to disable all recommended alarms (both distribution-level
|
|
182
|
+
* and per-function). Custom alarms added via
|
|
183
|
+
* {@link IDistributionBuilder.addAlarm} are unaffected. To disable a single
|
|
184
|
+
* function's alarms, set `recommendedAlarms: false` on the corresponding
|
|
185
|
+
* {@link InlineFunctionDefinition}.
|
|
159
186
|
*
|
|
160
187
|
* No alarm actions are configured by default since notification methods
|
|
161
188
|
* are user-specific. Access alarms from the build result or use an
|
|
162
189
|
* `afterBuild` hook to apply actions.
|
|
163
190
|
*
|
|
164
|
-
* @example
|
|
191
|
+
* @example Tighter dist-level threshold; function alarms unchanged.
|
|
192
|
+
* ```ts
|
|
193
|
+
* createDistributionBuilder()
|
|
194
|
+
* .origin(siteOrigin)
|
|
195
|
+
* .recommendedAlarms({ errorRate: { threshold: 2 } });
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example Multi-region setup — suppress all alarms here, recreate them in
|
|
199
|
+
* a `us-east-1` stack via {@link createCloudFrontAlarmBuilder}.
|
|
165
200
|
* ```ts
|
|
166
201
|
* createDistributionBuilder()
|
|
167
202
|
* .origin(siteOrigin)
|
|
168
|
-
* .recommendedAlarms(false)
|
|
169
|
-
* .defaultBehavior({
|
|
170
|
-
* functions: [{
|
|
171
|
-
* eventType: FunctionEventType.VIEWER_REQUEST,
|
|
172
|
-
* code,
|
|
173
|
-
* recommendedAlarms: false, // must also disable function alarms explicitly
|
|
174
|
-
* }],
|
|
175
|
-
* });
|
|
203
|
+
* .recommendedAlarms(false);
|
|
176
204
|
* ```
|
|
177
205
|
*
|
|
178
206
|
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#CloudFront
|
|
@@ -195,10 +223,11 @@ export interface DistributionBuilderResult {
|
|
|
195
223
|
* CloudFront Functions created by the builder for inline function
|
|
196
224
|
* definitions, keyed by `<behaviorScope><EventType>` —
|
|
197
225
|
* e.g. `defaultBehaviorViewerRequest`, `behaviorApiStarViewerRequest`.
|
|
198
|
-
*
|
|
199
|
-
*
|
|
226
|
+
* Each entry bundles the {@link CfFunction} with the behavior context
|
|
227
|
+
* (`pathPattern`, `eventType`) and the per-function `recommendedAlarms`
|
|
228
|
+
* config the user supplied. Empty if no inline functions were declared.
|
|
200
229
|
*/
|
|
201
|
-
functions: Record<string,
|
|
230
|
+
functions: Record<string, FunctionEntry>;
|
|
202
231
|
/**
|
|
203
232
|
* CloudWatch alarms created for the distribution and its inline functions,
|
|
204
233
|
* keyed by alarm name. Distribution-level keys: `errorRate`, `originLatency`.
|
|
@@ -206,7 +235,8 @@ export interface DistributionBuilderResult {
|
|
|
206
235
|
* e.g. `defaultBehaviorViewerRequestExecutionErrors`.
|
|
207
236
|
*
|
|
208
237
|
* Includes both recommended alarms and custom alarms added via
|
|
209
|
-
* {@link IDistributionBuilder.addAlarm}.
|
|
238
|
+
* {@link IDistributionBuilder.addAlarm}. Empty when `recommendedAlarms` is
|
|
239
|
+
* `false` and no custom alarms were added. No alarm actions are configured.
|
|
210
240
|
*/
|
|
211
241
|
alarms: Record<string, Alarm>;
|
|
212
242
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distribution-builder.d.ts","sourceRoot":"","sources":["../src/distribution-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,QAAQ,IAAI,UAAU,EAC3B,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAmB,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,KAAK,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
|
|
4
4
|
import { Builder, resolve, } from "@composurecdk/core";
|
|
5
|
-
import { AlarmDefinitionBuilder
|
|
5
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
6
6
|
import { createBucketBuilder } from "@composurecdk/s3";
|
|
7
|
-
import { resolveDistributionAlarmDefinitions } from "./distribution-alarms.js";
|
|
8
7
|
import { DISTRIBUTION_DEFAULTS } from "./defaults.js";
|
|
9
8
|
import { resolveBehaviors } from "./resolve-behaviors.js";
|
|
10
9
|
import { pathPatternSlug } from "./behavior-function-alarms.js";
|
|
11
|
-
|
|
12
|
-
* CloudFront metrics are emitted in `us-east-1` only. CloudWatch alarms are
|
|
13
|
-
* regional, so alarms created in any other region will never receive data
|
|
14
|
-
* and will never fire. Warn (don't error) the user if this builder is used
|
|
15
|
-
* from a stack deployed outside `us-east-1`, unless the region is an
|
|
16
|
-
* unresolved token (env-agnostic stack — user knows best).
|
|
17
|
-
*/
|
|
18
|
-
function warnIfNotUsEast1(scope) {
|
|
19
|
-
const region = Stack.of(scope).region;
|
|
20
|
-
if (Token.isUnresolved(region))
|
|
21
|
-
return;
|
|
22
|
-
if (region === "us-east-1")
|
|
23
|
-
return;
|
|
24
|
-
Annotations.of(scope).addWarningV2("@composurecdk/cloudfront:alarm-region", `CloudFront metrics are emitted in us-east-1 only, but this stack is deployed ` +
|
|
25
|
-
`in "${region}". CloudWatch alarms created here will not fire. Deploy the ` +
|
|
26
|
-
`stack in us-east-1, or disable recommended alarms and wire up a cross-region ` +
|
|
27
|
-
`alarm pattern yourself.`);
|
|
28
|
-
}
|
|
10
|
+
import { buildCloudFrontAlarms } from "./cloudfront-alarm-builder.js";
|
|
29
11
|
class DistributionBuilder {
|
|
30
12
|
props = {};
|
|
31
13
|
#origin;
|
|
@@ -125,19 +107,7 @@ class DistributionBuilder {
|
|
|
125
107
|
if (accessLogsBucket) {
|
|
126
108
|
distribution.node.addDependency(accessLogsBucket);
|
|
127
109
|
}
|
|
128
|
-
const
|
|
129
|
-
? []
|
|
130
|
-
: resolveDistributionAlarmDefinitions(distribution, alarmConfig);
|
|
131
|
-
const customAlarmDefs = this.#customAlarms.map((b) => b.resolve(distribution));
|
|
132
|
-
const allAlarmDefs = [
|
|
133
|
-
...distributionAlarmDefs,
|
|
134
|
-
...behaviors.alarmDefinitions,
|
|
135
|
-
...customAlarmDefs,
|
|
136
|
-
];
|
|
137
|
-
if (allAlarmDefs.length > 0) {
|
|
138
|
-
warnIfNotUsEast1(scope);
|
|
139
|
-
}
|
|
140
|
-
const alarms = createAlarms(scope, id, allAlarmDefs);
|
|
110
|
+
const alarms = buildCloudFrontAlarms(scope, id, { distribution, functions: behaviors.functions }, { recommendedAlarms: alarmConfig, customAlarms: this.#customAlarms });
|
|
141
111
|
return {
|
|
142
112
|
distribution,
|
|
143
113
|
accessLogsBucket,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distribution-builder.js","sourceRoot":"","sources":["../src/distribution-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAUb,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAe,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"distribution-builder.js","sourceRoot":"","sources":["../src/distribution-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAUb,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAe,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EACL,OAAO,EAGP,OAAO,GAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,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ACrE,CAAC;QAEF,OAAO;YACL,YAAY;YACZ,gBAAgB;YAChB,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,yBAAyB;IACvC,OAAO,OAAO,CAAgD,mBAAmB,CAAC,CAAC;AACrF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createDistributionBuilder, type DistributionBuilderProps, type DistributionBuilderResult, type IDistributionBuilder, type DefaultBehaviorConfig, type AdditionalBehaviorConfig, type InlineFunctionDefinition, } from "./distribution-builder.js";
|
|
2
|
+
export { createCloudFrontAlarmBuilder, type CloudFrontAlarmBuilderProps, type CloudFrontAlarmBuilderResult, type ICloudFrontAlarmBuilder, } from "./cloudfront-alarm-builder.js";
|
|
2
3
|
export { DISTRIBUTION_DEFAULTS, INLINE_FUNCTION_DEFAULTS } from "./defaults.js";
|
|
3
4
|
export { type DistributionAlarmConfig, type FunctionAlarmConfig } from "./alarm-config.js";
|
|
4
5
|
export { DISTRIBUTION_ALARM_DEFAULTS, FUNCTION_ALARM_DEFAULTS } from "./alarm-defaults.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,GAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,GAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,4BAA4B,EAC5B,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,uBAAuB,GAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createDistributionBuilder, } from "./distribution-builder.js";
|
|
2
|
+
export { createCloudFrontAlarmBuilder, } from "./cloudfront-alarm-builder.js";
|
|
2
3
|
export { DISTRIBUTION_DEFAULTS, INLINE_FUNCTION_DEFAULTS } from "./defaults.js";
|
|
3
4
|
export { DISTRIBUTION_ALARM_DEFAULTS, FUNCTION_ALARM_DEFAULTS } from "./alarm-defaults.js";
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,GAO1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEhF,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,GAO1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,4BAA4B,GAI7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEhF,OAAO,EAAE,2BAA2B,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type AddBehaviorOptions, type BehaviorOptions,
|
|
1
|
+
import { type AddBehaviorOptions, type BehaviorOptions, type IOrigin } from "aws-cdk-lib/aws-cloudfront";
|
|
2
2
|
import type { IConstruct } from "constructs";
|
|
3
|
-
import type {
|
|
4
|
-
import type { AdditionalBehaviorConfig, DefaultBehaviorConfig } from "./distribution-builder.js";
|
|
3
|
+
import type { AdditionalBehaviorConfig, DefaultBehaviorConfig, FunctionEntry } from "./distribution-builder.js";
|
|
5
4
|
/**
|
|
6
5
|
* Input required to resolve the default behavior, all additional behaviors,
|
|
7
6
|
* and any inline CloudFront Functions into concrete CDK objects.
|
|
@@ -36,12 +35,14 @@ export interface ResolveBehaviorsResult {
|
|
|
36
35
|
/** Concrete `BehaviorOptions` keyed by path pattern, in insertion order. */
|
|
37
36
|
additionalBehaviors: Record<string, BehaviorOptions>;
|
|
38
37
|
/**
|
|
39
|
-
* Owned inline CloudFront Functions
|
|
40
|
-
* `<behaviorScope><EventType>` —
|
|
38
|
+
* Owned inline CloudFront Functions plus the behavior context the builder
|
|
39
|
+
* used to create each one, keyed by `<behaviorScope><EventType>` —
|
|
40
|
+
* e.g. `defaultBehaviorViewerRequest`. Consumed by the alarm-creation code
|
|
41
|
+
* path (in {@link DistributionBuilder} and
|
|
42
|
+
* {@link createCloudFrontAlarmBuilder}) to materialize per-function
|
|
43
|
+
* recommended alarms.
|
|
41
44
|
*/
|
|
42
|
-
functions: Record<string,
|
|
43
|
-
/** Alarm definitions for the owned inline functions. */
|
|
44
|
-
alarmDefinitions: AlarmDefinition[];
|
|
45
|
+
functions: Record<string, FunctionEntry>;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Materializes the default and additional cache behaviors into CDK-ready
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-behaviors.d.ts","sourceRoot":"","sources":["../src/resolve-behaviors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"resolve-behaviors.d.ts","sourceRoot":"","sources":["../src/resolve-behaviors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EAMpB,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAQ7C,OAAO,KAAK,EACV,wBAAwB,EACxB,qBAAqB,EACrB,aAAa,EAEd,MAAM,2BAA2B,CAAC;AAEnC;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,KAAK,EAAE,UAAU,CAAC;IAElB,2EAA2E;IAC3E,EAAE,EAAE,MAAM,CAAC;IAEX,4EAA4E;IAC5E,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC,2CAA2C;IAC3C,aAAa,EAAE,OAAO,CAAC;IAEvB,gEAAgE;IAChE,eAAe,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAEnD,0EAA0E;IAC1E,uBAAuB,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAErD;;;OAGG;IACH,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;CAC5D;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,iEAAiE;IACjE,eAAe,EAAE,eAAe,CAAC;IAEjC,4EAA4E;IAC5E,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAErD;;;;;;;OAOG;IACH,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC1C;AAiDD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,sBAAsB,CA0DrF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Function as CfFunction, FunctionRuntime, } from "aws-cdk-lib/aws-cloudfront";
|
|
2
2
|
import { resolve } from "@composurecdk/core";
|
|
3
|
-
import { behaviorFunctionKeyPrefix, eventTypePascal, pathPatternSlug,
|
|
3
|
+
import { behaviorFunctionKeyPrefix, eventTypePascal, pathPatternSlug, } from "./behavior-function-alarms.js";
|
|
4
4
|
import { INLINE_FUNCTION_DEFAULTS } from "./defaults.js";
|
|
5
5
|
function scopeLabel(pathPattern) {
|
|
6
6
|
return pathPattern === null ? "default behavior" : `behavior "${pathPattern}"`;
|
|
@@ -47,7 +47,6 @@ function assertKeyValueStoreRuntime(def, pathPattern) {
|
|
|
47
47
|
export function resolveBehaviors(input) {
|
|
48
48
|
const { scope, id, context, defaultOrigin, defaultBehavior, defaultBehaviorDefaults } = input;
|
|
49
49
|
const functions = {};
|
|
50
|
-
const alarmDefinitions = [];
|
|
51
50
|
const buildInlineFunctions = (pathPattern, definitions) => {
|
|
52
51
|
if (!definitions || definitions.length === 0)
|
|
53
52
|
return [];
|
|
@@ -62,9 +61,13 @@ export function resolveBehaviors(input) {
|
|
|
62
61
|
...INLINE_FUNCTION_DEFAULTS,
|
|
63
62
|
...omit(def, "eventType", "recommendedAlarms"),
|
|
64
63
|
});
|
|
65
|
-
functions[behaviorFunctionKeyPrefix(pathPattern, eventType)] =
|
|
64
|
+
functions[behaviorFunctionKeyPrefix(pathPattern, eventType)] = {
|
|
65
|
+
function: fn,
|
|
66
|
+
pathPattern,
|
|
67
|
+
eventType,
|
|
68
|
+
recommendedAlarms: def.recommendedAlarms,
|
|
69
|
+
};
|
|
66
70
|
associations.push({ function: fn, eventType });
|
|
67
|
-
alarmDefinitions.push(...resolveBehaviorFunctionAlarmDefinitions(pathPattern, eventType, fn, def.recommendedAlarms));
|
|
68
71
|
}
|
|
69
72
|
return associations;
|
|
70
73
|
};
|
|
@@ -90,7 +93,6 @@ export function resolveBehaviors(input) {
|
|
|
90
93
|
defaultBehavior: resolvedDefaultBehavior,
|
|
91
94
|
additionalBehaviors: resolvedAdditionalBehaviors,
|
|
92
95
|
functions,
|
|
93
|
-
alarmDefinitions,
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
98
|
//# sourceMappingURL=resolve-behaviors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-behaviors.js","sourceRoot":"","sources":["../src/resolve-behaviors.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,IAAI,UAAU,EAItB,eAAe,GAEhB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve-behaviors.js","sourceRoot":"","sources":["../src/resolve-behaviors.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,IAAI,UAAU,EAItB,eAAe,GAEhB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,yBAAyB,EACzB,eAAe,EACf,eAAe,GAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AA6DzD,SAAS,UAAU,CAAC,WAA0B;IAC5C,OAAO,WAAW,KAAK,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,aAAa,WAAW,GAAG,CAAC;AACjF,CAAC;AAED,SAAS,eAAe,CAAC,WA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