@aws/nx-plugin-mcp 1.0.0-rc.13 → 1.0.0-rc.14
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/bin/aws-nx-mcp.js +28 -1
- package/docs/guides/connection/py-agent-dynamodb.mdx +116 -0
- package/docs/guides/connection/py-fast-api-dynamodb.mdx +56 -0
- package/docs/guides/connection/py-mcp-server-dynamodb.mdx +116 -0
- package/docs/guides/connection/smithy-dynamodb.mdx +2 -2
- package/docs/guides/connection/trpc-dynamodb.mdx +2 -2
- package/docs/guides/connection/ts-agent-dynamodb.mdx +2 -2
- package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +2 -2
- package/docs/guides/connection.mdx +30 -4
- package/docs/guides/py-dynamodb.mdx +449 -0
- package/docs/guides/ts-dynamodb.mdx +21 -250
- package/docs/snippets/connection/py-dynamodb-local-development.mdx +7 -0
- package/docs/snippets/dynamodb/deploying-table.mdx +171 -0
- package/docs/snippets/dynamodb/gsi-config.mdx +38 -0
- package/docs/snippets/dynamodb/infrastructure.mdx +33 -0
- package/docs/snippets/dynamodb/serve-local-start.mdx +13 -0
- package/docs/snippets/dynamodb/serve-local-windows.mdx +15 -0
- package/generators.json +28 -1
- package/package.json +1 -1
- package/src/py/dynamodb/agent-connection/schema.json +22 -0
- package/src/py/dynamodb/fast-api-connection/schema.json +18 -0
- package/src/py/dynamodb/mcp-server-connection/schema.json +22 -0
- package/src/py/dynamodb/schema.json +70 -0
- package/src/ts/dynamodb/schema.json +20 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: DynamoDB
|
|
3
|
-
description: Create a DynamoDB project
|
|
2
|
+
title: TypeScript DynamoDB
|
|
3
|
+
description: Create a TypeScript DynamoDB project
|
|
4
4
|
generator: ts#dynamodb
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -8,15 +8,13 @@ import { FileTree } from '@astrojs/starlight/components';
|
|
|
8
8
|
import Link from '@components/link.astro';
|
|
9
9
|
import RunGenerator from '@components/run-generator.astro';
|
|
10
10
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
11
|
-
import Infrastructure from '@components/infrastructure.astro';
|
|
12
|
-
import NxCommands from '@components/nx-commands.astro';
|
|
13
11
|
import Snippet from '@components/snippet.astro';
|
|
14
12
|
|
|
15
|
-
This generator creates a new TypeScript project backed by [Amazon DynamoDB](https://aws.amazon.com/dynamodb/), using [ElectroDB](https://electrodb.dev/) for type-safe entity modelling. It generates the application code and infrastructure needed to provision and manage a DynamoDB table using AWS CDK or Terraform, with single-table design support and built-in local development via DynamoDB Local.
|
|
13
|
+
This generator creates a new TypeScript DynamoDB project backed by [Amazon DynamoDB](https://aws.amazon.com/dynamodb/), using [ElectroDB](https://electrodb.dev/) for type-safe entity modelling. It generates the application code and infrastructure needed to provision and manage a DynamoDB table using AWS CDK or Terraform, with single-table design support and built-in local development via DynamoDB Local.
|
|
16
14
|
|
|
17
15
|
## Usage
|
|
18
16
|
|
|
19
|
-
### Generate a DynamoDB Project
|
|
17
|
+
### Generate a TypeScript DynamoDB Project
|
|
20
18
|
|
|
21
19
|
<RunGenerator generator="ts#dynamodb" />
|
|
22
20
|
|
|
@@ -29,66 +27,38 @@ This generator creates a new TypeScript project backed by [Amazon DynamoDB](http
|
|
|
29
27
|
The generator creates the following project structure in the `<directory>/<name>` directory:
|
|
30
28
|
|
|
31
29
|
<FileTree>
|
|
32
|
-
- scripts
|
|
33
|
-
- create-local-table.ts Creates the DynamoDB table in the local DynamoDB Local instance
|
|
34
|
-
- pull-image.ts Pulls the DynamoDB Local image
|
|
35
|
-
- start-container.ts Starts the DynamoDB Local container
|
|
36
30
|
- src
|
|
37
31
|
- index.ts Project entry point and exports
|
|
38
|
-
- constants.ts Local development constants and runtime config key
|
|
39
32
|
- client.ts DynamoDB client singleton and table name resolution
|
|
40
33
|
- entities
|
|
41
34
|
- example.ts Example ElectroDB entity definition
|
|
42
35
|
- index.ts Entity exports
|
|
43
|
-
-
|
|
36
|
+
- config.json Table configuration including GSI definitions and local development settings
|
|
44
37
|
- project.json Project configuration and build targets
|
|
45
38
|
</FileTree>
|
|
46
39
|
|
|
40
|
+
The local development scripts are shared across all DynamoDB projects (both TypeScript and Python) and generated once into:
|
|
41
|
+
|
|
42
|
+
<FileTree>
|
|
43
|
+
- packages/common/scripts/src/dynamodb
|
|
44
|
+
- create-local-table.ts Creates the DynamoDB table in the local DynamoDB Local instance
|
|
45
|
+
- pull-image.ts Pulls the DynamoDB Local image
|
|
46
|
+
- start-container.ts Starts the DynamoDB Local container
|
|
47
|
+
</FileTree>
|
|
48
|
+
|
|
47
49
|
### Infrastructure
|
|
48
50
|
|
|
49
|
-
<Snippet name="
|
|
50
|
-
|
|
51
|
-
<Infrastructure>
|
|
52
|
-
<Fragment slot="cdk">
|
|
53
|
-
<FileTree>
|
|
54
|
-
- packages/common/constructs/src
|
|
55
|
-
- app
|
|
56
|
-
- dynamodb
|
|
57
|
-
- \<name>.ts Infrastructure specific to your table
|
|
58
|
-
- core
|
|
59
|
-
- dynamodb.ts Generic DynamoDB table construct
|
|
60
|
-
</FileTree>
|
|
61
|
-
</Fragment>
|
|
62
|
-
<Fragment slot="terraform">
|
|
63
|
-
<FileTree>
|
|
64
|
-
- packages/common/terraform/src
|
|
65
|
-
- app
|
|
66
|
-
- dynamodb
|
|
67
|
-
- \<name>
|
|
68
|
-
- \<name>.tf Module specific to your table
|
|
69
|
-
- core
|
|
70
|
-
- dynamodb
|
|
71
|
-
- dynamodb.tf Generic DynamoDB module
|
|
72
|
-
</FileTree>
|
|
73
|
-
</Fragment>
|
|
74
|
-
</Infrastructure>
|
|
51
|
+
<Snippet name="dynamodb/infrastructure" />
|
|
75
52
|
|
|
76
53
|
## Local Development
|
|
77
54
|
|
|
78
55
|
### Starting Local DynamoDB
|
|
79
56
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
<NxCommands commands={['run <project-name>:serve-local']} />
|
|
83
|
-
|
|
84
|
-
This automatically:
|
|
85
|
-
1. Pulls the DynamoDB Local image (`pull-image` target)
|
|
86
|
-
2. Starts a container
|
|
87
|
-
3. Creates a local table with the indexes defined in `dynamodb.config.json`
|
|
57
|
+
<Snippet name="dynamodb/serve-local-start" />
|
|
88
58
|
|
|
89
59
|
### Data Modelling
|
|
90
60
|
|
|
91
|
-
The generated project uses [ElectroDB](https://electrodb.dev/) for type-safe entity modelling on a single DynamoDB table. Add or update entity files under `src/entities/`, using the generated example entity as a starting point.
|
|
61
|
+
The generated project uses [ElectroDB](https://electrodb.dev/) for type-safe entity modelling on a single DynamoDB table, following [DynamoDB's single-table design](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/data-modeling-foundations.html). Add or update entity files under `src/entities/`, using the generated example entity as a starting point.
|
|
92
62
|
|
|
93
63
|
Example entity definition:
|
|
94
64
|
|
|
@@ -151,48 +121,13 @@ The generated `src/client.ts` exports two key utilities:
|
|
|
151
121
|
|
|
152
122
|
### Stopping Local DynamoDB
|
|
153
123
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
:::caution[Windows]
|
|
157
|
-
Due to limitations with signal handling on Windows, the container is not automatically removed when `serve-local` is stopped. You will need to remove it manually:
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
<engine> rm -f <scope>-dynamodb
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Replace `<engine>` with your container engine (`docker` or `finch`) and `<scope>` with your Nx workspace scope (e.g. `proj`).
|
|
164
|
-
:::
|
|
124
|
+
<Snippet name="dynamodb/serve-local-windows" />
|
|
165
125
|
|
|
166
126
|
## Adding/Removing Global Secondary Indexes
|
|
167
127
|
|
|
168
|
-
GSIs are defined in `
|
|
128
|
+
GSIs are defined in `config.json` at the project root under the `tableConfig.globalSecondaryIndexes` key. Add an entry for each GSI, following the [single-table design](https://electrodb.dev/en/core-concepts/single-table-relationships/) naming convention for GSI keys:
|
|
169
129
|
|
|
170
|
-
|
|
171
|
-
{
|
|
172
|
-
"globalSecondaryIndexes": [
|
|
173
|
-
{
|
|
174
|
-
"indexName": "gsi1pk-gsi1sk-index",
|
|
175
|
-
"partitionKey": "gsi1pk",
|
|
176
|
-
"sortKey": "gsi1sk"
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
The `sortKey` field is optional for hash-key-only GSIs.
|
|
183
|
-
|
|
184
|
-
This config file is read directly from the project root by all consumers:
|
|
185
|
-
- **Local development** — `serve-local` reads `dynamodb.config.json` and creates or updates the local table to match the GSI list
|
|
186
|
-
- **CDK** — the construct reads `dynamodb.config.json` at synth time, so GSI changes are reflected on the next `cdk deploy`
|
|
187
|
-
- **Terraform** — the module reads `dynamodb.config.json` at plan/apply time
|
|
188
|
-
|
|
189
|
-
### One GSI per Deployment
|
|
190
|
-
|
|
191
|
-
:::caution
|
|
192
|
-
DynamoDB [does not allow more than one GSI to be created or deleted in a single table update](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.OnlineOps.html).
|
|
193
|
-
|
|
194
|
-
Each deployment can add or remove **at most one GSI**. If you need to add or remove multiple GSIs, do so one at a time — update `dynamodb.config.json`, deploy the stack, then repeat for the next change.
|
|
195
|
-
:::
|
|
130
|
+
<Snippet name="dynamodb/gsi-config" parentHeading="Adding/Removing Global Secondary Indexes" />
|
|
196
131
|
|
|
197
132
|
## Connecting to the Table
|
|
198
133
|
|
|
@@ -220,168 +155,4 @@ For specific project types, use the `connection` generator to automatically wire
|
|
|
220
155
|
|
|
221
156
|
## Deploying your Table
|
|
222
157
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
<Infrastructure>
|
|
226
|
-
<Fragment slot="cdk">
|
|
227
|
-
The CDK construct is created in `common/constructs`. Example usage:
|
|
228
|
-
|
|
229
|
-
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
230
|
-
import { MyTable } from ':my-scope/common-constructs';
|
|
231
|
-
|
|
232
|
-
export class ApplicationStack extends Stack {
|
|
233
|
-
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
234
|
-
super(scope, id, props);
|
|
235
|
-
|
|
236
|
-
const table = new MyTable(this, 'Table');
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
This provisions a DynamoDB table with:
|
|
242
|
-
- `pk` (partition key) and `sk` (sort key), both `String` type
|
|
243
|
-
- Global Secondary Indexes as defined in `dynamodb.config.json`
|
|
244
|
-
- On-demand (`PAY_PER_REQUEST`) billing
|
|
245
|
-
- Customer-managed KMS encryption with automatic key rotation
|
|
246
|
-
- Point-in-time recovery enabled
|
|
247
|
-
- Deletion protection enabled
|
|
248
|
-
- Table name registered in Runtime Config under the `dynamodb` namespace in AWS AppConfig
|
|
249
|
-
</Fragment>
|
|
250
|
-
<Fragment slot="terraform">
|
|
251
|
-
The Terraform module is created in `common/terraform`. Example usage:
|
|
252
|
-
|
|
253
|
-
```hcl title="packages/infra/src/main.tf"
|
|
254
|
-
module "my_table" {
|
|
255
|
-
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
256
|
-
}
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
This provisions a DynamoDB table with:
|
|
260
|
-
- `pk` (partition key) and `sk` (sort key), both `String` type
|
|
261
|
-
- Global Secondary Indexes as defined in `dynamodb.config.json`
|
|
262
|
-
- On-demand (`PAY_PER_REQUEST`) billing
|
|
263
|
-
- Customer-managed KMS encryption with automatic key rotation
|
|
264
|
-
- Point-in-time recovery enabled
|
|
265
|
-
- Deletion protection enabled
|
|
266
|
-
- Table name registered in Runtime Config
|
|
267
|
-
</Fragment>
|
|
268
|
-
</Infrastructure>
|
|
269
|
-
|
|
270
|
-
### Granting Access
|
|
271
|
-
|
|
272
|
-
<Snippet name="connection/lambda-dynamodb-access" />
|
|
273
|
-
|
|
274
|
-
### Deletion Protection
|
|
275
|
-
|
|
276
|
-
Deletion protection is enabled by default to prevent accidental table deletion.
|
|
277
|
-
|
|
278
|
-
#### Disable Deletion Protection
|
|
279
|
-
|
|
280
|
-
Disable it for environments where table deletion is expected, such as short-lived development or preview stacks.
|
|
281
|
-
|
|
282
|
-
<Infrastructure>
|
|
283
|
-
<Fragment slot="cdk">
|
|
284
|
-
|
|
285
|
-
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
286
|
-
import { MyTable } from ':my-scope/common-constructs';
|
|
287
|
-
|
|
288
|
-
const table = new MyTable(this, 'Table', {
|
|
289
|
-
deletionProtection: false,
|
|
290
|
-
});
|
|
291
|
-
```
|
|
292
|
-
</Fragment>
|
|
293
|
-
<Fragment slot="terraform">
|
|
294
|
-
|
|
295
|
-
```hcl title="packages/infra/src/main.tf"
|
|
296
|
-
module "my_table" {
|
|
297
|
-
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
298
|
-
deletion_protection_enabled = false
|
|
299
|
-
}
|
|
300
|
-
```
|
|
301
|
-
</Fragment>
|
|
302
|
-
</Infrastructure>
|
|
303
|
-
|
|
304
|
-
### Billing Mode
|
|
305
|
-
|
|
306
|
-
The table defaults to on-demand (`PAY_PER_REQUEST`) billing. Switch to provisioned capacity for predictable, high-throughput workloads.
|
|
307
|
-
|
|
308
|
-
<Infrastructure>
|
|
309
|
-
<Fragment slot="cdk">
|
|
310
|
-
|
|
311
|
-
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
312
|
-
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';
|
|
313
|
-
import { MyTable } from ':my-scope/common-constructs';
|
|
314
|
-
|
|
315
|
-
const table = new MyTable(this, 'Table', {
|
|
316
|
-
billingMode: BillingMode.PROVISIONED,
|
|
317
|
-
readCapacity: 5,
|
|
318
|
-
writeCapacity: 5,
|
|
319
|
-
});
|
|
320
|
-
```
|
|
321
|
-
</Fragment>
|
|
322
|
-
<Fragment slot="terraform">
|
|
323
|
-
|
|
324
|
-
```hcl title="packages/infra/src/main.tf"
|
|
325
|
-
module "my_table" {
|
|
326
|
-
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
327
|
-
billing_mode = "PROVISIONED"
|
|
328
|
-
}
|
|
329
|
-
```
|
|
330
|
-
</Fragment>
|
|
331
|
-
</Infrastructure>
|
|
332
|
-
|
|
333
|
-
### Point-in-time Recovery
|
|
334
|
-
|
|
335
|
-
[Point-in-time recovery](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Point-in-time-recovery.html) is enabled by default, allowing you to restore the table to any point in the last 35 days.
|
|
336
|
-
|
|
337
|
-
#### Disable Point-in-time Recovery
|
|
338
|
-
|
|
339
|
-
<Infrastructure>
|
|
340
|
-
<Fragment slot="cdk">
|
|
341
|
-
|
|
342
|
-
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
343
|
-
import { MyTable } from ':my-scope/common-constructs';
|
|
344
|
-
|
|
345
|
-
const table = new MyTable(this, 'Table', {
|
|
346
|
-
pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: false },
|
|
347
|
-
});
|
|
348
|
-
```
|
|
349
|
-
</Fragment>
|
|
350
|
-
<Fragment slot="terraform">
|
|
351
|
-
|
|
352
|
-
```hcl title="packages/infra/src/main.tf"
|
|
353
|
-
module "my_table" {
|
|
354
|
-
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
355
|
-
point_in_time_recovery_enabled = false
|
|
356
|
-
}
|
|
357
|
-
```
|
|
358
|
-
</Fragment>
|
|
359
|
-
</Infrastructure>
|
|
360
|
-
|
|
361
|
-
### Encryption Key Rotation
|
|
362
|
-
|
|
363
|
-
The KMS key used to encrypt the table has automatic key rotation enabled by default. Disable it if your security policy manages rotation externally.
|
|
364
|
-
|
|
365
|
-
#### Disable Encryption Key Rotation
|
|
366
|
-
|
|
367
|
-
<Infrastructure>
|
|
368
|
-
<Fragment slot="cdk">
|
|
369
|
-
|
|
370
|
-
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
371
|
-
import { MyTable } from ':my-scope/common-constructs';
|
|
372
|
-
|
|
373
|
-
const table = new MyTable(this, 'Table', {
|
|
374
|
-
enableKeyRotation: false,
|
|
375
|
-
});
|
|
376
|
-
```
|
|
377
|
-
</Fragment>
|
|
378
|
-
<Fragment slot="terraform">
|
|
379
|
-
|
|
380
|
-
```hcl title="packages/infra/src/main.tf"
|
|
381
|
-
module "my_table" {
|
|
382
|
-
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
383
|
-
enable_key_rotation = false
|
|
384
|
-
}
|
|
385
|
-
```
|
|
386
|
-
</Fragment>
|
|
387
|
-
</Infrastructure>
|
|
158
|
+
<Snippet name="dynamodb/deploying-table" parentHeading="Deploying your Table" />
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Python DynamoDB Local Development
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `connection` generator configures your project's `serve-local` target to depend on the DynamoDB project's `serve-local` target. DynamoDB Local will start automatically alongside your project when running `serve-local`.
|
|
6
|
+
|
|
7
|
+
The `SERVE_LOCAL=true` environment variable is set automatically, so `is_local()` returns `True` and your PynamoDB entities connect to the local DynamoDB instance instead of AWS.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Deploying your DynamoDB Table
|
|
3
|
+
---
|
|
4
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
5
|
+
import Snippet from '@components/snippet.astro';
|
|
6
|
+
|
|
7
|
+
The DynamoDB generator creates CDK or Terraform infrastructure based on your selected `iac`.
|
|
8
|
+
|
|
9
|
+
<Infrastructure>
|
|
10
|
+
<Fragment slot="cdk">
|
|
11
|
+
The CDK construct is created in `common/constructs`. Example usage:
|
|
12
|
+
|
|
13
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
14
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
15
|
+
|
|
16
|
+
export class ApplicationStack extends Stack {
|
|
17
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
18
|
+
super(scope, id, props);
|
|
19
|
+
|
|
20
|
+
const table = new MyTable(this, 'Table');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This provisions a DynamoDB table with:
|
|
26
|
+
- `pk` (partition key) and `sk` (sort key), both `String` type
|
|
27
|
+
- Global Secondary Indexes as defined in `config.json`
|
|
28
|
+
- On-demand (`PAY_PER_REQUEST`) billing
|
|
29
|
+
- Customer-managed KMS encryption with automatic key rotation
|
|
30
|
+
- Point-in-time recovery enabled
|
|
31
|
+
- Deletion protection enabled
|
|
32
|
+
- Table name registered in Runtime Config under the `dynamodb` namespace in AWS AppConfig
|
|
33
|
+
</Fragment>
|
|
34
|
+
<Fragment slot="terraform">
|
|
35
|
+
The Terraform module is created in `common/terraform`. Example usage:
|
|
36
|
+
|
|
37
|
+
```hcl title="packages/infra/src/main.tf"
|
|
38
|
+
module "my_table" {
|
|
39
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This provisions a DynamoDB table with:
|
|
44
|
+
- `pk` (partition key) and `sk` (sort key), both `String` type
|
|
45
|
+
- Global Secondary Indexes as defined in `config.json`
|
|
46
|
+
- On-demand (`PAY_PER_REQUEST`) billing
|
|
47
|
+
- Customer-managed KMS encryption with automatic key rotation
|
|
48
|
+
- Point-in-time recovery enabled
|
|
49
|
+
- Deletion protection enabled
|
|
50
|
+
- Table name registered in Runtime Config
|
|
51
|
+
</Fragment>
|
|
52
|
+
</Infrastructure>
|
|
53
|
+
|
|
54
|
+
### Granting Access
|
|
55
|
+
|
|
56
|
+
<Snippet name="connection/lambda-dynamodb-access" />
|
|
57
|
+
|
|
58
|
+
### Deletion Protection
|
|
59
|
+
|
|
60
|
+
Deletion protection is enabled by default to prevent accidental table deletion.
|
|
61
|
+
|
|
62
|
+
#### Disable Deletion Protection
|
|
63
|
+
|
|
64
|
+
Disable it for environments where table deletion is expected, such as short-lived development or preview stacks.
|
|
65
|
+
|
|
66
|
+
<Infrastructure>
|
|
67
|
+
<Fragment slot="cdk">
|
|
68
|
+
|
|
69
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
70
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
71
|
+
|
|
72
|
+
const table = new MyTable(this, 'Table', {
|
|
73
|
+
deletionProtection: false,
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
</Fragment>
|
|
77
|
+
<Fragment slot="terraform">
|
|
78
|
+
|
|
79
|
+
```hcl title="packages/infra/src/main.tf"
|
|
80
|
+
module "my_table" {
|
|
81
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
82
|
+
deletion_protection_enabled = false
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
</Fragment>
|
|
86
|
+
</Infrastructure>
|
|
87
|
+
|
|
88
|
+
### Billing Mode
|
|
89
|
+
|
|
90
|
+
The table defaults to on-demand (`PAY_PER_REQUEST`) billing. Switch to provisioned capacity for predictable, high-throughput workloads.
|
|
91
|
+
|
|
92
|
+
<Infrastructure>
|
|
93
|
+
<Fragment slot="cdk">
|
|
94
|
+
|
|
95
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
96
|
+
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';
|
|
97
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
98
|
+
|
|
99
|
+
const table = new MyTable(this, 'Table', {
|
|
100
|
+
billingMode: BillingMode.PROVISIONED,
|
|
101
|
+
readCapacity: 5,
|
|
102
|
+
writeCapacity: 5,
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
</Fragment>
|
|
106
|
+
<Fragment slot="terraform">
|
|
107
|
+
|
|
108
|
+
```hcl title="packages/infra/src/main.tf"
|
|
109
|
+
module "my_table" {
|
|
110
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
111
|
+
billing_mode = "PROVISIONED"
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
</Fragment>
|
|
115
|
+
</Infrastructure>
|
|
116
|
+
|
|
117
|
+
### Point-in-time Recovery
|
|
118
|
+
|
|
119
|
+
[Point-in-time recovery](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Point-in-time-recovery.html) is enabled by default, allowing you to restore the table to any point in the last 35 days.
|
|
120
|
+
|
|
121
|
+
#### Disable Point-in-time Recovery
|
|
122
|
+
|
|
123
|
+
<Infrastructure>
|
|
124
|
+
<Fragment slot="cdk">
|
|
125
|
+
|
|
126
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
127
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
128
|
+
|
|
129
|
+
const table = new MyTable(this, 'Table', {
|
|
130
|
+
pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: false },
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
</Fragment>
|
|
134
|
+
<Fragment slot="terraform">
|
|
135
|
+
|
|
136
|
+
```hcl title="packages/infra/src/main.tf"
|
|
137
|
+
module "my_table" {
|
|
138
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
139
|
+
point_in_time_recovery_enabled = false
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
</Fragment>
|
|
143
|
+
</Infrastructure>
|
|
144
|
+
|
|
145
|
+
### Encryption Key Rotation
|
|
146
|
+
|
|
147
|
+
The KMS key used to encrypt the table has automatic key rotation enabled by default. Disable it if your security policy manages rotation externally.
|
|
148
|
+
|
|
149
|
+
#### Disable Encryption Key Rotation
|
|
150
|
+
|
|
151
|
+
<Infrastructure>
|
|
152
|
+
<Fragment slot="cdk">
|
|
153
|
+
|
|
154
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
155
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
156
|
+
|
|
157
|
+
const table = new MyTable(this, 'Table', {
|
|
158
|
+
enableKeyRotation: false,
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
</Fragment>
|
|
162
|
+
<Fragment slot="terraform">
|
|
163
|
+
|
|
164
|
+
```hcl title="packages/infra/src/main.tf"
|
|
165
|
+
module "my_table" {
|
|
166
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
167
|
+
enable_key_rotation = false
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
</Fragment>
|
|
171
|
+
</Infrastructure>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: GSI Configuration
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
```json title="config.json"
|
|
6
|
+
{
|
|
7
|
+
...
|
|
8
|
+
"tableConfig": {
|
|
9
|
+
"globalSecondaryIndexes": [
|
|
10
|
+
{
|
|
11
|
+
"indexName": "gsi1pk-gsi1sk-index",
|
|
12
|
+
"partitionKey": "gsi1pk",
|
|
13
|
+
"sortKey": "gsi1sk"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"indexName": "gsi2pk-gsi2sk-index",
|
|
17
|
+
"partitionKey": "gsi2pk",
|
|
18
|
+
"sortKey": "gsi2sk"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The `sortKey` field is optional for hash-key-only GSIs.
|
|
26
|
+
|
|
27
|
+
This config file is the single source of truth read by all consumers:
|
|
28
|
+
- **Local development** — `serve-local` reads `config.json` and creates or updates the local table to match the GSI list
|
|
29
|
+
- **CDK** — the construct reads `config.json` at synth time, so GSI changes are reflected on the next `cdk deploy`
|
|
30
|
+
- **Terraform** — the module reads `config.json` at plan/apply time
|
|
31
|
+
|
|
32
|
+
### One GSI per Deployment
|
|
33
|
+
|
|
34
|
+
:::caution
|
|
35
|
+
DynamoDB [does not allow more than one GSI to be created or deleted in a single table update](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.OnlineOps.html).
|
|
36
|
+
|
|
37
|
+
Each deployment can add or remove **at most one GSI**. If you need to add or remove multiple GSIs, do so one at a time — update `config.json` and relevant entity classes, deploy the stack, then repeat for the next change.
|
|
38
|
+
:::
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: DynamoDB Infrastructure
|
|
3
|
+
---
|
|
4
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
5
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
6
|
+
import Snippet from '@components/snippet.astro';
|
|
7
|
+
|
|
8
|
+
<Snippet name="shared-constructs" />
|
|
9
|
+
|
|
10
|
+
<Infrastructure>
|
|
11
|
+
<Fragment slot="cdk">
|
|
12
|
+
<FileTree>
|
|
13
|
+
- packages/common/constructs/src
|
|
14
|
+
- app
|
|
15
|
+
- dynamodb
|
|
16
|
+
- \<name>.ts Infrastructure specific to your table
|
|
17
|
+
- core
|
|
18
|
+
- dynamodb.ts Generic DynamoDB table construct
|
|
19
|
+
</FileTree>
|
|
20
|
+
</Fragment>
|
|
21
|
+
<Fragment slot="terraform">
|
|
22
|
+
<FileTree>
|
|
23
|
+
- packages/common/terraform/src
|
|
24
|
+
- app
|
|
25
|
+
- dynamodb
|
|
26
|
+
- \<name>
|
|
27
|
+
- \<name>.tf Module specific to your table
|
|
28
|
+
- core
|
|
29
|
+
- dynamodb
|
|
30
|
+
- dynamodb.tf Generic DynamoDB module
|
|
31
|
+
</FileTree>
|
|
32
|
+
</Fragment>
|
|
33
|
+
</Infrastructure>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Starting Local DynamoDB
|
|
3
|
+
---
|
|
4
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
5
|
+
|
|
6
|
+
The generator configures a `serve-local` target that starts a [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) instance and creates the table:
|
|
7
|
+
|
|
8
|
+
<NxCommands commands={['run <project-name>:serve-local']} />
|
|
9
|
+
|
|
10
|
+
This automatically:
|
|
11
|
+
1. Pulls the DynamoDB Local image (`pull-image` target)
|
|
12
|
+
2. Starts a container
|
|
13
|
+
3. Creates a local table with the indexes defined in `config.json`
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Serve Local Windows Caution
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Stopping `serve-local` (e.g. with `Ctrl+C`) automatically removes the DynamoDB Local container, but preserves the named volume so your data persists across restarts.
|
|
6
|
+
|
|
7
|
+
:::caution[Windows]
|
|
8
|
+
Due to limitations with signal handling on Windows, the container is not automatically removed when `serve-local` is stopped. You will need to remove it manually:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
<engine> rm -f <scope>-dynamodb
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Replace `<engine>` with your container engine (`docker` or `finch`) and `<scope>` with your Nx workspace scope (e.g. `proj`).
|
|
15
|
+
:::
|
package/generators.json
CHANGED
|
@@ -383,7 +383,7 @@
|
|
|
383
383
|
"ts#dynamodb": {
|
|
384
384
|
"factory": "./src/ts/dynamodb/generator",
|
|
385
385
|
"schema": "./src/ts/dynamodb/schema.json",
|
|
386
|
-
"description": "Create a DynamoDB project",
|
|
386
|
+
"description": "Create a TypeScript DynamoDB project",
|
|
387
387
|
"metric": "g43"
|
|
388
388
|
},
|
|
389
389
|
"ts#dynamodb#trpc-connection": {
|
|
@@ -413,6 +413,33 @@
|
|
|
413
413
|
"description": "Connect a ts#mcp-server to a ts#dynamodb project",
|
|
414
414
|
"metric": "g47",
|
|
415
415
|
"hidden": true
|
|
416
|
+
},
|
|
417
|
+
"py#dynamodb": {
|
|
418
|
+
"factory": "./src/py/dynamodb/generator",
|
|
419
|
+
"schema": "./src/py/dynamodb/schema.json",
|
|
420
|
+
"description": "Create a Python DynamoDB project",
|
|
421
|
+
"metric": "g52"
|
|
422
|
+
},
|
|
423
|
+
"py#dynamodb#fast-api-connection": {
|
|
424
|
+
"factory": "./src/py/dynamodb/fast-api-connection/generator",
|
|
425
|
+
"schema": "./src/py/dynamodb/fast-api-connection/schema.json",
|
|
426
|
+
"description": "Connect a py#fast-api project to a py#dynamodb project",
|
|
427
|
+
"metric": "g53",
|
|
428
|
+
"hidden": true
|
|
429
|
+
},
|
|
430
|
+
"py#dynamodb#agent-connection": {
|
|
431
|
+
"factory": "./src/py/dynamodb/agent-connection/generator",
|
|
432
|
+
"schema": "./src/py/dynamodb/agent-connection/schema.json",
|
|
433
|
+
"description": "Connect a py#agent to a py#dynamodb project",
|
|
434
|
+
"metric": "g54",
|
|
435
|
+
"hidden": true
|
|
436
|
+
},
|
|
437
|
+
"py#dynamodb#mcp-server-connection": {
|
|
438
|
+
"factory": "./src/py/dynamodb/mcp-server-connection/generator",
|
|
439
|
+
"schema": "./src/py/dynamodb/mcp-server-connection/schema.json",
|
|
440
|
+
"description": "Connect a py#mcp-server to a py#dynamodb project",
|
|
441
|
+
"metric": "g55",
|
|
442
|
+
"hidden": true
|
|
416
443
|
}
|
|
417
444
|
}
|
|
418
445
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "py#dynamodb#agent-connection",
|
|
4
|
+
"title": "py#dynamodb#agent-connection",
|
|
5
|
+
"description": "Connect a py#agent to a py#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project containing the py#agent to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The py#dynamodb project to connect to"
|
|
15
|
+
},
|
|
16
|
+
"sourceComponent": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The agent component name"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["sourceProject", "targetProject"]
|
|
22
|
+
}
|