@composurecdk/dynamodb 0.8.4
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 +186 -0
- package/dist/commonjs/defaults.d.ts +25 -0
- package/dist/commonjs/defaults.d.ts.map +1 -0
- package/dist/commonjs/defaults.js +138 -0
- package/dist/commonjs/defaults.js.map +1 -0
- package/dist/commonjs/index.d.ts +6 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +13 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/table-alarm-config.d.ts +58 -0
- package/dist/commonjs/table-alarm-config.d.ts.map +1 -0
- package/dist/commonjs/table-alarm-config.js +3 -0
- package/dist/commonjs/table-alarm-config.js.map +1 -0
- package/dist/commonjs/table-alarm-defaults.d.ts +21 -0
- package/dist/commonjs/table-alarm-defaults.d.ts.map +1 -0
- package/dist/commonjs/table-alarm-defaults.js +51 -0
- package/dist/commonjs/table-alarm-defaults.js.map +1 -0
- package/dist/commonjs/table-alarms.d.ts +26 -0
- package/dist/commonjs/table-alarms.d.ts.map +1 -0
- package/dist/commonjs/table-alarms.js +129 -0
- package/dist/commonjs/table-alarms.js.map +1 -0
- package/dist/commonjs/table-builder.d.ts +123 -0
- package/dist/commonjs/table-builder.d.ts.map +1 -0
- package/dist/commonjs/table-builder.js +86 -0
- package/dist/commonjs/table-builder.js.map +1 -0
- package/dist/commonjs/table-v2-builder.d.ts +129 -0
- package/dist/commonjs/table-v2-builder.d.ts.map +1 -0
- package/dist/commonjs/table-v2-builder.js +71 -0
- package/dist/commonjs/table-v2-builder.js.map +1 -0
- package/dist/esm/defaults.d.ts +25 -0
- package/dist/esm/defaults.d.ts.map +1 -0
- package/dist/esm/defaults.js +135 -0
- package/dist/esm/defaults.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/table-alarm-config.d.ts +58 -0
- package/dist/esm/table-alarm-config.d.ts.map +1 -0
- package/dist/esm/table-alarm-config.js +2 -0
- package/dist/esm/table-alarm-config.js.map +1 -0
- package/dist/esm/table-alarm-defaults.d.ts +21 -0
- package/dist/esm/table-alarm-defaults.d.ts.map +1 -0
- package/dist/esm/table-alarm-defaults.js +48 -0
- package/dist/esm/table-alarm-defaults.js.map +1 -0
- package/dist/esm/table-alarms.d.ts +26 -0
- package/dist/esm/table-alarms.d.ts.map +1 -0
- package/dist/esm/table-alarms.js +125 -0
- package/dist/esm/table-alarms.js.map +1 -0
- package/dist/esm/table-builder.d.ts +123 -0
- package/dist/esm/table-builder.d.ts.map +1 -0
- package/dist/esm/table-builder.js +83 -0
- package/dist/esm/table-builder.js.map +1 -0
- package/dist/esm/table-v2-builder.d.ts +129 -0
- package/dist/esm/table-v2-builder.d.ts.map +1 -0
- package/dist/esm/table-v2-builder.js +68 -0
- package/dist/esm/table-v2-builder.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Billing, BillingMode, TableEncryption, TableEncryptionV2, } from "aws-cdk-lib/aws-dynamodb";
|
|
2
|
+
/**
|
|
3
|
+
* Secure, AWS-recommended defaults applied to every DynamoDB table built
|
|
4
|
+
* with {@link createTableBuilder}. Each property can be individually
|
|
5
|
+
* overridden via the builder's fluent API.
|
|
6
|
+
*
|
|
7
|
+
* `partitionKey` is intentionally not defaulted — the key schema is the
|
|
8
|
+
* single most workload-specific decision for a table and there is no safe
|
|
9
|
+
* generic value. The builder requires it to be set before {@link Lifecycle.build}.
|
|
10
|
+
*/
|
|
11
|
+
export const TABLE_DEFAULTS = {
|
|
12
|
+
/**
|
|
13
|
+
* On-demand (pay-per-request) capacity. Removes the need to forecast and
|
|
14
|
+
* provision read/write capacity, scales instantly with traffic, and avoids
|
|
15
|
+
* throttling caused by under-provisioning — the safe default for variable
|
|
16
|
+
* or unknown workloads. Switch to {@link BillingMode.PROVISIONED} with
|
|
17
|
+
* `.readCapacity()` / `.writeCapacity()` for steady, predictable traffic
|
|
18
|
+
* where provisioned capacity is more cost-effective.
|
|
19
|
+
*
|
|
20
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/capacity.html
|
|
21
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html
|
|
22
|
+
*/
|
|
23
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
24
|
+
/**
|
|
25
|
+
* Encrypt at rest with an AWS-managed KMS key (`aws/dynamodb`) rather than
|
|
26
|
+
* the default AWS-owned key. The AWS-managed key is visible in the account's
|
|
27
|
+
* KMS console and its use is logged in CloudTrail, giving an auditable record
|
|
28
|
+
* of table encryption — what the Security Pillar asks for. Bring-your-own KMS
|
|
29
|
+
* is opt-in: set `.encryptionKey(key)` and the builder infers
|
|
30
|
+
* {@link TableEncryption.CUSTOMER_MANAGED}.
|
|
31
|
+
*
|
|
32
|
+
* Note: the AWS-managed key incurs KMS API request charges that the free,
|
|
33
|
+
* AWS-owned key does not. Override with `.encryption(TableEncryption.DEFAULT)`
|
|
34
|
+
* to fall back to the AWS-owned key.
|
|
35
|
+
*
|
|
36
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/protecting-data-at-rest.html
|
|
37
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/EncryptionAtRest.html
|
|
38
|
+
*/
|
|
39
|
+
encryption: TableEncryption.AWS_MANAGED,
|
|
40
|
+
/**
|
|
41
|
+
* Enable point-in-time recovery (continuous backups). Lets the table be
|
|
42
|
+
* restored to any second within the preceding 35 days, protecting against
|
|
43
|
+
* accidental writes, deletes, and application-level corruption. The Reliability
|
|
44
|
+
* Pillar treats automated, restorable backups as table stakes for stateful
|
|
45
|
+
* services.
|
|
46
|
+
*
|
|
47
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/rel_backing_up_data_identified_backups_data.html
|
|
48
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/PointInTimeRecovery.html
|
|
49
|
+
*/
|
|
50
|
+
pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: true },
|
|
51
|
+
/**
|
|
52
|
+
* Enable deletion protection so the table cannot be deleted by an API call,
|
|
53
|
+
* console action, or `cdk destroy` until protection is explicitly turned off.
|
|
54
|
+
* Guards production data against accidental teardown.
|
|
55
|
+
*
|
|
56
|
+
* This is intentionally heavier than CDK's default `RemovalPolicy.RETAIN`
|
|
57
|
+
* (which only orphans the table from the stack): deletion protection blocks
|
|
58
|
+
* the delete operation itself. Override with `.deletionProtection(false)` for
|
|
59
|
+
* ephemeral or test tables you expect to tear down.
|
|
60
|
+
*
|
|
61
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.Basics.html#WorkingWithTables.Basics.DeletionProtection
|
|
62
|
+
*/
|
|
63
|
+
deletionProtection: true,
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Secure, AWS-recommended defaults applied to every DynamoDB table built with
|
|
67
|
+
* {@link createTableV2Builder}. These encode the same well-architected intent
|
|
68
|
+
* as {@link TABLE_DEFAULTS} (on-demand billing, AWS-managed-KMS encryption,
|
|
69
|
+
* point-in-time recovery, deletion protection) against the `TableV2`
|
|
70
|
+
* (`AWS::DynamoDB::GlobalTable`) prop shape, where billing and encryption are
|
|
71
|
+
* single helper objects rather than flat props.
|
|
72
|
+
*
|
|
73
|
+
* As with {@link TABLE_DEFAULTS}, `partitionKey` is intentionally not defaulted
|
|
74
|
+
* — the key schema is the single most workload-specific decision for a table
|
|
75
|
+
* and there is no safe generic value.
|
|
76
|
+
*/
|
|
77
|
+
export const TABLE_V2_DEFAULTS = {
|
|
78
|
+
/**
|
|
79
|
+
* On-demand (pay-per-request) capacity. Removes the need to forecast and
|
|
80
|
+
* provision read/write capacity, scales instantly with traffic, and avoids
|
|
81
|
+
* throttling caused by under-provisioning — the safe default for variable or
|
|
82
|
+
* unknown workloads. Switch to {@link Billing.provisioned} with
|
|
83
|
+
* `MaxCapacity`/`Capacity.autoscaled(...)` for steady, predictable traffic
|
|
84
|
+
* where provisioned capacity is more cost-effective.
|
|
85
|
+
*
|
|
86
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/capacity.html
|
|
87
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html
|
|
88
|
+
*/
|
|
89
|
+
billing: Billing.onDemand(),
|
|
90
|
+
/**
|
|
91
|
+
* Encrypt at rest with an AWS-managed KMS key (`aws/dynamodb`) rather than the
|
|
92
|
+
* default AWS-owned key. The AWS-managed key is visible in the account's KMS
|
|
93
|
+
* console and its use is logged in CloudTrail, giving an auditable record of
|
|
94
|
+
* table encryption — what the Security Pillar asks for. Bring-your-own KMS is
|
|
95
|
+
* opt-in via `.encryption(TableEncryptionV2.customerManagedKey(key))`.
|
|
96
|
+
*
|
|
97
|
+
* Note: the AWS-managed key incurs KMS API request charges that the free,
|
|
98
|
+
* AWS-owned key does not. Override with
|
|
99
|
+
* `.encryption(TableEncryptionV2.dynamoOwnedKey())` to fall back to the
|
|
100
|
+
* AWS-owned key.
|
|
101
|
+
*
|
|
102
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/protecting-data-at-rest.html
|
|
103
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/EncryptionAtRest.html
|
|
104
|
+
*/
|
|
105
|
+
encryption: TableEncryptionV2.awsManagedKey(),
|
|
106
|
+
/**
|
|
107
|
+
* Enable point-in-time recovery (continuous backups). Lets the table be
|
|
108
|
+
* restored to any second within the preceding 35 days, protecting against
|
|
109
|
+
* accidental writes, deletes, and application-level corruption. The
|
|
110
|
+
* Reliability Pillar treats automated, restorable backups as table stakes for
|
|
111
|
+
* stateful services.
|
|
112
|
+
*
|
|
113
|
+
* Note: for `TableV2` (`AWS::DynamoDB::GlobalTable`) this setting is encoded
|
|
114
|
+
* per-replica (`Replicas[].PointInTimeRecoverySpecification`), not at the
|
|
115
|
+
* resource root — CDK applies it to each replica.
|
|
116
|
+
*
|
|
117
|
+
* @see https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/rel_backing_up_data_identified_backups_data.html
|
|
118
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/PointInTimeRecovery.html
|
|
119
|
+
*/
|
|
120
|
+
pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: true },
|
|
121
|
+
/**
|
|
122
|
+
* Enable deletion protection so the table cannot be deleted by an API call,
|
|
123
|
+
* console action, or `cdk destroy` until protection is explicitly turned off.
|
|
124
|
+
* Guards production data against accidental teardown. Override with
|
|
125
|
+
* `.deletionProtection(false)` for ephemeral or test tables.
|
|
126
|
+
*
|
|
127
|
+
* Note: for `TableV2` (`AWS::DynamoDB::GlobalTable`) this setting is encoded
|
|
128
|
+
* per-replica (`Replicas[].DeletionProtectionEnabled`), not at the resource
|
|
129
|
+
* root — CDK applies it to each replica.
|
|
130
|
+
*
|
|
131
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.Basics.html#WorkingWithTables.Basics.DeletionProtection
|
|
132
|
+
*/
|
|
133
|
+
deletionProtection: true,
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwB;IACjD;;;;;;;;;;OAUG;IACH,WAAW,EAAE,WAAW,CAAC,eAAe;IAExC;;;;;;;;;;;;;;OAcG;IACH,UAAU,EAAE,eAAe,CAAC,WAAW;IAEvC;;;;;;;;;OASG;IACH,gCAAgC,EAAE,EAAE,0BAA0B,EAAE,IAAI,EAAE;IAEtE;;;;;;;;;;;OAWG;IACH,kBAAkB,EAAE,IAAI;CACzB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA0B;IACtD;;;;;;;;;;OAUG;IACH,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;IAE3B;;;;;;;;;;;;;;OAcG;IACH,UAAU,EAAE,iBAAiB,CAAC,aAAa,EAAE;IAE7C;;;;;;;;;;;;;OAaG;IACH,gCAAgC,EAAE,EAAE,0BAA0B,EAAE,IAAI,EAAE;IAEtE;;;;;;;;;;;OAWG;IACH,kBAAkB,EAAE,IAAI;CACzB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createTableBuilder, type ITableBuilder, type TableBuilderProps, type TableBuilderResult, } from "./table-builder.js";
|
|
2
|
+
export { createTableV2Builder, type ITableV2Builder, type TableV2BuilderProps, type TableV2BuilderResult, } from "./table-v2-builder.js";
|
|
3
|
+
export { TABLE_DEFAULTS, TABLE_V2_DEFAULTS } from "./defaults.js";
|
|
4
|
+
export { type TableAlarmConfig } from "./table-alarm-config.js";
|
|
5
|
+
export { TABLE_ALARM_DEFAULTS } from "./table-alarm-defaults.js";
|
|
6
|
+
//# 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,EACL,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createTableBuilder, } from "./table-builder.js";
|
|
2
|
+
export { createTableV2Builder, } from "./table-v2-builder.js";
|
|
3
|
+
export { TABLE_DEFAULTS, TABLE_V2_DEFAULTS } from "./defaults.js";
|
|
4
|
+
export { TABLE_ALARM_DEFAULTS } from "./table-alarm-defaults.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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,EACL,oBAAoB,GAIrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { AlarmConfig } from "@composurecdk/cloudwatch";
|
|
2
|
+
/**
|
|
3
|
+
* Controls which recommended alarms are created for a DynamoDB table.
|
|
4
|
+
* All applicable alarms are enabled by default with AWS-recommended
|
|
5
|
+
* thresholds. Set individual alarms to `false` to disable them, or provide
|
|
6
|
+
* an {@link AlarmConfig} to tune thresholds.
|
|
7
|
+
*
|
|
8
|
+
* The defaults target a table-scoped view of availability and throttling.
|
|
9
|
+
* Account-level recommended alarms (e.g. `AccountProvisionedReadCapacityUtilization`)
|
|
10
|
+
* and provisioned-capacity utilization alarms are not created here — see the
|
|
11
|
+
* package README for the rationale.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
14
|
+
*/
|
|
15
|
+
export interface TableAlarmConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Master switch: set to `false` to disable all recommended alarms.
|
|
18
|
+
* Individual alarms can also be disabled via their own entry.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Alarm on server-side errors (HTTP 500) returned by the table. These are
|
|
24
|
+
* faults on the DynamoDB side rather than the caller's, so any sustained
|
|
25
|
+
* occurrence is worth surfacing. Summed across all operations.
|
|
26
|
+
*
|
|
27
|
+
* Metric: `AWS/DynamoDB SystemErrors` (summed per-operation via a math
|
|
28
|
+
* expression), statistic Sum, period 1 minute.
|
|
29
|
+
* Default threshold: > 0.
|
|
30
|
+
*
|
|
31
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
32
|
+
*/
|
|
33
|
+
systemErrors?: AlarmConfig | false;
|
|
34
|
+
/**
|
|
35
|
+
* Alarm when read requests are throttled. On an on-demand table sustained
|
|
36
|
+
* read throttling signals traffic ramping faster than DynamoDB's adaptive
|
|
37
|
+
* scaling can follow, or a hot partition; on a provisioned table it signals
|
|
38
|
+
* under-provisioned read capacity.
|
|
39
|
+
*
|
|
40
|
+
* Metric: `AWS/DynamoDB ReadThrottleEvents`, statistic Sum, period 1 minute.
|
|
41
|
+
* Default threshold: > 0.
|
|
42
|
+
*
|
|
43
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html
|
|
44
|
+
*/
|
|
45
|
+
readThrottleEvents?: AlarmConfig | false;
|
|
46
|
+
/**
|
|
47
|
+
* Alarm when write requests are throttled. As with read throttling, this
|
|
48
|
+
* indicates a hot partition or capacity that cannot keep up with the write
|
|
49
|
+
* rate.
|
|
50
|
+
*
|
|
51
|
+
* Metric: `AWS/DynamoDB WriteThrottleEvents`, statistic Sum, period 1 minute.
|
|
52
|
+
* Default threshold: > 0.
|
|
53
|
+
*
|
|
54
|
+
* @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html
|
|
55
|
+
*/
|
|
56
|
+
writeThrottleEvents?: AlarmConfig | false;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=table-alarm-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-alarm-config.d.ts","sourceRoot":"","sources":["../../src/table-alarm-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;OAUG;IACH,YAAY,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEnC;;;;;;;;;;OAUG;IACH,kBAAkB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;IAEzC;;;;;;;;;OASG;IACH,mBAAmB,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CAC3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-alarm-config.js","sourceRoot":"","sources":["../../src/table-alarm-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AlarmConfigDefaults } from "@composurecdk/cloudwatch";
|
|
2
|
+
interface TableAlarmDefaults {
|
|
3
|
+
enabled: true;
|
|
4
|
+
systemErrors: AlarmConfigDefaults;
|
|
5
|
+
readThrottleEvents: AlarmConfigDefaults;
|
|
6
|
+
writeThrottleEvents: AlarmConfigDefaults;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* AWS-recommended default alarm configuration for DynamoDB tables.
|
|
10
|
+
*
|
|
11
|
+
* Thresholds are deliberately strict (> 0) because the metrics they watch —
|
|
12
|
+
* server-side errors and throttling — should be at or near zero for a healthy
|
|
13
|
+
* table. Tune them up via `recommendedAlarms` for workloads where a low rate
|
|
14
|
+
* of throttling is expected and acceptable (e.g. cost-optimised provisioned
|
|
15
|
+
* tables that lean on burst capacity).
|
|
16
|
+
*
|
|
17
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
18
|
+
*/
|
|
19
|
+
export declare const TABLE_ALARM_DEFAULTS: TableAlarmDefaults;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=table-alarm-defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-alarm-defaults.d.ts","sourceRoot":"","sources":["../../src/table-alarm-defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,UAAU,kBAAkB;IAC1B,OAAO,EAAE,IAAI,CAAC;IACd,YAAY,EAAE,mBAAmB,CAAC;IAClC,kBAAkB,EAAE,mBAAmB,CAAC;IACxC,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,EAAE,kBAqClC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
|
|
2
|
+
/**
|
|
3
|
+
* AWS-recommended default alarm configuration for DynamoDB tables.
|
|
4
|
+
*
|
|
5
|
+
* Thresholds are deliberately strict (> 0) because the metrics they watch —
|
|
6
|
+
* server-side errors and throttling — should be at or near zero for a healthy
|
|
7
|
+
* table. Tune them up via `recommendedAlarms` for workloads where a low rate
|
|
8
|
+
* of throttling is expected and acceptable (e.g. cost-optimised provisioned
|
|
9
|
+
* tables that lean on burst capacity).
|
|
10
|
+
*
|
|
11
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
12
|
+
*/
|
|
13
|
+
export const TABLE_ALARM_DEFAULTS = {
|
|
14
|
+
enabled: true,
|
|
15
|
+
/**
|
|
16
|
+
* > 0 — any server-side (HTTP 500) error is an availability signal worth
|
|
17
|
+
* investigating. NOT_BREACHING for missing data: a table with no traffic
|
|
18
|
+
* emits no SystemErrors datapoints and should stay OK.
|
|
19
|
+
*/
|
|
20
|
+
systemErrors: {
|
|
21
|
+
threshold: 0,
|
|
22
|
+
evaluationPeriods: 1,
|
|
23
|
+
datapointsToAlarm: 1,
|
|
24
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* > 0 — surface read throttling immediately. Conservative starting point;
|
|
28
|
+
* raise the threshold or `evaluationPeriods` for workloads where brief,
|
|
29
|
+
* self-correcting throttling under burst is tolerable.
|
|
30
|
+
*/
|
|
31
|
+
readThrottleEvents: {
|
|
32
|
+
threshold: 0,
|
|
33
|
+
evaluationPeriods: 1,
|
|
34
|
+
datapointsToAlarm: 1,
|
|
35
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* > 0 — surface write throttling immediately, on the same basis as read
|
|
39
|
+
* throttling.
|
|
40
|
+
*/
|
|
41
|
+
writeThrottleEvents: {
|
|
42
|
+
threshold: 0,
|
|
43
|
+
evaluationPeriods: 1,
|
|
44
|
+
datapointsToAlarm: 1,
|
|
45
|
+
treatMissingData: TreatMissingData.NOT_BREACHING,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=table-alarm-defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-alarm-defaults.js","sourceRoot":"","sources":["../../src/table-alarm-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAU9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAuB;IACtD,OAAO,EAAE,IAAI;IAEb;;;;OAIG;IACH,YAAY,EAAE;QACZ,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,gBAAgB,CAAC,aAAa;KACjD;IAED;;;;OAIG;IACH,kBAAkB,EAAE;QAClB,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;QACpB,iBAAiB,EAAE,CAAC;QACpB,gBAAgB,EAAE,gBAAgB,CAAC,aAAa;KACjD;IAED;;;OAGG;IACH,mBAAmB,EAAE;QACnB,SAAS,EAAE,CAAC;QACZ,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 ITable } from "aws-cdk-lib/aws-dynamodb";
|
|
3
|
+
import type { IConstruct } from "constructs";
|
|
4
|
+
import type { AlarmDefinition } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { AlarmDefinitionBuilder } from "@composurecdk/cloudwatch";
|
|
6
|
+
import type { TableAlarmConfig } from "./table-alarm-config.js";
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the recommended alarm configuration into fully-resolved
|
|
9
|
+
* {@link AlarmDefinition}s for a DynamoDB table.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveTableAlarmDefinitions(table: ITable, config: TableAlarmConfig | undefined): AlarmDefinition[];
|
|
12
|
+
/**
|
|
13
|
+
* Creates AWS-recommended CloudWatch alarms for a DynamoDB table, 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 table - The DynamoDB table 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#DynamoDB
|
|
24
|
+
*/
|
|
25
|
+
export declare function createTableAlarms(scope: IConstruct, id: string, table: ITable, config: TableAlarmConfig | false | undefined, customAlarms?: AlarmDefinitionBuilder<ITable>[]): Record<string, Alarm>;
|
|
26
|
+
//# sourceMappingURL=table-alarms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-alarms.d.ts","sourceRoot":"","sources":["../../src/table-alarms.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,KAAK,EAKX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,0BAA0B,CAAC;AAClE,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;AAyChE;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,GAAG,SAAS,GACnC,eAAe,EAAE,CAqEnB;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,125 @@
|
|
|
1
|
+
import { Duration } from "aws-cdk-lib";
|
|
2
|
+
import { ComparisonOperator, Metric, Stats, } from "aws-cdk-lib/aws-cloudwatch";
|
|
3
|
+
import { Operation } from "aws-cdk-lib/aws-dynamodb";
|
|
4
|
+
import { createAlarms, resolveAlarmConfig } from "@composurecdk/cloudwatch";
|
|
5
|
+
import { TABLE_ALARM_DEFAULTS } from "./table-alarm-defaults.js";
|
|
6
|
+
const METRIC_PERIOD = Duration.minutes(1);
|
|
7
|
+
const METRIC_PERIOD_LABEL = `${String(METRIC_PERIOD.toMinutes())} minute`;
|
|
8
|
+
/**
|
|
9
|
+
* Operations the default `systemErrors` alarm sums over. A CloudWatch alarm on
|
|
10
|
+
* a metric-math expression may reference at most 10 individual metrics, and
|
|
11
|
+
* DynamoDB defines 14 operations — so the full-table aggregate cannot be
|
|
12
|
+
* alarmed directly. These ten are the core SDK data-plane operations (single
|
|
13
|
+
* item, query/scan, batch, and transactions); the PartiQL statement operations
|
|
14
|
+
* and the stream `GetRecords` operation are omitted. Override via a custom
|
|
15
|
+
* `addAlarm` if your workload's error profile lives in the excluded set.
|
|
16
|
+
*/
|
|
17
|
+
const SYSTEM_ERROR_OPERATIONS = [
|
|
18
|
+
Operation.GET_ITEM,
|
|
19
|
+
Operation.BATCH_GET_ITEM,
|
|
20
|
+
Operation.QUERY,
|
|
21
|
+
Operation.SCAN,
|
|
22
|
+
Operation.PUT_ITEM,
|
|
23
|
+
Operation.UPDATE_ITEM,
|
|
24
|
+
Operation.DELETE_ITEM,
|
|
25
|
+
Operation.BATCH_WRITE_ITEM,
|
|
26
|
+
Operation.TRANSACT_GET_ITEMS,
|
|
27
|
+
Operation.TRANSACT_WRITE_ITEMS,
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Builds a table-scoped `AWS/DynamoDB` metric with the `TableName` dimension.
|
|
31
|
+
*/
|
|
32
|
+
function tableMetric(table, metricName) {
|
|
33
|
+
return new Metric({
|
|
34
|
+
namespace: "AWS/DynamoDB",
|
|
35
|
+
metricName,
|
|
36
|
+
dimensionsMap: { TableName: table.tableName },
|
|
37
|
+
statistic: Stats.SUM,
|
|
38
|
+
period: METRIC_PERIOD,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the recommended alarm configuration into fully-resolved
|
|
43
|
+
* {@link AlarmDefinition}s for a DynamoDB table.
|
|
44
|
+
*/
|
|
45
|
+
export function resolveTableAlarmDefinitions(table, config) {
|
|
46
|
+
if (config?.enabled === false)
|
|
47
|
+
return [];
|
|
48
|
+
const definitions = [];
|
|
49
|
+
if (config?.systemErrors !== false) {
|
|
50
|
+
const cfg = resolveAlarmConfig(config?.systemErrors, TABLE_ALARM_DEFAULTS.systemErrors);
|
|
51
|
+
definitions.push({
|
|
52
|
+
key: "systemErrors",
|
|
53
|
+
alarmName: cfg.alarmName,
|
|
54
|
+
// metricSystemErrorsForOperations sums SystemErrors across the given
|
|
55
|
+
// operations into a single MathExpression — the per-operation dimension
|
|
56
|
+
// means there is no single plain Metric for "errors on this table".
|
|
57
|
+
metric: table.metricSystemErrorsForOperations({
|
|
58
|
+
period: METRIC_PERIOD,
|
|
59
|
+
operations: SYSTEM_ERROR_OPERATIONS,
|
|
60
|
+
}),
|
|
61
|
+
threshold: cfg.threshold,
|
|
62
|
+
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
63
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
64
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
65
|
+
treatMissingData: cfg.treatMissingData,
|
|
66
|
+
description: `DynamoDB table is returning server-side (HTTP 500) errors, summed across the core data-plane operations. ` +
|
|
67
|
+
`Threshold: > ${String(cfg.threshold)} in ${METRIC_PERIOD_LABEL}.`,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (config?.readThrottleEvents !== false) {
|
|
71
|
+
const cfg = resolveAlarmConfig(config?.readThrottleEvents, TABLE_ALARM_DEFAULTS.readThrottleEvents);
|
|
72
|
+
definitions.push({
|
|
73
|
+
key: "readThrottleEvents",
|
|
74
|
+
alarmName: cfg.alarmName,
|
|
75
|
+
metric: tableMetric(table, "ReadThrottleEvents"),
|
|
76
|
+
threshold: cfg.threshold,
|
|
77
|
+
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
78
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
79
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
80
|
+
treatMissingData: cfg.treatMissingData,
|
|
81
|
+
description: `DynamoDB table read requests are being throttled, indicating a hot partition or ` +
|
|
82
|
+
`insufficient read capacity. Threshold: > ${String(cfg.threshold)} in ${METRIC_PERIOD_LABEL}.`,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (config?.writeThrottleEvents !== false) {
|
|
86
|
+
const cfg = resolveAlarmConfig(config?.writeThrottleEvents, TABLE_ALARM_DEFAULTS.writeThrottleEvents);
|
|
87
|
+
definitions.push({
|
|
88
|
+
key: "writeThrottleEvents",
|
|
89
|
+
alarmName: cfg.alarmName,
|
|
90
|
+
metric: tableMetric(table, "WriteThrottleEvents"),
|
|
91
|
+
threshold: cfg.threshold,
|
|
92
|
+
comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
|
|
93
|
+
evaluationPeriods: cfg.evaluationPeriods,
|
|
94
|
+
datapointsToAlarm: cfg.datapointsToAlarm,
|
|
95
|
+
treatMissingData: cfg.treatMissingData,
|
|
96
|
+
description: `DynamoDB table write requests are being throttled, indicating a hot partition or ` +
|
|
97
|
+
`insufficient write capacity. Threshold: > ${String(cfg.threshold)} in ${METRIC_PERIOD_LABEL}.`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return definitions;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates AWS-recommended CloudWatch alarms for a DynamoDB table, merging
|
|
104
|
+
* recommended definitions with any custom alarm builders.
|
|
105
|
+
*
|
|
106
|
+
* @param scope - CDK construct scope for creating alarm constructs.
|
|
107
|
+
* @param id - Base identifier for alarm construct ids.
|
|
108
|
+
* @param table - The DynamoDB table to create alarms for.
|
|
109
|
+
* @param config - User-provided alarm configuration, or `false` to disable all.
|
|
110
|
+
* @param customAlarms - Custom alarm builders added via `addAlarm()`.
|
|
111
|
+
* @returns A record mapping alarm keys to their created Alarm constructs.
|
|
112
|
+
*
|
|
113
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
114
|
+
*/
|
|
115
|
+
export function createTableAlarms(scope, id, table, config, customAlarms = []) {
|
|
116
|
+
if (config === false)
|
|
117
|
+
return {};
|
|
118
|
+
const enabled = config?.enabled ?? TABLE_ALARM_DEFAULTS.enabled;
|
|
119
|
+
if (!enabled)
|
|
120
|
+
return {};
|
|
121
|
+
const recommended = resolveTableAlarmDefinitions(table, config);
|
|
122
|
+
const custom = customAlarms.map((b) => b.resolve(table));
|
|
123
|
+
return createAlarms(scope, id, [...recommended, ...custom]);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=table-alarms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-alarms.js","sourceRoot":"","sources":["../../src/table-alarms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAEL,kBAAkB,EAElB,MAAM,EACN,KAAK,GACN,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAe,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAA0B,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEpG,OAAO,EAAE,oBAAoB,EA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ib/aws-dynamodb";
|
|
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 { TableAlarmConfig } from "./table-alarm-config.js";
|
|
8
|
+
/**
|
|
9
|
+
* Configuration properties for the DynamoDB table builder.
|
|
10
|
+
*
|
|
11
|
+
* Extends the CDK {@link TableProps} with additional builder-specific options.
|
|
12
|
+
*/
|
|
13
|
+
export interface TableBuilderProps extends TableProps {
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for AWS-recommended CloudWatch alarms.
|
|
16
|
+
*
|
|
17
|
+
* By default, the builder creates recommended alarms with sensible
|
|
18
|
+
* thresholds for server-side errors and read/write throttling. Individual
|
|
19
|
+
* alarms can be customized or disabled. Set to `false` to disable all alarms.
|
|
20
|
+
*
|
|
21
|
+
* No alarm actions are configured by default since notification methods are
|
|
22
|
+
* user-specific. Access alarms from the build result or use an `afterBuild`
|
|
23
|
+
* hook to apply actions.
|
|
24
|
+
*
|
|
25
|
+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html#DynamoDB
|
|
26
|
+
*/
|
|
27
|
+
recommendedAlarms?: TableAlarmConfig | false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The build output of an {@link ITableBuilder}. Contains the CDK constructs
|
|
31
|
+
* created during {@link Lifecycle.build}, keyed by role.
|
|
32
|
+
*/
|
|
33
|
+
export interface TableBuilderResult {
|
|
34
|
+
/** The classic DynamoDB {@link Table} construct created by the builder. */
|
|
35
|
+
table: Table;
|
|
36
|
+
/**
|
|
37
|
+
* The table's DynamoDB Streams ARN, or `undefined` when no stream is
|
|
38
|
+
* configured. Surfaced directly so a downstream consumer (e.g. a Lambda
|
|
39
|
+
* `DynamoEventSource`) can be wired via `ref()`.
|
|
40
|
+
*/
|
|
41
|
+
tableStreamArn?: string;
|
|
42
|
+
/**
|
|
43
|
+
* CloudWatch alarms created for the table, keyed by alarm name — both the
|
|
44
|
+
* AWS-recommended alarms and any added via {@link ITableBuilder.addAlarm}.
|
|
45
|
+
* No alarm actions are configured.
|
|
46
|
+
*/
|
|
47
|
+
alarms: Record<string, Alarm>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A fluent builder for configuring and creating an AWS DynamoDB table.
|
|
51
|
+
*
|
|
52
|
+
* Wraps the classic {@link Table} construct (`AWS::DynamoDB::Table`). For new
|
|
53
|
+
* tables, prefer {@link createTableV2Builder} ({@link TableV2}) — AWS recommends
|
|
54
|
+
* it, and it lets you add cross-region replicas later without replacing the
|
|
55
|
+
* table. Reach for this classic builder when you need an `importSource` (S3 bulk
|
|
56
|
+
* import, V1-only) or parity with existing classic tables. Note the two are
|
|
57
|
+
* different CloudFormation resources and cannot be migrated in place.
|
|
58
|
+
*
|
|
59
|
+
* Each configuration property from the CDK {@link TableProps} is exposed as an
|
|
60
|
+
* overloaded method: call with a value to set it (returns the builder for
|
|
61
|
+
* chaining), or call with no arguments to read the current value.
|
|
62
|
+
*
|
|
63
|
+
* The builder implements {@link Lifecycle}, so it can be used directly as a
|
|
64
|
+
* component in a {@link compose | composed system}. When built, it creates a
|
|
65
|
+
* DynamoDB table with the configured properties — merged with secure,
|
|
66
|
+
* AWS-recommended {@link TABLE_DEFAULTS} — and returns a {@link TableBuilderResult}.
|
|
67
|
+
*
|
|
68
|
+
* The builder also creates AWS-recommended CloudWatch alarms by default. Alarms
|
|
69
|
+
* can be customized or disabled via the `recommendedAlarms` property. Custom
|
|
70
|
+
* alarms can be added via the {@link addAlarm} method.
|
|
71
|
+
*
|
|
72
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_dynamodb.Table.html
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { AttributeType, StreamViewType } from "aws-cdk-lib/aws-dynamodb";
|
|
77
|
+
*
|
|
78
|
+
* const orders = createTableBuilder()
|
|
79
|
+
* .partitionKey({ name: "pk", type: AttributeType.STRING })
|
|
80
|
+
* .sortKey({ name: "sk", type: AttributeType.STRING })
|
|
81
|
+
* .stream(StreamViewType.NEW_AND_OLD_IMAGES);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export type ITableBuilder = ITaggedBuilder<TableBuilderProps, TableBuilder>;
|
|
85
|
+
declare class TableBuilder implements Lifecycle<TableBuilderResult> {
|
|
86
|
+
#private;
|
|
87
|
+
props: Partial<TableBuilderProps>;
|
|
88
|
+
addAlarm(key: string, configure: (alarm: AlarmDefinitionBuilder<ITable>) => AlarmDefinitionBuilder<ITable>): this;
|
|
89
|
+
/** @internal — see ADR-0005. */
|
|
90
|
+
[COPY_STATE](target: TableBuilder): void;
|
|
91
|
+
build(scope: IConstruct, id: string): TableBuilderResult;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new {@link ITableBuilder} for configuring an AWS DynamoDB table.
|
|
95
|
+
*
|
|
96
|
+
* This is the entry point for defining a DynamoDB table component. The returned
|
|
97
|
+
* builder exposes every {@link TableBuilderProps} property as a fluent
|
|
98
|
+
* setter/getter and implements {@link Lifecycle} for use with {@link compose}.
|
|
99
|
+
*
|
|
100
|
+
* @returns A fluent builder for an AWS DynamoDB table.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { AttributeType } from "aws-cdk-lib/aws-dynamodb";
|
|
105
|
+
*
|
|
106
|
+
* const orders = createTableBuilder().partitionKey({
|
|
107
|
+
* name: "orderId",
|
|
108
|
+
* type: AttributeType.STRING,
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // Use standalone:
|
|
112
|
+
* const result = orders.build(stack, "Orders");
|
|
113
|
+
*
|
|
114
|
+
* // Or compose into a system, wiring the stream into a Lambda:
|
|
115
|
+
* const system = compose(
|
|
116
|
+
* { orders, processor: createFunctionBuilder() },
|
|
117
|
+
* { orders: [], processor: ["orders"] },
|
|
118
|
+
* );
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function createTableBuilder(): ITableBuilder;
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=table-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-builder.d.ts","sourceRoot":"","sources":["../../src/table-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAmB,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAChG,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,2EAA2E;IAC3E,KAAK,EAAE,KAAK,CAAC;IAEb;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,aAAa,GAAG,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