@composurecdk/sqs 0.7.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.
- package/README.md +131 -0
- package/dist/defaults.d.ts +8 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +35 -0
- package/dist/defaults.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/queue-alarm-config.d.ts +46 -0
- package/dist/queue-alarm-config.d.ts.map +1 -0
- package/dist/queue-alarm-config.js +2 -0
- package/dist/queue-alarm-config.js.map +1 -0
- package/dist/queue-alarm-defaults.d.ts +18 -0
- package/dist/queue-alarm-defaults.d.ts.map +1 -0
- package/dist/queue-alarm-defaults.js +37 -0
- package/dist/queue-alarm-defaults.js.map +1 -0
- package/dist/queue-alarms.d.ts +26 -0
- package/dist/queue-alarms.d.ts.map +1 -0
- package/dist/queue-alarms.js +71 -0
- package/dist/queue-alarms.js.map +1 -0
- package/dist/queue-builder.d.ts +111 -0
- package/dist/queue-builder.d.ts.map +1 -0
- package/dist/queue-builder.js +57 -0
- package/dist/queue-builder.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @composurecdk/sqs
|
|
2
|
+
|
|
3
|
+
SQS queue builder for [ComposureCDK](../../README.md).
|
|
4
|
+
|
|
5
|
+
This package provides a fluent builder for SQS queues with secure, AWS-recommended defaults and built-in CloudWatch alarms. It wraps the CDK [Queue](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs.Queue.html) construct — refer to the CDK documentation for the full set of configurable properties.
|
|
6
|
+
|
|
7
|
+
## Queue Builder
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Duration } from "aws-cdk-lib";
|
|
11
|
+
import { createQueueBuilder } from "@composurecdk/sqs";
|
|
12
|
+
|
|
13
|
+
const orders = createQueueBuilder()
|
|
14
|
+
.queueName("orders")
|
|
15
|
+
.visibilityTimeout(Duration.seconds(60))
|
|
16
|
+
.build(stack, "Orders");
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Every [QueueProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs.QueueProps.html) property is available as a fluent setter on the builder. FIFO queues are supported via the standard `fifo`, `contentBasedDeduplication`, and `fifoThroughputLimit` props — no FIFO-specific defaults are applied.
|
|
20
|
+
|
|
21
|
+
## Secure Defaults
|
|
22
|
+
|
|
23
|
+
`createQueueBuilder` applies the following defaults. Each can be overridden via the builder's fluent API.
|
|
24
|
+
|
|
25
|
+
| Property | Default | Rationale |
|
|
26
|
+
| ------------------------ | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| `enforceSSL` | `true` | Denies any request that doesn't use TLS (resource policy `Deny` on `aws:SecureTransport: false`). Mirrors the SNS topic default. ([SNS/SQS security best practices](https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/sqs-security-best-practices.html)) |
|
|
28
|
+
| `encryption` | `QueueEncryption.SQS_MANAGED` | Encrypts at rest with the SQS-managed key (SSE-SQS). KMS encryption is opt-in via `.encryption(QueueEncryption.KMS)` + `.encryptionMasterKey(key)`. ([SQS data protection](https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/sqs-data-protection.html)) |
|
|
29
|
+
| `receiveMessageWaitTime` | `Duration.seconds(20)` | Enables [long polling](https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/sqs-short-and-long-polling.html#sqs-long-polling) — fewer empty receives, lower cost, lower latency. 20s is the SQS maximum. |
|
|
30
|
+
|
|
31
|
+
`visibilityTimeout` is intentionally not defaulted — it must match the longest consumer processing time, which is workload-specific. `retentionPeriod` is also left at CDK's default of 4 days; bump it to 14 days if you need a longer replay window.
|
|
32
|
+
|
|
33
|
+
The defaults are exported as `QUEUE_DEFAULTS` for visibility and testing:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { QUEUE_DEFAULTS } from "@composurecdk/sqs";
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Overriding defaults
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const queue = createQueueBuilder()
|
|
43
|
+
.queueName("my-queue")
|
|
44
|
+
.enforceSSL(false)
|
|
45
|
+
.receiveMessageWaitTime(Duration.seconds(0))
|
|
46
|
+
.build(stack, "MyQueue");
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Recommended Alarms
|
|
50
|
+
|
|
51
|
+
The builder creates [AWS-recommended CloudWatch alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS) by default. No alarm actions are configured — access alarms from the build result to add SNS topics or other actions.
|
|
52
|
+
|
|
53
|
+
| Alarm | Metric | Default threshold | Rationale |
|
|
54
|
+
| --------------------------------------- | ---------------------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| `approximateAgeOfOldestMessage` | `ApproximateAgeOfOldestMessage` (Max, 1 min) | > 300s (5 min) | Primary "consumer falling behind" signal. Conservative starting point — tune to your SLA and `retentionPeriod`. |
|
|
56
|
+
| `approximateNumberOfMessagesNotVisible` | `ApproximateNumberOfMessagesNotVisible` (Max, 1 min) | > 90,000 | 75% of the [120k in-flight messages](https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/quotas-messages.html#quotas-in-flight) per-queue quota. Proactive guardrail before receives are rejected. |
|
|
57
|
+
|
|
58
|
+
These defaults target primary queues; dead-letter queues need different thresholds (any message on a DLQ is itself an alert).
|
|
59
|
+
|
|
60
|
+
The third AWS-recommended SQS alarm, `ApproximateNumberOfMessagesVisible`, is not enabled by default — its useful threshold depends entirely on the application's processing capacity, and any generic value would be either noise or silence. Use `addAlarm` (see [Custom alarms](#custom-alarms)) to add it for workloads where you know the right threshold.
|
|
61
|
+
|
|
62
|
+
The defaults are exported as `QUEUE_ALARM_DEFAULTS` for visibility and testing:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { QUEUE_ALARM_DEFAULTS } from "@composurecdk/sqs";
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Customizing thresholds
|
|
69
|
+
|
|
70
|
+
Override individual alarm properties via `recommendedAlarms`. Unspecified fields keep their defaults.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const queue = createQueueBuilder()
|
|
74
|
+
.queueName("orders")
|
|
75
|
+
.recommendedAlarms({
|
|
76
|
+
approximateAgeOfOldestMessage: { threshold: 60, evaluationPeriods: 3 },
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Disabling alarms
|
|
81
|
+
|
|
82
|
+
Disable all recommended alarms:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
builder.recommendedAlarms(false);
|
|
86
|
+
// or
|
|
87
|
+
builder.recommendedAlarms({ enabled: false });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Disable individual alarms:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
builder.recommendedAlarms({ approximateNumberOfMessagesNotVisible: false });
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Custom alarms
|
|
97
|
+
|
|
98
|
+
Add custom alarms alongside the recommended ones via `addAlarm`. The callback receives an `AlarmDefinitionBuilder` typed to `IQueue`, so the metric factory has access to the queue's properties.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { Duration } from "aws-cdk-lib";
|
|
102
|
+
|
|
103
|
+
const queue = createQueueBuilder()
|
|
104
|
+
.queueName("orders")
|
|
105
|
+
.addAlarm("highEmptyReceiveRate", (alarm) =>
|
|
106
|
+
alarm
|
|
107
|
+
.metric((queue) => queue.metricNumberOfEmptyReceives({ period: Duration.minutes(1) }))
|
|
108
|
+
.threshold(1000)
|
|
109
|
+
.greaterThan()
|
|
110
|
+
.description("Queue receiving an unusually high number of empty receives."),
|
|
111
|
+
);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Applying alarm actions
|
|
115
|
+
|
|
116
|
+
Alarms are returned in the build result as `Record<string, Alarm>`:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
const result = createQueueBuilder().queueName("orders").build(stack, "Orders");
|
|
120
|
+
|
|
121
|
+
const alertTopic = new Topic(stack, "AlertTopic");
|
|
122
|
+
for (const alarm of Object.values(result.alarms)) {
|
|
123
|
+
alarm.addAlarmAction(new SnsAction(alertTopic));
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
For composing the alarm-actions wiring across multiple builders in a single `compose` system, see [`alarmActionsPolicy`](../cloudwatch/README.md) in `@composurecdk/cloudwatch`.
|
|
128
|
+
|
|
129
|
+
## Examples
|
|
130
|
+
|
|
131
|
+
- [OrderProcessorStack](../examples/src/order-processor-app.ts) — Primary SQS queue with recommended alarms routed to a sibling SNS alert topic.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type QueueProps } from "aws-cdk-lib/aws-sqs";
|
|
2
|
+
/**
|
|
3
|
+
* Secure, AWS-recommended defaults applied to every SQS queue built
|
|
4
|
+
* with {@link createQueueBuilder}. Each property can be individually
|
|
5
|
+
* overridden via the builder's fluent API.
|
|
6
|
+
*/
|
|
7
|
+
export declare const QUEUE_DEFAULTS: Partial<QueueProps>;
|
|
8
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,UAAU,CA4B9C,CAAC"}
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Duration } from "aws-cdk-lib";
|
|
2
|
+
import { QueueEncryption } from "aws-cdk-lib/aws-sqs";
|
|
3
|
+
/**
|
|
4
|
+
* Secure, AWS-recommended defaults applied to every SQS queue built
|
|
5
|
+
* with {@link createQueueBuilder}. Each property can be individually
|
|
6
|
+
* overridden via the builder's fluent API.
|
|
7
|
+
*/
|
|
8
|
+
export const QUEUE_DEFAULTS = {
|
|
9
|
+
/**
|
|
10
|
+
* Reject any request that does not use TLS. Adds a resource policy
|
|
11
|
+
* `Deny` on `aws:SecureTransport: false`, the same control applied to
|
|
12
|
+
* SNS topics by {@link createTopicBuilder}.
|
|
13
|
+
* @see https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/sqs-security-best-practices.html
|
|
14
|
+
*/
|
|
15
|
+
enforceSSL: true,
|
|
16
|
+
/**
|
|
17
|
+
* Encrypt messages at rest with the SQS-managed key (SSE-SQS). This
|
|
18
|
+
* is the safe baseline; bring-your-own KMS encryption is opt-in via
|
|
19
|
+
* `.encryptionMasterKey(...)` paired with `.encryption(QueueEncryption.KMS)`.
|
|
20
|
+
* CDK already defaults newly-created queues to SSE-SQS — making it
|
|
21
|
+
* explicit here keeps the default discoverable and stable across CDK
|
|
22
|
+
* versions.
|
|
23
|
+
* @see https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/sqs-data-protection.html
|
|
24
|
+
*/
|
|
25
|
+
encryption: QueueEncryption.SQS_MANAGED,
|
|
26
|
+
/**
|
|
27
|
+
* Enable long polling. Holds `ReceiveMessage` connections open for up
|
|
28
|
+
* to 20 seconds while waiting for messages, which cuts both the cost
|
|
29
|
+
* of empty receives and the perceived delivery latency of low-traffic
|
|
30
|
+
* queues. The 20s value is the SQS maximum.
|
|
31
|
+
* @see https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/sqs-short-and-long-polling.html#sqs-long-polling
|
|
32
|
+
*/
|
|
33
|
+
receiveMessageWaitTime: Duration.seconds(20),
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAC;AAEvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwB;IACjD;;;;;OAKG;IACH,UAAU,EAAE,IAAI;IAEhB;;;;;;;;OAQG;IACH,UAAU,EAAE,eAAe,CAAC,WAAW;IAEvC;;;;;;OAMG;IACH,sBAAsB,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;CAC7C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createQueueBuilder, type IQueueBuilder, type QueueBuilderProps, type QueueBuilderResult, } from "./queue-builder.js";
|
|
2
|
+
export { QUEUE_DEFAULTS } from "./defaults.js";
|
|
3
|
+
export { type QueueAlarmConfig } from "./queue-alarm-config.js";
|
|
4
|
+
export { QUEUE_ALARM_DEFAULTS } from "./queue-alarm-defaults.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAInB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AlarmConfig } from "@composurecdk/cloudwatch";
|
|
2
|
+
/**
|
|
3
|
+
* Controls which recommended alarms are created for an SQS queue.
|
|
4
|
+
* All applicable alarms are enabled by default with AWS-recommended thresholds.
|
|
5
|
+
* Set individual alarms to `false` to disable them, or provide an
|
|
6
|
+
* {@link AlarmConfig} to tune thresholds.
|
|
7
|
+
*
|
|
8
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
9
|
+
*/
|
|
10
|
+
export interface QueueAlarmConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Master switch: set to `false` to disable all recommended alarms.
|
|
13
|
+
* Individual alarms can also be disabled via their own entry.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Alarm when the oldest unprocessed message in the queue has been
|
|
19
|
+
* waiting longer than the configured threshold. Primary signal that
|
|
20
|
+
* consumers are falling behind.
|
|
21
|
+
*
|
|
22
|
+
* Metric: `AWS/SQS ApproximateAgeOfOldestMessage`, statistic Maximum,
|
|
23
|
+
* period 1 minute.
|
|
24
|
+
* Default threshold: > 300 seconds (5 minutes).
|
|
25
|
+
*
|
|
26
|
+
* The default is conservative and should be tuned to the queue's
|
|
27
|
+
* SLA and `retentionPeriod`.
|
|
28
|
+
*
|
|
29
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
30
|
+
*/
|
|
31
|
+
approximateAgeOfOldestMessage?: AlarmConfig | false;
|
|
32
|
+
/**
|
|
33
|
+
* Alarm when the number of in-flight (received but not yet deleted)
|
|
34
|
+
* messages approaches the SQS quota of 120,000 per queue. A breach
|
|
35
|
+
* means new messages will start being rejected.
|
|
36
|
+
*
|
|
37
|
+
* Metric: `AWS/SQS ApproximateNumberOfMessagesNotVisible`, statistic
|
|
38
|
+
* Maximum, period 1 minute.
|
|
39
|
+
* Default threshold: > 90,000 (75% of the in-flight quota).
|
|
40
|
+
*
|
|
41
|
+
* @see https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/quotas-messages.html#quotas-in-flight
|
|
42
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
43
|
+
*/
|
|
44
|
+
approximateNumberOfMessagesNotVisible?: AlarmConfig | false;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=queue-alarm-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-alarm-config.d.ts","sourceRoot":"","sources":["../src/queue-alarm-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;;;;OAaG;IACH,6BAA6B,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEpD;;;;;;;;;;;OAWG;IACH,qCAAqC,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-alarm-config.js","sourceRoot":"","sources":["../src/queue-alarm-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AlarmConfigDefaults } from "@composurecdk/cloudwatch";
|
|
2
|
+
interface QueueAlarmDefaults {
|
|
3
|
+
enabled: true;
|
|
4
|
+
approximateAgeOfOldestMessage: AlarmConfigDefaults;
|
|
5
|
+
approximateNumberOfMessagesNotVisible: AlarmConfigDefaults;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* AWS-recommended default alarm configuration for SQS queues.
|
|
9
|
+
*
|
|
10
|
+
* Tuned for primary (consumer-fed) queues. Dead-letter queues need
|
|
11
|
+
* different thresholds — any message on a DLQ is itself an alert,
|
|
12
|
+
* whereas a primary queue with messages is normal.
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
15
|
+
*/
|
|
16
|
+
export declare const QUEUE_ALARM_DEFAULTS: QueueAlarmDefaults;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=queue-alarm-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-alarm-defaults.d.ts","sourceRoot":"","sources":["../src/queue-alarm-defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,UAAU,kBAAkB;IAC1B,OAAO,EAAE,IAAI,CAAC;IACd,6BAA6B,EAAE,mBAAmB,CAAC;IACnD,qCAAqC,EAAE,mBAAmB,CAAC;CAC5D;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,kBA2BlC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
/**
|
|
3
|
+
* AWS-recommended default alarm configuration for SQS queues.
|
|
4
|
+
*
|
|
5
|
+
* Tuned for primary (consumer-fed) queues. Dead-letter queues need
|
|
6
|
+
* different thresholds — any message on a DLQ is itself an alert,
|
|
7
|
+
* whereas a primary queue with messages is normal.
|
|
8
|
+
*
|
|
9
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
10
|
+
*/
|
|
11
|
+
export const QUEUE_ALARM_DEFAULTS = {
|
|
12
|
+
enabled: true,
|
|
13
|
+
/**
|
|
14
|
+
* 5 minutes. Conservative starting point for a "consumer falling
|
|
15
|
+
* behind" alarm. The right value depends on the workload's SLA and
|
|
16
|
+
* `retentionPeriod`; tune via `recommendedAlarms`.
|
|
17
|
+
*/
|
|
18
|
+
approximateAgeOfOldestMessage: {
|
|
19
|
+
threshold: 300,
|
|
20
|
+
evaluationPeriods: 1,
|
|
21
|
+
datapointsToAlarm: 1,
|
|
22
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* 90,000 — 75% of the SQS 120,000 in-flight message quota. Proactive
|
|
26
|
+
* guardrail; a breach means the queue is approaching the point where
|
|
27
|
+
* new messages will be rejected.
|
|
28
|
+
* @see https://docs.aws.amazon.com/AmazonSQS/latest/SQSDeveloperGuide/quotas-messages.html#quotas-in-flight
|
|
29
|
+
*/
|
|
30
|
+
approximateNumberOfMessagesNotVisible: {
|
|
31
|
+
threshold: 90_000,
|
|
32
|
+
evaluationPeriods: 1,
|
|
33
|
+
datapointsToAlarm: 1,
|
|
34
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=queue-alarm-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-alarm-defaults.js","sourceRoot":"","sources":["../src/queue-alarm-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAS9D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAuB;IACtD,OAAO,EAAE,IAAI;IAEb;;;;OAIG;IACH,6BAA6B,EAAE;QAC7B,SAAS,EAAE,GAAG;QACd,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,gBAAgB,CAAC,aAAa;KACjD;IAED;;;;;OAKG;IACH,qCAAqC,EAAE;QACrC,SAAS,EAAE,MAAM;QACjB,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,gBAAgB,CAAC,aAAa;KACjD;CACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Alarm } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
import type { IQueue } from "aws-cdk-lib/aws-sqs";
|
|
3
|
+
import type { IConstruct } from "constructs";
|
|
4
|
+
import type { AlarmDefinition } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
6
|
+
import type { QueueAlarmConfig } from "./queue-alarm-config.js";
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the recommended alarm configuration into fully-resolved
|
|
9
|
+
* {@link AlarmDefinition}s for an SQS queue.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveQueueAlarmDefinitions(queue: IQueue, config: QueueAlarmConfig | undefined): AlarmDefinition[];
|
|
12
|
+
/**
|
|
13
|
+
* Creates AWS-recommended CloudWatch alarms for an SQS queue, merging
|
|
14
|
+
* recommended definitions with any custom alarm builders.
|
|
15
|
+
*
|
|
16
|
+
* @param scope - CDK construct scope for creating alarm constructs.
|
|
17
|
+
* @param id - Base identifier for alarm construct ids.
|
|
18
|
+
* @param queue - The SQS queue to create alarms for.
|
|
19
|
+
* @param config - User-provided alarm configuration, or `false` to disable all.
|
|
20
|
+
* @param customAlarms - Custom alarm builders added via `addAlarm()`.
|
|
21
|
+
* @returns A record mapping alarm keys to their created Alarm constructs.
|
|
22
|
+
*
|
|
23
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
24
|
+
*/
|
|
25
|
+
export declare function createQueueAlarms(scope: IConstruct, id: string, queue: IQueue, config: QueueAlarmConfig | false | undefined, customAlarms?: AlarmDefinitionBuilder<IQueue>[]): Record<string, Alarm>;
|
|
26
|
+
//# sourceMappingURL=queue-alarms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-alarms.d.ts","sourceRoot":"","sources":["../src/queue-alarms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAsB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAoC,MAAM,0BAA0B,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAMhE;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,GAAG,SAAS,GACnC,eAAe,EAAE,CA+CnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,GAAG,KAAK,GAAG,SAAS,EAC5C,YAAY,GAAE,sBAAsB,CAAC,MAAM,CAAC,EAAO,GAClD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAUvB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Duration } from "aws-cdk-lib";
|
|
2
|
+
import { ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
|
|
3
|
+
import { createAlarms, resolveAlarmConfig } from "@composurecdk/cloudwatch";
|
|
4
|
+
import { QUEUE_ALARM_DEFAULTS } from "./queue-alarm-defaults.js";
|
|
5
|
+
const METRIC_PERIOD = Duration.minutes(1);
|
|
6
|
+
const METRIC_PERIOD_LABEL = `${String(METRIC_PERIOD.toMinutes())} minute`;
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the recommended alarm configuration into fully-resolved
|
|
9
|
+
* {@link AlarmDefinition}s for an SQS queue.
|
|
10
|
+
*/
|
|
11
|
+
export function resolveQueueAlarmDefinitions(queue, config) {
|
|
12
|
+
if (config?.enabled === false)
|
|
13
|
+
return [];
|
|
14
|
+
const definitions = [];
|
|
15
|
+
if (config?.approximateAgeOfOldestMessage !== false) {
|
|
16
|
+
const cfg = resolveAlarmConfig(config?.approximateAgeOfOldestMessage, QUEUE_ALARM_DEFAULTS.approximateAgeOfOldestMessage);
|
|
17
|
+
definitions.push({
|
|
18
|
+
key: "approximateAgeOfOldestMessage",
|
|
19
|
+
alarmName: cfg.alarmName,
|
|
20
|
+
metric: queue.metricApproximateAgeOfOldestMessage({ period: METRIC_PERIOD }),
|
|
21
|
+
threshold: cfg.threshold,
|
|
22
|
+
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
23
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
24
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
25
|
+
treatMissingData: cfg.treatMissingData,
|
|
26
|
+
description: `SQS queue's oldest message has been waiting longer than the threshold, ` +
|
|
27
|
+
`indicating consumers are falling behind. Threshold: > ${String(cfg.threshold)} seconds in ${METRIC_PERIOD_LABEL}.`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (config?.approximateNumberOfMessagesNotVisible !== false) {
|
|
31
|
+
const cfg = resolveAlarmConfig(config?.approximateNumberOfMessagesNotVisible, QUEUE_ALARM_DEFAULTS.approximateNumberOfMessagesNotVisible);
|
|
32
|
+
definitions.push({
|
|
33
|
+
key: "approximateNumberOfMessagesNotVisible",
|
|
34
|
+
alarmName: cfg.alarmName,
|
|
35
|
+
metric: queue.metricApproximateNumberOfMessagesNotVisible({ period: METRIC_PERIOD }),
|
|
36
|
+
threshold: cfg.threshold,
|
|
37
|
+
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
38
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
39
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
40
|
+
treatMissingData: cfg.treatMissingData,
|
|
41
|
+
description: `SQS queue's in-flight messages are approaching the 120,000 per-queue quota; ` +
|
|
42
|
+
`further receives will be rejected once the quota is hit. ` +
|
|
43
|
+
`Threshold: > ${String(cfg.threshold)} in-flight in ${METRIC_PERIOD_LABEL}.`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return definitions;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates AWS-recommended CloudWatch alarms for an SQS queue, merging
|
|
50
|
+
* recommended definitions with any custom alarm builders.
|
|
51
|
+
*
|
|
52
|
+
* @param scope - CDK construct scope for creating alarm constructs.
|
|
53
|
+
* @param id - Base identifier for alarm construct ids.
|
|
54
|
+
* @param queue - The SQS queue to create alarms for.
|
|
55
|
+
* @param config - User-provided alarm configuration, or `false` to disable all.
|
|
56
|
+
* @param customAlarms - Custom alarm builders added via `addAlarm()`.
|
|
57
|
+
* @returns A record mapping alarm keys to their created Alarm constructs.
|
|
58
|
+
*
|
|
59
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
60
|
+
*/
|
|
61
|
+
export function createQueueAlarms(scope, id, queue, config, customAlarms = []) {
|
|
62
|
+
if (config === false)
|
|
63
|
+
return {};
|
|
64
|
+
const enabled = config?.enabled ?? QUEUE_ALARM_DEFAULTS.enabled;
|
|
65
|
+
if (!enabled)
|
|
66
|
+
return {};
|
|
67
|
+
const recommended = resolveQueueAlarmDefinitions(queue, config);
|
|
68
|
+
const custom = customAlarms.map((b) => b.resolve(queue));
|
|
69
|
+
return createAlarms(scope, id, [...recommended, ...custom]);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=queue-alarms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-alarms.js","sourceRoot":"","sources":["../src/queue-alarms.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type Alarm } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
import { type IQueue, Queue, type QueueProps } from "aws-cdk-lib/aws-sqs";
|
|
3
|
+
import { type IConstruct } from "constructs";
|
|
4
|
+
import { COPY_STATE, type Lifecycle } from "@composurecdk/core";
|
|
5
|
+
import { type ITaggedBuilder } from "@composurecdk/cloudformation";
|
|
6
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
7
|
+
import type { QueueAlarmConfig } from "./queue-alarm-config.js";
|
|
8
|
+
/**
|
|
9
|
+
* Configuration properties for the SQS queue builder.
|
|
10
|
+
*
|
|
11
|
+
* Extends the CDK {@link QueueProps} with additional builder-specific options.
|
|
12
|
+
*/
|
|
13
|
+
export interface QueueBuilderProps extends QueueProps {
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for AWS-recommended CloudWatch alarms.
|
|
16
|
+
*
|
|
17
|
+
* By default, the builder creates recommended alarms with sensible
|
|
18
|
+
* thresholds for every applicable metric. Individual alarms can be
|
|
19
|
+
* customized or disabled. Set to `false` to disable all alarms.
|
|
20
|
+
*
|
|
21
|
+
* No alarm actions are configured by default since notification
|
|
22
|
+
* methods are user-specific. Access alarms from the build result
|
|
23
|
+
* or use an `afterBuild` hook to apply actions.
|
|
24
|
+
*
|
|
25
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
26
|
+
*/
|
|
27
|
+
recommendedAlarms?: QueueAlarmConfig | false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The build output of an {@link IQueueBuilder}. Contains the CDK constructs
|
|
31
|
+
* created during {@link Lifecycle.build}, keyed by role.
|
|
32
|
+
*/
|
|
33
|
+
export interface QueueBuilderResult {
|
|
34
|
+
/** The SQS queue construct created by the builder. */
|
|
35
|
+
queue: Queue;
|
|
36
|
+
/**
|
|
37
|
+
* CloudWatch alarms created for the queue, keyed by alarm name.
|
|
38
|
+
*
|
|
39
|
+
* Includes both AWS-recommended alarms and any custom alarms added
|
|
40
|
+
* via {@link IQueueBuilder.addAlarm}. Access individual alarms
|
|
41
|
+
* by key (e.g., `result.alarms.approximateAgeOfOldestMessage`).
|
|
42
|
+
*
|
|
43
|
+
* No alarm actions are configured — apply them via the result or an
|
|
44
|
+
* `afterBuild` hook.
|
|
45
|
+
*
|
|
46
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#SQS
|
|
47
|
+
*/
|
|
48
|
+
alarms: Record<string, Alarm>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A fluent builder for configuring and creating an AWS SQS queue.
|
|
52
|
+
*
|
|
53
|
+
* Each configuration property from the CDK {@link QueueProps} is exposed
|
|
54
|
+
* as an overloaded method: call with a value to set it (returns the builder
|
|
55
|
+
* for chaining), or call with no arguments to read the current value.
|
|
56
|
+
*
|
|
57
|
+
* The builder implements {@link Lifecycle}, so it can be used directly as a
|
|
58
|
+
* component in a {@link compose | composed system}. When built, it creates
|
|
59
|
+
* an SQS queue with the configured properties and returns a
|
|
60
|
+
* {@link QueueBuilderResult}.
|
|
61
|
+
*
|
|
62
|
+
* The builder also creates AWS-recommended CloudWatch alarms by default.
|
|
63
|
+
* Alarms can be customized or disabled via the `recommendedAlarms` property.
|
|
64
|
+
* Custom alarms can be added via the {@link addAlarm} method.
|
|
65
|
+
*
|
|
66
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs.Queue.html
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const orders = createQueueBuilder()
|
|
71
|
+
* .queueName("orders")
|
|
72
|
+
* .visibilityTimeout(Duration.seconds(60));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export type IQueueBuilder = ITaggedBuilder<QueueBuilderProps, QueueBuilder>;
|
|
76
|
+
declare class QueueBuilder implements Lifecycle<QueueBuilderResult> {
|
|
77
|
+
#private;
|
|
78
|
+
props: Partial<QueueBuilderProps>;
|
|
79
|
+
addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<IQueue>) => AlarmDefinitionBuilder<IQueue>): this;
|
|
80
|
+
/** @internal — see ADR-0005. */
|
|
81
|
+
[COPY_STATE](target: QueueBuilder): void;
|
|
82
|
+
build(scope: IConstruct, id: string): QueueBuilderResult;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new {@link IQueueBuilder} for configuring an AWS SQS queue.
|
|
86
|
+
*
|
|
87
|
+
* This is the entry point for defining an SQS queue component. The returned
|
|
88
|
+
* builder exposes every {@link QueueBuilderProps} property as a fluent setter/getter
|
|
89
|
+
* and implements {@link Lifecycle} for use with {@link compose}.
|
|
90
|
+
*
|
|
91
|
+
* @returns A fluent builder for an AWS SQS queue.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const orders = createQueueBuilder()
|
|
96
|
+
* .queueName("orders")
|
|
97
|
+
* .visibilityTimeout(Duration.seconds(60));
|
|
98
|
+
*
|
|
99
|
+
* // Use standalone:
|
|
100
|
+
* const result = orders.build(stack, "Orders");
|
|
101
|
+
*
|
|
102
|
+
* // Or compose into a system:
|
|
103
|
+
* const system = compose(
|
|
104
|
+
* { orders, alerts: createTopicBuilder() },
|
|
105
|
+
* { orders: [], alerts: [] },
|
|
106
|
+
* );
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function createQueueBuilder(): IQueueBuilder;
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=queue-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-builder.d.ts","sourceRoot":"","sources":["../src/queue-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIhE;;;;GAIG;AACH,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC;CAC9C;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,sDAAsD;IACtD,KAAK,EAAE,KAAK,CAAC;IAEb;;;;;;;;;;;OAWG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;AAE5E,cAAM,YAAa,YAAW,SAAS,CAAC,kBAAkB,CAAC;;IACzD,KAAK,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAM;IAGvC,QAAQ,CACN,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAC,MAAM,CAAC,GACnF,IAAI;IAKP,gCAAgC;IAChC,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAIxC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,kBAAkB;CAczD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,IAAI,aAAa,CAElD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Queue } from "aws-cdk-lib/aws-sqs";
|
|
2
|
+
import { COPY_STATE } from "@composurecdk/core";
|
|
3
|
+
import { taggedBuilder } from "@composurecdk/cloudformation";
|
|
4
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { createQueueAlarms } from "./queue-alarms.js";
|
|
6
|
+
import { QUEUE_DEFAULTS } from "./defaults.js";
|
|
7
|
+
class QueueBuilder {
|
|
8
|
+
props = {};
|
|
9
|
+
#customAlarms = [];
|
|
10
|
+
addAlarm(key, configure) {
|
|
11
|
+
this.#customAlarms.push(configure(new AlarmDefinitionBuilder(key)));
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
/** @internal — see ADR-0005. */
|
|
15
|
+
[COPY_STATE](target) {
|
|
16
|
+
target.#customAlarms.push(...this.#customAlarms);
|
|
17
|
+
}
|
|
18
|
+
build(scope, id) {
|
|
19
|
+
const { recommendedAlarms: alarmConfig, ...queueProps } = this.props;
|
|
20
|
+
const mergedProps = {
|
|
21
|
+
...QUEUE_DEFAULTS,
|
|
22
|
+
...queueProps,
|
|
23
|
+
};
|
|
24
|
+
const queue = new Queue(scope, id, mergedProps);
|
|
25
|
+
const alarms = createQueueAlarms(scope, id, queue, alarmConfig, this.#customAlarms);
|
|
26
|
+
return { queue, alarms };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new {@link IQueueBuilder} for configuring an AWS SQS queue.
|
|
31
|
+
*
|
|
32
|
+
* This is the entry point for defining an SQS queue component. The returned
|
|
33
|
+
* builder exposes every {@link QueueBuilderProps} property as a fluent setter/getter
|
|
34
|
+
* and implements {@link Lifecycle} for use with {@link compose}.
|
|
35
|
+
*
|
|
36
|
+
* @returns A fluent builder for an AWS SQS queue.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const orders = createQueueBuilder()
|
|
41
|
+
* .queueName("orders")
|
|
42
|
+
* .visibilityTimeout(Duration.seconds(60));
|
|
43
|
+
*
|
|
44
|
+
* // Use standalone:
|
|
45
|
+
* const result = orders.build(stack, "Orders");
|
|
46
|
+
*
|
|
47
|
+
* // Or compose into a system:
|
|
48
|
+
* const system = compose(
|
|
49
|
+
* { orders, alerts: createTopicBuilder() },
|
|
50
|
+
* { orders: [], alerts: [] },
|
|
51
|
+
* );
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function createQueueBuilder() {
|
|
55
|
+
return taggedBuilder(QueueBuilder);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=queue-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-builder.js","sourceRoot":"","sources":["../src/queue-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,EAAmB,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAuB,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA0E/C,MAAM,YAAY;IAChB,KAAK,GAA+B,EAAE,CAAC;IAC9B,aAAa,GAAqC,EAAE,CAAC;IAE9D,QAAQ,CACN,GAAW,EACX,SAAoF;QAEpF,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,sBAAsB,CAAS,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gCAAgC;IAChC,CAAC,UAAU,CAAC,CAAC,MAAoB;QAC/B,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,KAAiB,EAAE,EAAU;QACjC,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAErE,MAAM,WAAW,GAAG;YAClB,GAAG,cAAc;YACjB,GAAG,UAAU;SACO,CAAC;QAEvB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QAEhD,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAEpF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC3B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,aAAa,CAAkC,YAAY,CAAC,CAAC;AACtE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@composurecdk/sqs",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Composable SQS queue builder with well-architected defaults",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/laazyj/composureCDK",
|
|
8
|
+
"directory": "packages/sqs"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"build": "tsc -p tsconfig.build.json",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [],
|
|
31
|
+
"author": "Jason Duffett (https://github.com/laazyj)",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@composurecdk/cloudformation": "^0.7.0",
|
|
39
|
+
"@composurecdk/cloudwatch": "^0.7.0",
|
|
40
|
+
"@composurecdk/core": "^0.7.0",
|
|
41
|
+
"aws-cdk-lib": "^2.0.0",
|
|
42
|
+
"constructs": "^10.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^25.6.2",
|
|
46
|
+
"aws-cdk-lib": "^2.253.1",
|
|
47
|
+
"constructs": "^10.6.0",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"vitest": "^4.1.4"
|
|
50
|
+
}
|
|
51
|
+
}
|