@composurecdk/lambda 0.6.0 → 0.8.0

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.
Files changed (81) hide show
  1. package/README.md +138 -6
  2. package/dist/{alarm-config.d.ts → commonjs/alarm-config.d.ts} +30 -0
  3. package/dist/commonjs/alarm-config.d.ts.map +1 -0
  4. package/dist/commonjs/alarm-config.js +3 -0
  5. package/dist/{alarm-config.js.map → commonjs/alarm-config.js.map} +1 -1
  6. package/dist/{alarm-defaults.d.ts → commonjs/alarm-defaults.d.ts} +2 -0
  7. package/dist/commonjs/alarm-defaults.d.ts.map +1 -0
  8. package/dist/commonjs/alarm-defaults.js +61 -0
  9. package/dist/commonjs/alarm-defaults.js.map +1 -0
  10. package/dist/commonjs/defaults.d.ts.map +1 -0
  11. package/dist/commonjs/defaults.js +23 -0
  12. package/dist/commonjs/defaults.js.map +1 -0
  13. package/dist/commonjs/event-sources/composure-event-source.d.ts +76 -0
  14. package/dist/commonjs/event-sources/composure-event-source.d.ts.map +1 -0
  15. package/dist/commonjs/event-sources/composure-event-source.js +36 -0
  16. package/dist/commonjs/event-sources/composure-event-source.js.map +1 -0
  17. package/dist/commonjs/event-sources/sqs-event-source.d.ts +54 -0
  18. package/dist/commonjs/event-sources/sqs-event-source.d.ts.map +1 -0
  19. package/dist/commonjs/event-sources/sqs-event-source.js +80 -0
  20. package/dist/commonjs/event-sources/sqs-event-source.js.map +1 -0
  21. package/dist/{function-alarms.d.ts → commonjs/function-alarms.d.ts} +5 -2
  22. package/dist/commonjs/function-alarms.d.ts.map +1 -0
  23. package/dist/commonjs/function-alarms.js +191 -0
  24. package/dist/commonjs/function-alarms.js.map +1 -0
  25. package/dist/commonjs/function-builder.d.ts +252 -0
  26. package/dist/commonjs/function-builder.d.ts.map +1 -0
  27. package/dist/commonjs/function-builder.js +233 -0
  28. package/dist/commonjs/function-builder.js.map +1 -0
  29. package/dist/{index.d.ts → commonjs/index.d.ts} +2 -0
  30. package/dist/commonjs/index.d.ts.map +1 -0
  31. package/dist/commonjs/index.js +13 -0
  32. package/dist/commonjs/index.js.map +1 -0
  33. package/dist/commonjs/package.json +3 -0
  34. package/dist/esm/alarm-config.d.ts +114 -0
  35. package/dist/esm/alarm-config.d.ts.map +1 -0
  36. package/dist/esm/alarm-config.js.map +1 -0
  37. package/dist/esm/alarm-defaults.d.ts +19 -0
  38. package/dist/esm/alarm-defaults.d.ts.map +1 -0
  39. package/dist/{alarm-defaults.js → esm/alarm-defaults.js} +14 -0
  40. package/dist/esm/alarm-defaults.js.map +1 -0
  41. package/dist/esm/defaults.d.ts +8 -0
  42. package/dist/esm/defaults.d.ts.map +1 -0
  43. package/dist/esm/defaults.js.map +1 -0
  44. package/dist/esm/event-sources/composure-event-source.d.ts +76 -0
  45. package/dist/esm/event-sources/composure-event-source.d.ts.map +1 -0
  46. package/dist/esm/event-sources/composure-event-source.js +31 -0
  47. package/dist/esm/event-sources/composure-event-source.js.map +1 -0
  48. package/dist/esm/event-sources/sqs-event-source.d.ts +54 -0
  49. package/dist/esm/event-sources/sqs-event-source.d.ts.map +1 -0
  50. package/dist/esm/event-sources/sqs-event-source.js +76 -0
  51. package/dist/esm/event-sources/sqs-event-source.js.map +1 -0
  52. package/dist/esm/function-alarms.d.ts +31 -0
  53. package/dist/esm/function-alarms.d.ts.map +1 -0
  54. package/dist/{function-alarms.js → esm/function-alarms.js} +69 -4
  55. package/dist/esm/function-alarms.js.map +1 -0
  56. package/dist/esm/function-builder.d.ts +252 -0
  57. package/dist/esm/function-builder.d.ts.map +1 -0
  58. package/dist/esm/function-builder.js +230 -0
  59. package/dist/esm/function-builder.js.map +1 -0
  60. package/dist/esm/index.d.ts +7 -0
  61. package/dist/esm/index.d.ts.map +1 -0
  62. package/dist/{index.js → esm/index.js} +1 -0
  63. package/dist/esm/index.js.map +1 -0
  64. package/dist/esm/package.json +3 -0
  65. package/package.json +38 -17
  66. package/dist/alarm-config.d.ts.map +0 -1
  67. package/dist/alarm-defaults.d.ts.map +0 -1
  68. package/dist/alarm-defaults.js.map +0 -1
  69. package/dist/defaults.d.ts.map +0 -1
  70. package/dist/defaults.js.map +0 -1
  71. package/dist/function-alarms.d.ts.map +0 -1
  72. package/dist/function-alarms.js.map +0 -1
  73. package/dist/function-builder.d.ts +0 -137
  74. package/dist/function-builder.d.ts.map +0 -1
  75. package/dist/function-builder.js +0 -62
  76. package/dist/function-builder.js.map +0 -1
  77. package/dist/index.d.ts.map +0 -1
  78. package/dist/index.js.map +0 -1
  79. /package/dist/{defaults.d.ts → commonjs/defaults.d.ts} +0 -0
  80. /package/dist/{alarm-config.js → esm/alarm-config.js} +0 -0
  81. /package/dist/{defaults.js → esm/defaults.js} +0 -0
package/README.md CHANGED
@@ -49,16 +49,92 @@ const handler = createFunctionBuilder()
49
49
  .build(stack, "MyFunction");
50
50
  ```
51
51
 
52
+ ## Execution role
53
+
54
+ By default, `createFunctionBuilder` creates an explicit IAM execution role with an inline `LogsWriter` policy scoped to the function's auto-created log group:
55
+
56
+ - `logs:CreateLogStream` and `logs:PutLogEvents` on the function's specific log group ARN.
57
+ - No `logs:CreateLogGroup` (the builder pre-creates the group).
58
+ - No `AWSLambdaBasicExecutionRole` managed policy — that policy grants the same actions on `*`, allowing a compromised function to write to any log group in the account.
59
+
60
+ The role is exposed on the build result:
61
+
62
+ ```ts
63
+ const result = createFunctionBuilder()
64
+ .runtime(Runtime.NODEJS_22_X)
65
+ .handler("index.handler")
66
+ .code(Code.fromAsset("lambda"))
67
+ .build(stack, "MyFunction");
68
+
69
+ result.role; // IRole — the execution role attached to the function
70
+ ```
71
+
72
+ CDK continues to layer X-Ray, VPC, KMS-env, DLQ, and EFS permissions onto the role automatically based on the function's other props.
73
+
74
+ ### Extending the default role: `.configureRole(fn)`
75
+
76
+ For least-privilege grants alongside the defaults:
77
+
78
+ ```ts
79
+ import { createStatementBuilder } from "@composurecdk/iam";
80
+
81
+ const handler = createFunctionBuilder()
82
+ .runtime(Runtime.NODEJS_22_X)
83
+ .handler("index.handler")
84
+ .code(Code.fromAsset("lambda"))
85
+ .configureRole((role) =>
86
+ role.addInlinePolicyStatements("OrdersRead", [
87
+ createStatementBuilder()
88
+ .allow()
89
+ .actions(["dynamodb:GetItem", "dynamodb:Query"])
90
+ .resources([table.tableArn]),
91
+ ]),
92
+ );
93
+ ```
94
+
95
+ The callback receives the internal [`IRoleBuilder`](../iam/README.md). Calling `configureRole` more than once replaces the previous callback. The reserved `LogsWriter` name throws at build time if added a second time.
96
+
97
+ ### Supplying a role: `.role(role)`
98
+
99
+ For a fully external role. The builder skips creating its own role and **does not** auto-attach the `LogsWriter` policy — the caller takes responsibility for permissions. Accepts a concrete `IRole` or a `ref(...)` for cross-component wiring under `compose`:
100
+
101
+ ```ts
102
+ import { compose, ref } from "@composurecdk/core";
103
+ import { createServiceRoleBuilder, type RoleBuilderResult } from "@composurecdk/iam";
104
+
105
+ compose(
106
+ {
107
+ sharedRole: createServiceRoleBuilder("lambda.amazonaws.com"),
108
+ handler: createFunctionBuilder()
109
+ .runtime(Runtime.NODEJS_22_X)
110
+ .handler("index.handler")
111
+ .code(Code.fromAsset("lambda"))
112
+ .role(ref("sharedRole", (r: RoleBuilderResult) => r.role)),
113
+ },
114
+ { sharedRole: [], handler: ["sharedRole"] },
115
+ ).build(stack, "MySystem");
116
+ ```
117
+
118
+ ### Escape hatch: `.useCdkAutoRole()`
119
+
120
+ Opt back into CDK's auto-created role attached to `AWSLambdaBasicExecutionRole`. Not the recommended path — it re-introduces the wildcard log surface — but available for matching an existing stack's logical IDs during a phased migration.
121
+
122
+ `.role()`, `.configureRole()`, and `.useCdkAutoRole()` are mutually exclusive; combining any two throws at build time.
123
+
52
124
  ## Recommended Alarms
53
125
 
54
126
  The builder creates [AWS-recommended CloudWatch alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#Lambda) by default. No alarm actions are configured — access alarms from the build result to add SNS topics or other actions.
55
127
 
56
- | Alarm | Metric | Default threshold | Created when |
57
- | ---------------------- | --------------------------------- | --------------------------- | ------------------------------------- |
58
- | `errors` | Errors (Sum, 1 min) | > 0 | Always |
59
- | `throttles` | Throttles (Sum, 1 min) | > 0 | Always |
60
- | `duration` | Duration (p99, 1 min) | > 90% of configured timeout | `timeout` is set |
61
- | `concurrentExecutions` | ConcurrentExecutions (Max, 1 min) | >= 80% of reserved limit | `reservedConcurrentExecutions` is set |
128
+ | Alarm | Metric | Default threshold | Created when |
129
+ | ------------------------ | --------------------------------- | --------------------------- | ------------------------------------- |
130
+ | `errors` | Errors (Sum, 1 min) | > 0 | Always |
131
+ | `throttles` | Throttles (Sum, 1 min) | > 0 | Always |
132
+ | `duration` | Duration (p99, 1 min) | > 90% of configured timeout | `timeout` is set |
133
+ | `concurrentExecutions` | ConcurrentExecutions (Max, 1 min) | >= 80% of reserved limit | `reservedConcurrentExecutions` is set |
134
+ | `<key>FailedInvocations` | FailedInvokeEventCount (Sum) | > 0 | An SQS event source is attached |
135
+ | `<key>DroppedEvents` | DroppedEventCount (Sum) | > 0 | An SQS event source is attached |
136
+
137
+ The event-source alarms are contextual: one pair is created per event source attached via `addEventSource` (see [Event sources](#event-sources)) whose kind emits per-mapping ESM metrics. Each alarm's key is the event source's key suffixed with `FailedInvocations` / `DroppedEvents` — e.g. an event source added as `"orders"` produces `ordersFailedInvocations` and `ordersDroppedEvents`. The `eventSourceFailedInvocations` / `eventSourceDroppedEvents` fields on `recommendedAlarms` tune every such alarm.
62
138
 
63
139
  The defaults are exported as `FUNCTION_ALARM_DEFAULTS` for visibility and testing:
64
140
 
@@ -144,7 +220,63 @@ for (const alarm of Object.values(result.alarms)) {
144
220
  }
145
221
  ```
146
222
 
223
+ ## Event sources
224
+
225
+ `addEventSource(key, source)` wires a queue or stream to the function. A Lambda
226
+ function can have many event sources of mixed types, so the hook is repeatable
227
+ and keyed — the resolved sources are exposed on `result.eventSources`.
228
+
229
+ Pass a `ComposureEventSource` from a factory (`sqsEventSource`), which carries
230
+ its own `Resolvable` so the source queue can be a `ref()` to a sibling
231
+ component, or a bare CDK `IEventSource` as an escape hatch.
232
+
233
+ ```ts
234
+ import { compose, ref } from "@composurecdk/core";
235
+ import { createFunctionBuilder, sqsEventSource } from "@composurecdk/lambda";
236
+ import { createQueueBuilder } from "@composurecdk/sqs";
237
+
238
+ const system = compose(
239
+ {
240
+ orders: createQueueBuilder().queueName("orders"),
241
+ processor: createFunctionBuilder()
242
+ .runtime(Runtime.NODEJS_22_X)
243
+ .handler("index.handler")
244
+ .code(Code.fromAsset("lambda"))
245
+ .addEventSource("orders", sqsEventSource(ref("orders", (r) => r.queue))),
246
+ },
247
+ { orders: [], processor: ["orders"] },
248
+ );
249
+ ```
250
+
251
+ The source is attached _after_ the function and its least-privilege execution
252
+ role exist, so the `source.bind(fn)` that `addEventSource` performs grants the
253
+ queue-consume permission onto the builder's role rather than CDK's auto-role.
254
+
255
+ ### Secure defaults
256
+
257
+ `sqsEventSource` applies AWS-recommended defaults, each overridable via the
258
+ second `props` argument and exported as `DEFAULT_SQS_EVENT_SOURCE_PROPS`:
259
+
260
+ | Property | Default | Rationale |
261
+ | ------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------- |
262
+ | `reportBatchItemFailures` | `true` | A single poison message fails only its own record, not the whole batch. CDK defaults this `false`. |
263
+ | `metricsConfig` | `{ metrics: [EventCount] }` | Enables the per-mapping ESM metrics that back the event-source contextual alarms. |
264
+
265
+ ### Cross-component invariants
266
+
267
+ AWS Well-Architected guidance spans the queue and the function — the source
268
+ queue's visibility timeout should be ≥ 6× the function timeout, and its redrive
269
+ `maxReceiveCount` should be ≥ 5 before the DLQ. These are **not** enforced
270
+ today (the queue often arrives as an unresolved `ref()`); they are tracked in
271
+ [#123](https://github.com/laazyj/composureCDK/issues/123) and
272
+ [#124](https://github.com/laazyj/composureCDK/issues/124).
273
+
274
+ `kinesisEventSource` / `dynamoEventSource` and the stream-only `IteratorAge`
275
+ alarm are deferred — see [#120](https://github.com/laazyj/composureCDK/issues/120)
276
+ and [#121](https://github.com/laazyj/composureCDK/issues/121).
277
+
147
278
  ## Examples
148
279
 
149
280
  - [DualFunctionStack](../examples/src/dual-function-app.ts) — Two Lambda functions with recommended alarms, custom alarms, and SNS alarm actions
150
281
  - [MultiStackApp](../examples/src/multi-stack-app.ts) — Lambda split across stacks via `.withStacks()`, wired with `ref`
282
+ - [OrderProcessorStack](../examples/src/order-processor-app.ts) — SQS queue wired to a Lambda consumer via `sqsEventSource`
@@ -80,5 +80,35 @@ export interface FunctionAlarmConfig {
80
80
  * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#Lambda
81
81
  */
82
82
  concurrentExecutions?: PercentageAlarmConfig | false;
83
+ /**
84
+ * Alarm when an event source fails to invoke the function.
85
+ *
86
+ * Contextual: one alarm is created per event source attached via
87
+ * {@link IFunctionBuilder.addEventSource} whose kind emits per-mapping ESM
88
+ * metrics (currently SQS). The created alarm's key is the event source's
89
+ * key suffixed with `FailedInvocations` (e.g. `ordersFailedInvocations`);
90
+ * this config tunes every such alarm.
91
+ *
92
+ * Metric: `AWS/Lambda FailedInvokeEventCount`, statistic Sum, period 1
93
+ * minute, dimensioned on the event source mapping. Default threshold: > 0.
94
+ *
95
+ * @see https://aws.amazon.com/blogs/compute/introducing-new-event-source-mapping-esm-metrics-for-aws-lambda/
96
+ */
97
+ eventSourceFailedInvocations?: AlarmConfig | false;
98
+ /**
99
+ * Alarm when an event source drops events after exhausting retries or TTL.
100
+ *
101
+ * Contextual: one alarm is created per event source attached via
102
+ * {@link IFunctionBuilder.addEventSource} whose kind emits per-mapping ESM
103
+ * metrics (currently SQS). The created alarm's key is the event source's
104
+ * key suffixed with `DroppedEvents` (e.g. `ordersDroppedEvents`); this
105
+ * config tunes every such alarm.
106
+ *
107
+ * Metric: `AWS/Lambda DroppedEventCount`, statistic Sum, period 1 minute,
108
+ * dimensioned on the event source mapping. Default threshold: > 0.
109
+ *
110
+ * @see https://aws.amazon.com/blogs/compute/introducing-new-event-source-mapping-esm-metrics-for-aws-lambda/
111
+ */
112
+ eventSourceDroppedEvents?: AlarmConfig | false;
83
113
  }
84
114
  //# sourceMappingURL=alarm-config.d.ts.map
@@ -0,0 +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;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,GAAG;IACnE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC,IAAI,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC,CAAC;AAE/F;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAE7B;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEhC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAAC;IAEzC;;;;;;;;;;OAUG;IACH,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAAC;IAErD;;;;;;;;;;;;;OAaG;IACH,4BAA4B,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEnD;;;;;;;;;;;;;OAaG;IACH,wBAAwB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CAChD"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=alarm-config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"alarm-config.js","sourceRoot":"","sources":["../src/alarm-config.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"alarm-config.js","sourceRoot":"","sources":["../../src/alarm-config.ts"],"names":[],"mappings":""}
@@ -6,6 +6,8 @@ interface FunctionAlarmDefaults {
6
6
  throttles: AlarmConfigDefaults;
7
7
  duration: PercentageAlarmConfigDefaults;
8
8
  concurrentExecutions: PercentageAlarmConfigDefaults;
9
+ eventSourceFailedInvocations: AlarmConfigDefaults;
10
+ eventSourceDroppedEvents: AlarmConfigDefaults;
9
11
  }
10
12
  /**
11
13
  * AWS-recommended default alarm configuration for Lambda functions.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alarm-defaults.d.ts","sourceRoot":"","sources":["../../src/alarm-defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAEvE,UAAU,qBAAqB;IAC7B,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,mBAAmB,CAAC;IAC5B,SAAS,EAAE,mBAAmB,CAAC;IAC/B,QAAQ,EAAE,6BAA6B,CAAC;IACxC,oBAAoB,EAAE,6BAA6B,CAAC;IACpD,4BAA4B,EAAE,mBAAmB,CAAC;IAClD,wBAAwB,EAAE,mBAAmB,CAAC;CAC/C;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,qBAwDrC,CAAC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FUNCTION_ALARM_DEFAULTS = void 0;
4
+ const aws_cloudwatch_1 = require("aws-cdk-lib/aws-cloudwatch");
5
+ /**
6
+ * AWS-recommended default alarm configuration for Lambda functions.
7
+ *
8
+ * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#Lambda
9
+ */
10
+ exports.FUNCTION_ALARM_DEFAULTS = {
11
+ enabled: true,
12
+ /** Any error is worth investigating; threshold 0. */
13
+ errors: {
14
+ threshold: 0,
15
+ evaluationPeriods: 1,
16
+ datapointsToAlarm: 1,
17
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
18
+ },
19
+ /** Any throttle indicates capacity pressure; threshold 0. */
20
+ throttles: {
21
+ threshold: 0,
22
+ evaluationPeriods: 1,
23
+ datapointsToAlarm: 1,
24
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
25
+ },
26
+ /**
27
+ * p99 duration approaching timeout indicates risk of timeouts.
28
+ * 90% of the configured timeout — early warning before hard failures.
29
+ */
30
+ duration: {
31
+ thresholdPercent: 0.9,
32
+ evaluationPeriods: 3,
33
+ datapointsToAlarm: 3,
34
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
35
+ },
36
+ /**
37
+ * Concurrent executions approaching reserved concurrency indicates
38
+ * risk of throttling. 80% of the reserved limit — early warning.
39
+ */
40
+ concurrentExecutions: {
41
+ thresholdPercent: 0.8,
42
+ evaluationPeriods: 3,
43
+ datapointsToAlarm: 3,
44
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
45
+ },
46
+ /** Any failed invocation from an event source is worth investigating; threshold 0. */
47
+ eventSourceFailedInvocations: {
48
+ threshold: 0,
49
+ evaluationPeriods: 1,
50
+ datapointsToAlarm: 1,
51
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
52
+ },
53
+ /** Any dropped event is lost work; threshold 0. */
54
+ eventSourceDroppedEvents: {
55
+ threshold: 0,
56
+ evaluationPeriods: 1,
57
+ datapointsToAlarm: 1,
58
+ treatMissingData: aws_cloudwatch_1.TreatMissingData.NOT_BREACHING,
59
+ },
60
+ };
61
+ //# sourceMappingURL=alarm-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alarm-defaults.js","sourceRoot":"","sources":["../../src/alarm-defaults.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAc9D;;;;GAIG;AACU,QAAA,uBAAuB,GAA0B;IAC5D,OAAO,EAAE,IAAI;IAEb,qDAAqD;IACrD,MAAM,EAAE;QACN,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;IAED,6DAA6D;IAC7D,SAAS,EAAE;QACT,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;IAED;;;OAGG;IACH,QAAQ,EAAE;QACR,gBAAgB,EAAE,GAAG;QACrB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;IAED;;;OAGG;IACH,oBAAoB,EAAE;QACpB,gBAAgB,EAAE,GAAG;QACrB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;IAED,sFAAsF;IACtF,4BAA4B,EAAE;QAC5B,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;IAED,mDAAmD;IACnD,wBAAwB,EAAE;QACxB,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,iCAAgB,CAAC,aAAa;KACjD;CACF,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEpF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,aAAa,CAapD,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FUNCTION_DEFAULTS = void 0;
4
+ const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
5
+ /**
6
+ * Secure, AWS-recommended defaults applied to every Lambda function built
7
+ * with {@link createFunctionBuilder}. Each property can be individually
8
+ * overridden via the builder's fluent API.
9
+ */
10
+ exports.FUNCTION_DEFAULTS = {
11
+ /**
12
+ * Enable AWS X-Ray active tracing for distributed request tracking.
13
+ * @see https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/opex-distributed-tracing.html
14
+ */
15
+ tracing: aws_lambda_1.Tracing.ACTIVE,
16
+ /**
17
+ * Emit logs as structured JSON for CloudWatch Logs Insights auto-discovery
18
+ * and consistent querying across services.
19
+ * @see https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/opex-logging.html
20
+ */
21
+ loggingFormat: aws_lambda_1.LoggingFormat.JSON,
22
+ };
23
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":";;;AAAA,uDAAoF;AAEpF;;;;GAIG;AACU,QAAA,iBAAiB,GAA2B;IACvD;;;OAGG;IACH,OAAO,EAAE,oBAAO,CAAC,MAAM;IAEvB;;;;OAIG;IACH,aAAa,EAAE,0BAAa,CAAC,IAAI;CAClC,CAAC"}
@@ -0,0 +1,76 @@
1
+ import type { IEventSource } from "aws-cdk-lib/aws-lambda";
2
+ import type { Resolvable } from "@composurecdk/core";
3
+ /**
4
+ * Discriminator for the kind of event source a {@link ComposureEventSource}
5
+ * wraps. `FunctionBuilder` keys its contextual alarms and invariant checks
6
+ * off this value so it never has to `instanceof` CDK internals.
7
+ *
8
+ * `"unknown"` is the kind assigned to a bare {@link IEventSource} passed
9
+ * straight to {@link IFunctionBuilder.addEventSource} as an escape hatch —
10
+ * the builder still attaches it, but cannot reason about it.
11
+ */
12
+ export type EventSourceKind = "sqs" | "unknown";
13
+ /** @internal — brands {@link ComposureEventSource} so the guard is unambiguous. */
14
+ declare const COMPOSURE_EVENT_SOURCE: unique symbol;
15
+ /**
16
+ * A `Resolvable`-aware event source produced by a ComposureCDK factory
17
+ * (e.g. {@link sqsEventSource}).
18
+ *
19
+ * Follows the `events/targets` factory shape — the factory wraps the
20
+ * underlying CDK event source and resolves any `ref()` to a sibling
21
+ * component at build time — and additionally tags it with a
22
+ * {@link EventSourceKind} discriminator so `FunctionBuilder` can pick the
23
+ * right contextual alarms without inspecting CDK internals.
24
+ *
25
+ * Construct one via a factory rather than by hand; the brand is private.
26
+ */
27
+ export interface ComposureEventSource {
28
+ /** @internal */
29
+ readonly [COMPOSURE_EVENT_SOURCE]: true;
30
+ /** The kind of source, used to dispatch contextual alarms and checks. */
31
+ readonly kind: EventSourceKind;
32
+ /**
33
+ * The wrapped CDK event source, deferred behind a {@link Resolvable} when
34
+ * the factory was handed a `ref()` to a sibling component's output.
35
+ */
36
+ readonly source: Resolvable<IEventSource>;
37
+ }
38
+ /** @internal — assembles a branded {@link ComposureEventSource}. */
39
+ export declare function composureEventSource(kind: EventSourceKind, source: Resolvable<IEventSource>): ComposureEventSource;
40
+ /**
41
+ * Reads the event source mapping UUID off a bound CDK source, keyed by
42
+ * {@link EventSourceKind}. Defined only for kinds whose per-mapping ESM
43
+ * metrics back contextual alarms (currently SQS); `FunctionBuilder` invokes
44
+ * the reader after `addEventSource` so the binding exists. Keying off `kind`
45
+ * — like {@link EVENT_SOURCE_ALARM_SPECS} — keeps the builder from
46
+ * `instanceof`-ing CDK source classes.
47
+ *
48
+ * @internal
49
+ */
50
+ export declare const EVENT_SOURCE_MAPPING_ID_READERS: Record<EventSourceKind, ((bound: IEventSource) => string) | undefined>;
51
+ /**
52
+ * Type guard distinguishing a {@link ComposureEventSource} from a bare
53
+ * {@link IEventSource} escape-hatch value.
54
+ */
55
+ export declare function isComposureEventSource(value: ComposureEventSource | IEventSource): value is ComposureEventSource;
56
+ /**
57
+ * An event source resolved and attached to a function during build, carrying
58
+ * the metadata the alarm machinery needs to emit contextual alarms.
59
+ *
60
+ * @internal — the contract between `FunctionBuilder.build()` and the
61
+ * event-source alarm machinery in `function-alarms.ts`.
62
+ */
63
+ export interface AttachedEventSource {
64
+ /** The key the source was registered under via `addEventSource`. */
65
+ key: string;
66
+ /** The kind of source, used to dispatch contextual alarms. */
67
+ kind: EventSourceKind;
68
+ /**
69
+ * The event source mapping UUID, populated for kinds whose per-mapping
70
+ * ESM metrics back contextual alarms (currently SQS only). The contextual
71
+ * alarms key off this dimension.
72
+ */
73
+ eventSourceMappingId?: string;
74
+ }
75
+ export {};
76
+ //# sourceMappingURL=composure-event-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composure-event-source.d.ts","sourceRoot":"","sources":["../../../src/event-sources/composure-event-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,SAAS,CAAC;AAEhD,mFAAmF;AACnF,QAAA,MAAM,sBAAsB,eAAgD,CAAC;AAE7E;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,oBAAoB;IACnC,gBAAgB;IAChB,QAAQ,CAAC,CAAC,sBAAsB,CAAC,EAAE,IAAI,CAAC;IAExC,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;CAC3C;AAED,oEAAoE;AACpE,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,GAC/B,oBAAoB,CAEtB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAClD,eAAe,EACf,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,CAAC,GAAG,SAAS,CAO9C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,oBAAoB,GAAG,YAAY,GACzC,KAAK,IAAI,oBAAoB,CAE/B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;IAEZ,8DAA8D;IAC9D,IAAI,EAAE,eAAe,CAAC;IAEtB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVENT_SOURCE_MAPPING_ID_READERS = void 0;
4
+ exports.composureEventSource = composureEventSource;
5
+ exports.isComposureEventSource = isComposureEventSource;
6
+ /** @internal — brands {@link ComposureEventSource} so the guard is unambiguous. */
7
+ const COMPOSURE_EVENT_SOURCE = Symbol.for("composurecdk.lambda.eventSource");
8
+ /** @internal — assembles a branded {@link ComposureEventSource}. */
9
+ function composureEventSource(kind, source) {
10
+ return { [COMPOSURE_EVENT_SOURCE]: true, kind, source };
11
+ }
12
+ /**
13
+ * Reads the event source mapping UUID off a bound CDK source, keyed by
14
+ * {@link EventSourceKind}. Defined only for kinds whose per-mapping ESM
15
+ * metrics back contextual alarms (currently SQS); `FunctionBuilder` invokes
16
+ * the reader after `addEventSource` so the binding exists. Keying off `kind`
17
+ * — like {@link EVENT_SOURCE_ALARM_SPECS} — keeps the builder from
18
+ * `instanceof`-ing CDK source classes.
19
+ *
20
+ * @internal
21
+ */
22
+ exports.EVENT_SOURCE_MAPPING_ID_READERS = {
23
+ // Safe: the `"sqs"` kind is only ever assigned by `sqsEventSource()`, which
24
+ // constructs the `SqsEventSource` in the same call — kind and concrete class
25
+ // move in lockstep.
26
+ sqs: (bound) => bound.eventSourceMappingId,
27
+ unknown: undefined,
28
+ };
29
+ /**
30
+ * Type guard distinguishing a {@link ComposureEventSource} from a bare
31
+ * {@link IEventSource} escape-hatch value.
32
+ */
33
+ function isComposureEventSource(value) {
34
+ return COMPOSURE_EVENT_SOURCE in value;
35
+ }
36
+ //# sourceMappingURL=composure-event-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composure-event-source.js","sourceRoot":"","sources":["../../../src/event-sources/composure-event-source.ts"],"names":[],"mappings":";;;AA6CA,oDAKC;AA2BD,wDAIC;AAlED,mFAAmF;AACnF,MAAM,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AA4B7E,oEAAoE;AACpE,SAAgB,oBAAoB,CAClC,IAAqB,EACrB,MAAgC;IAEhC,OAAO,EAAE,CAAC,sBAAsB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACU,QAAA,+BAA+B,GAGxC;IACF,4EAA4E;IAC5E,6EAA6E;IAC7E,oBAAoB;IACpB,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAE,KAAwB,CAAC,oBAAoB;IAC9D,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF;;;GAGG;AACH,SAAgB,sBAAsB,CACpC,KAA0C;IAE1C,OAAO,sBAAsB,IAAI,KAAK,CAAC;AACzC,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { type SqsEventSourceProps } from "aws-cdk-lib/aws-lambda-event-sources";
2
+ import type { IQueue } from "aws-cdk-lib/aws-sqs";
3
+ import { type Resolvable } from "@composurecdk/core";
4
+ import { type ComposureEventSource } from "./composure-event-source.js";
5
+ /**
6
+ * Secure, AWS-recommended defaults applied to every SQS event source built
7
+ * with {@link sqsEventSource}. Each property can be overridden via the
8
+ * factory's `props` argument.
9
+ */
10
+ export declare const DEFAULT_SQS_EVENT_SOURCE_PROPS: Pick<SqsEventSourceProps, "reportBatchItemFailures" | "metricsConfig">;
11
+ /**
12
+ * Wraps an SQS queue as a Lambda {@link IEventSource}, deferring resolution
13
+ * when the queue is a `ref()` to a sibling component's output.
14
+ *
15
+ * Follows the `events/targets` factory shape: register the result with
16
+ * {@link IFunctionBuilder.addEventSource} and the builder resolves the
17
+ * `ref()`, attaches the source, and (because `addEventSource` calls
18
+ * `source.bind(fn)`) grants the function's least-privilege execution role
19
+ * permission to consume the queue.
20
+ *
21
+ * Applies {@link DEFAULT_SQS_EVENT_SOURCE_PROPS}; pass `props` to override.
22
+ *
23
+ * ## Cross-component invariants (not enforced)
24
+ *
25
+ * AWS Well-Architected guidance spans the queue and the function:
26
+ * - the source queue's visibility timeout should be ≥ 6× the function
27
+ * timeout, leaving room for Lambda to retry a throttled batch;
28
+ * - the source queue's redrive `maxReceiveCount` should be ≥ 5 before the DLQ.
29
+ *
30
+ * These are not validated here — the queue often arrives as a `ref()` that is
31
+ * not resolvable at configuration time. Tracked in laazyj/composureCDK#123
32
+ * and #124.
33
+ *
34
+ * @param queue - The source queue, concrete or a `ref()` to a sibling.
35
+ * @param props - Overrides for {@link DEFAULT_SQS_EVENT_SOURCE_PROPS} and any
36
+ * other {@link SqsEventSourceProps}.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * compose(
41
+ * {
42
+ * orders: createQueueBuilder().queueName("orders"),
43
+ * processor: createFunctionBuilder()
44
+ * .runtime(Runtime.NODEJS_22_X)
45
+ * .handler("index.handler")
46
+ * .code(Code.fromAsset("lambda"))
47
+ * .addEventSource("orders", sqsEventSource(ref("orders", (r) => r.queue))),
48
+ * },
49
+ * { orders: [], processor: ["orders"] },
50
+ * );
51
+ * ```
52
+ */
53
+ export declare function sqsEventSource(queue: Resolvable<IQueue>, props?: SqsEventSourceProps): ComposureEventSource;
54
+ //# sourceMappingURL=sqs-event-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqs-event-source.d.ts","sourceRoot":"","sources":["../../../src/event-sources/sqs-event-source.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAChG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,KAAK,oBAAoB,EAAwB,MAAM,6BAA6B,CAAC;AAE9F;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,EAAE,IAAI,CAC/C,mBAAmB,EACnB,yBAAyB,GAAG,eAAe,CAkB5C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EACzB,KAAK,CAAC,EAAE,mBAAmB,GAC1B,oBAAoB,CAMtB"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SQS_EVENT_SOURCE_PROPS = void 0;
4
+ exports.sqsEventSource = sqsEventSource;
5
+ const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
6
+ const aws_lambda_event_sources_1 = require("aws-cdk-lib/aws-lambda-event-sources");
7
+ const core_1 = require("@composurecdk/core");
8
+ const composure_event_source_js_1 = require("./composure-event-source.js");
9
+ /**
10
+ * Secure, AWS-recommended defaults applied to every SQS event source built
11
+ * with {@link sqsEventSource}. Each property can be overridden via the
12
+ * factory's `props` argument.
13
+ */
14
+ exports.DEFAULT_SQS_EVENT_SOURCE_PROPS = {
15
+ /**
16
+ * Report partial batch failures so a single poison message does not fail
17
+ * the whole batch and force redelivery of already-processed records. CDK
18
+ * defaults this to `false`.
19
+ * @see https://aws.amazon.com/blogs/compute/implementing-aws-well-architected-best-practices-for-amazon-sqs-part-3/
20
+ * @see https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting
21
+ */
22
+ reportBatchItemFailures: true,
23
+ /**
24
+ * Enable the per-mapping `EventCount` ESM metrics (`FailedInvokeEventCount`,
25
+ * `DroppedEventCount`, …). They emit only when opted in, and the
26
+ * event-source contextual alarms on {@link IFunctionBuilder} depend on them.
27
+ * @see https://aws.amazon.com/blogs/compute/introducing-new-event-source-mapping-esm-metrics-for-aws-lambda/
28
+ */
29
+ metricsConfig: { metrics: [aws_lambda_1.MetricType.EVENT_COUNT] },
30
+ };
31
+ /**
32
+ * Wraps an SQS queue as a Lambda {@link IEventSource}, deferring resolution
33
+ * when the queue is a `ref()` to a sibling component's output.
34
+ *
35
+ * Follows the `events/targets` factory shape: register the result with
36
+ * {@link IFunctionBuilder.addEventSource} and the builder resolves the
37
+ * `ref()`, attaches the source, and (because `addEventSource` calls
38
+ * `source.bind(fn)`) grants the function's least-privilege execution role
39
+ * permission to consume the queue.
40
+ *
41
+ * Applies {@link DEFAULT_SQS_EVENT_SOURCE_PROPS}; pass `props` to override.
42
+ *
43
+ * ## Cross-component invariants (not enforced)
44
+ *
45
+ * AWS Well-Architected guidance spans the queue and the function:
46
+ * - the source queue's visibility timeout should be ≥ 6× the function
47
+ * timeout, leaving room for Lambda to retry a throttled batch;
48
+ * - the source queue's redrive `maxReceiveCount` should be ≥ 5 before the DLQ.
49
+ *
50
+ * These are not validated here — the queue often arrives as a `ref()` that is
51
+ * not resolvable at configuration time. Tracked in laazyj/composureCDK#123
52
+ * and #124.
53
+ *
54
+ * @param queue - The source queue, concrete or a `ref()` to a sibling.
55
+ * @param props - Overrides for {@link DEFAULT_SQS_EVENT_SOURCE_PROPS} and any
56
+ * other {@link SqsEventSourceProps}.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * compose(
61
+ * {
62
+ * orders: createQueueBuilder().queueName("orders"),
63
+ * processor: createFunctionBuilder()
64
+ * .runtime(Runtime.NODEJS_22_X)
65
+ * .handler("index.handler")
66
+ * .code(Code.fromAsset("lambda"))
67
+ * .addEventSource("orders", sqsEventSource(ref("orders", (r) => r.queue))),
68
+ * },
69
+ * { orders: [], processor: ["orders"] },
70
+ * );
71
+ * ```
72
+ */
73
+ function sqsEventSource(queue, props) {
74
+ const merged = { ...exports.DEFAULT_SQS_EVENT_SOURCE_PROPS, ...props };
75
+ const source = (0, core_1.isRef)(queue)
76
+ ? queue.map((resolved) => new aws_lambda_event_sources_1.SqsEventSource(resolved, merged))
77
+ : new aws_lambda_event_sources_1.SqsEventSource(queue, merged);
78
+ return (0, composure_event_source_js_1.composureEventSource)("sqs", source);
79
+ }
80
+ //# sourceMappingURL=sqs-event-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqs-event-source.js","sourceRoot":"","sources":["../../../src/event-sources/sqs-event-source.ts"],"names":[],"mappings":";;;AA4EA,wCASC;AApFD,uDAAoD;AACpD,mFAAgG;AAEhG,6CAA4D;AAC5D,2EAA8F;AAE9F;;;;GAIG;AACU,QAAA,8BAA8B,GAGvC;IACF;;;;;;OAMG;IACH,uBAAuB,EAAE,IAAI;IAE7B;;;;;OAKG;IACH,aAAa,EAAE,EAAE,OAAO,EAAE,CAAC,uBAAU,CAAC,WAAW,CAAC,EAAE;CACrD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,SAAgB,cAAc,CAC5B,KAAyB,EACzB,KAA2B;IAE3B,MAAM,MAAM,GAAwB,EAAE,GAAG,sCAA8B,EAAE,GAAG,KAAK,EAAE,CAAC;IACpF,MAAM,MAAM,GAA6B,IAAA,YAAK,EAAC,KAAK,CAAC;QACnD,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,yCAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC/D,CAAC,CAAC,IAAI,yCAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACtC,OAAO,IAAA,gDAAoB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC"}
@@ -4,12 +4,13 @@ import type { IConstruct } from "constructs";
4
4
  import type { AlarmDefinition } from "@composurecdk/cloudwatch";
5
5
  import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
6
6
  import type { FunctionAlarmConfig } from "./alarm-config.js";
7
+ import type { AttachedEventSource } from "./event-sources/composure-event-source.js";
7
8
  /**
8
9
  * Resolves the recommended alarm configuration into fully-resolved
9
10
  * {@link AlarmDefinition}s, applying contextual logic for timeout-based
10
11
  * duration and reserved-concurrency-based concurrent execution alarms.
11
12
  */
12
- export declare function resolveFunctionAlarmDefinitions(fn: LambdaFunction, config: FunctionAlarmConfig | undefined, props: Pick<FunctionProps, "timeout" | "reservedConcurrentExecutions">): AlarmDefinition[];
13
+ export declare function resolveFunctionAlarmDefinitions(fn: LambdaFunction, config: FunctionAlarmConfig | undefined, props: Pick<FunctionProps, "timeout" | "reservedConcurrentExecutions">, eventSources?: AttachedEventSource[]): AlarmDefinition[];
13
14
  /**
14
15
  * Creates AWS-recommended CloudWatch alarms for a Lambda function,
15
16
  * merging recommended definitions with any custom alarm builders.
@@ -19,10 +20,12 @@ export declare function resolveFunctionAlarmDefinitions(fn: LambdaFunction, conf
19
20
  * @param fn - The Lambda function to create alarms for.
20
21
  * @param config - User-provided alarm configuration, or `false` to disable all.
21
22
  * @param props - The merged function props, used for contextual alarm thresholds.
23
+ * @param eventSources - Event sources attached to the function, used for
24
+ * per-event-source contextual alarms.
22
25
  * @param customAlarms - Custom alarm builders added via `addAlarm()`.
23
26
  * @returns A record mapping alarm keys to their created Alarm constructs.
24
27
  *
25
28
  * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#Lambda
26
29
  */
27
- export declare function createFunctionAlarms(scope: IConstruct, id: string, fn: LambdaFunction, config: FunctionAlarmConfig | false | undefined, props: Pick<FunctionProps, "timeout" | "reservedConcurrentExecutions">, customAlarms?: AlarmDefinitionBuilder<LambdaFunction>[]): Record<string, Alarm>;
30
+ export declare function createFunctionAlarms(scope: IConstruct, id: string, fn: LambdaFunction, config: FunctionAlarmConfig | false | undefined, props: Pick<FunctionProps, "timeout" | "reservedConcurrentExecutions">, eventSources?: AttachedEventSource[], customAlarms?: AlarmDefinitionBuilder<LambdaFunction>[]): Record<string, Alarm>;
28
31
  //# sourceMappingURL=function-alarms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-alarms.d.ts","sourceRoot":"","sources":["../../src/function-alarms.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,KAAK,EAKX,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAa,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAoC,MAAM,0BAA0B,CAAC;AACpG,OAAO,KAAK,EACV,mBAAmB,EAGpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AA2CrF;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,EAAE,EAAE,cAAc,EAClB,MAAM,EAAE,mBAAmB,GAAG,SAAS,EACvC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,8BAA8B,CAAC,EACtE,YAAY,GAAE,mBAAmB,EAAO,GACvC,eAAe,EAAE,CAqGnB;AAiBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,cAAc,EAClB,MAAM,EAAE,mBAAmB,GAAG,KAAK,GAAG,SAAS,EAC/C,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,8BAA8B,CAAC,EACtE,YAAY,GAAE,mBAAmB,EAAO,EACxC,YAAY,GAAE,sBAAsB,CAAC,cAAc,CAAC,EAAO,GAC1D,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAUvB"}