@aws/nx-plugin-mcp 1.0.0-rc.2 → 1.0.0-rc.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/bin/aws-nx-mcp.js +2376 -2043
- package/docs/guides/connection/smithy-dynamodb.mdx +68 -0
- package/docs/guides/connection/trpc-dynamodb.mdx +62 -0
- package/docs/guides/connection/ts-agent-dynamodb.mdx +128 -0
- package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +125 -0
- package/docs/guides/connection.mdx +29 -0
- package/docs/guides/ts-dynamodb.mdx +364 -0
- package/docs/guides/workspace.mdx +6 -0
- package/docs/snippets/connection/dynamodb-local-development.mdx +7 -0
- package/docs/snippets/connection/lambda-dynamodb-access.mdx +80 -0
- package/docs/snippets/mcp/config.mdx +1 -1
- package/generators.json +34 -0
- package/package.json +1 -1
- package/src/preset/schema.json +5 -0
- package/src/ts/dynamodb/agent-connection/schema.json +22 -0
- package/src/ts/dynamodb/mcp-server-connection/schema.json +22 -0
- package/src/ts/dynamodb/schema.json +52 -0
- package/src/ts/dynamodb/smithy-connection/schema.json +18 -0
- package/src/ts/dynamodb/trpc-connection/schema.json +18 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: DynamoDB
|
|
3
|
+
description: Create a DynamoDB project
|
|
4
|
+
generator: ts#dynamodb
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
8
|
+
import Link from '@components/link.astro';
|
|
9
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
10
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
11
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import Snippet from '@components/snippet.astro';
|
|
14
|
+
import OptionFilter from '@components/option-filter.astro';
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Generate a DynamoDB Project
|
|
21
|
+
|
|
22
|
+
<RunGenerator generator="ts#dynamodb" />
|
|
23
|
+
|
|
24
|
+
### Options
|
|
25
|
+
|
|
26
|
+
<GeneratorParameters generator="ts#dynamodb" />
|
|
27
|
+
|
|
28
|
+
## Generator Output
|
|
29
|
+
|
|
30
|
+
The generator creates the following project structure in the `<directory>/<name>` directory:
|
|
31
|
+
|
|
32
|
+
<FileTree>
|
|
33
|
+
- scripts
|
|
34
|
+
- create-local-table.ts Creates the DynamoDB table in the local DynamoDB Local instance
|
|
35
|
+
- pull-image.ts Pulls the DynamoDB Local image
|
|
36
|
+
- start-container.ts Starts the DynamoDB Local container
|
|
37
|
+
- src
|
|
38
|
+
- index.ts Project entry point and exports
|
|
39
|
+
- constants.ts Local development constants and runtime config key
|
|
40
|
+
- client.ts DynamoDB client singleton and table name resolution
|
|
41
|
+
- entities
|
|
42
|
+
- example.ts Example ElectroDB entity definition
|
|
43
|
+
- index.ts Entity exports
|
|
44
|
+
- project.json Project configuration and build targets
|
|
45
|
+
</FileTree>
|
|
46
|
+
|
|
47
|
+
### Infrastructure
|
|
48
|
+
|
|
49
|
+
<Snippet name="shared-constructs" />
|
|
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>
|
|
75
|
+
|
|
76
|
+
## Local Development
|
|
77
|
+
|
|
78
|
+
### Starting Local DynamoDB
|
|
79
|
+
|
|
80
|
+
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:
|
|
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 pre-defined indexes
|
|
88
|
+
|
|
89
|
+
### Data Modelling
|
|
90
|
+
|
|
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.
|
|
92
|
+
|
|
93
|
+
Example entity definition:
|
|
94
|
+
|
|
95
|
+
```ts title="packages/my-table/src/entities/example.ts"
|
|
96
|
+
import { Entity } from 'electrodb';
|
|
97
|
+
import { getDynamoDBClient, resolveTableName } from '../client.js';
|
|
98
|
+
|
|
99
|
+
export const createExampleEntity = async () =>
|
|
100
|
+
new Entity(
|
|
101
|
+
{
|
|
102
|
+
model: {
|
|
103
|
+
entity: 'example',
|
|
104
|
+
version: '1',
|
|
105
|
+
service: 'MyTable',
|
|
106
|
+
},
|
|
107
|
+
attributes: {
|
|
108
|
+
id: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
required: true,
|
|
111
|
+
},
|
|
112
|
+
createdAt: {
|
|
113
|
+
type: 'string',
|
|
114
|
+
required: true,
|
|
115
|
+
default: () => new Date().toISOString(),
|
|
116
|
+
readOnly: true,
|
|
117
|
+
},
|
|
118
|
+
updatedAt: {
|
|
119
|
+
type: 'string',
|
|
120
|
+
required: true,
|
|
121
|
+
default: () => new Date().toISOString(),
|
|
122
|
+
watch: '*',
|
|
123
|
+
set: () => new Date().toISOString(),
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
indexes: {
|
|
127
|
+
primary: {
|
|
128
|
+
pk: {
|
|
129
|
+
field: 'pk',
|
|
130
|
+
composite: ['id'],
|
|
131
|
+
},
|
|
132
|
+
sk: {
|
|
133
|
+
field: 'sk',
|
|
134
|
+
composite: [],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
{ client: getDynamoDBClient(), table: await resolveTableName() },
|
|
140
|
+
);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
For more details, see the [ElectroDB entity documentation](https://electrodb.dev/en/modeling/entities/).
|
|
144
|
+
|
|
145
|
+
### Using the DynamoDB Client
|
|
146
|
+
|
|
147
|
+
The generated `src/client.ts` exports two key utilities:
|
|
148
|
+
|
|
149
|
+
- `getDynamoDBClient()` — returns a cached singleton `DynamoDBClient`. When `SERVE_LOCAL=true`, connects to the local DynamoDB Local instance; otherwise creates an AWS client using the default credential chain.
|
|
150
|
+
- `resolveTableName()` — returns the DynamoDB table name. When `SERVE_LOCAL=true`, returns the local table name constant; otherwise fetches the name from AWS AppConfig using the `RUNTIME_CONFIG_APP_ID` environment variable and caches it for subsequent calls.
|
|
151
|
+
|
|
152
|
+
### Stopping Local DynamoDB
|
|
153
|
+
|
|
154
|
+
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.
|
|
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
|
+
:::
|
|
165
|
+
|
|
166
|
+
## Adding/Removing Global Secondary Indexes
|
|
167
|
+
|
|
168
|
+
Start by updating `GLOBAL_SECONDARY_INDEXES` in `src/gsi.ts` — this is the source of truth for your GSI definitions, and on the next `serve-local` run the script will automatically add or remove indexes on the local table to reflect the new list. When using CDK, these changes are also automatically reflected in your AWS table on the next deployment.
|
|
169
|
+
|
|
170
|
+
<OptionFilter when={{ iac: 'terraform' }}>
|
|
171
|
+
Unlike CDK, changes to `src/gsi.ts` are not automatically reflected in your Terraform module. You must also manually update your Terraform module to add or remove the corresponding GSI definitions before deploying.
|
|
172
|
+
</OptionFilter>
|
|
173
|
+
|
|
174
|
+
## Connecting to the Table
|
|
175
|
+
|
|
176
|
+
In any TypeScript project, import entity factories from your DynamoDB package and use them directly:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
import { createExampleEntity } from ':my-scope/my-table';
|
|
180
|
+
|
|
181
|
+
const entity = await createExampleEntity();
|
|
182
|
+
const result = await entity.query.primary({ id: '123' }).go();
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
:::note[Runtime config]
|
|
186
|
+
When running in AWS, `resolveTableName()` fetches the table name from AWS AppConfig using the `RUNTIME_CONFIG_APP_ID` environment variable. Projects built with this plugin (tRPC APIs, Smithy APIs, agents, MCP servers) already have this variable configured automatically. For other TypeScript projects, ensure `RUNTIME_CONFIG_APP_ID` is set in the runtime environment with the AppConfig application ID provisioned by your infrastructure. For more information, see the <Link path="guides/runtime-config">Runtime Configuration guide</Link>.
|
|
187
|
+
:::
|
|
188
|
+
|
|
189
|
+
### Connection Generators
|
|
190
|
+
|
|
191
|
+
For specific project types, use the `connection` generator to automatically wire up local development dependencies so DynamoDB Local starts automatically alongside your project:
|
|
192
|
+
|
|
193
|
+
- <Link path="guides/connection/trpc-dynamodb">tRPC API → DynamoDB</Link>
|
|
194
|
+
- <Link path="guides/connection/smithy-dynamodb">Smithy API → DynamoDB</Link>
|
|
195
|
+
- <Link path="guides/connection/ts-agent-dynamodb">TypeScript Agent → DynamoDB</Link>
|
|
196
|
+
- <Link path="guides/connection/ts-mcp-server-dynamodb">MCP Server → DynamoDB</Link>
|
|
197
|
+
|
|
198
|
+
## Deploying your Table
|
|
199
|
+
|
|
200
|
+
The DynamoDB generator creates CDK or Terraform infrastructure based on your selected `iac`.
|
|
201
|
+
|
|
202
|
+
<Infrastructure>
|
|
203
|
+
<Fragment slot="cdk">
|
|
204
|
+
The CDK construct is created in `common/constructs`. Example usage:
|
|
205
|
+
|
|
206
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
207
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
208
|
+
|
|
209
|
+
export class ApplicationStack extends Stack {
|
|
210
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
211
|
+
super(scope, id, props);
|
|
212
|
+
|
|
213
|
+
const table = new MyTable(this, 'Table');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
This provisions a DynamoDB table with:
|
|
219
|
+
- `pk` (partition key) and `sk` (sort key), both `String` type
|
|
220
|
+
- 2 Global Secondary Indexes by default, as defined in `src/gsi.ts`
|
|
221
|
+
- On-demand (`PAY_PER_REQUEST`) billing
|
|
222
|
+
- Customer-managed KMS encryption with automatic key rotation
|
|
223
|
+
- Point-in-time recovery enabled
|
|
224
|
+
- Deletion protection enabled
|
|
225
|
+
- Table name registered in Runtime Config under the `dynamodb` namespace in AWS AppConfig
|
|
226
|
+
</Fragment>
|
|
227
|
+
<Fragment slot="terraform">
|
|
228
|
+
The Terraform module is created in `common/terraform`. Example usage:
|
|
229
|
+
|
|
230
|
+
```hcl title="packages/infra/src/main.tf"
|
|
231
|
+
module "my_table" {
|
|
232
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
This provisions a DynamoDB table with:
|
|
237
|
+
- `pk` (partition key) and `sk` (sort key), both `String` type
|
|
238
|
+
- 2 Global Secondary Indexes by default, as defined in `src/gsi.ts`
|
|
239
|
+
- On-demand (`PAY_PER_REQUEST`) billing
|
|
240
|
+
- Customer-managed KMS encryption with automatic key rotation
|
|
241
|
+
- Point-in-time recovery enabled
|
|
242
|
+
- Deletion protection enabled
|
|
243
|
+
- Table name registered in Runtime Config
|
|
244
|
+
</Fragment>
|
|
245
|
+
</Infrastructure>
|
|
246
|
+
|
|
247
|
+
### Granting Access
|
|
248
|
+
|
|
249
|
+
<Snippet name="connection/lambda-dynamodb-access" />
|
|
250
|
+
|
|
251
|
+
### Deletion Protection
|
|
252
|
+
|
|
253
|
+
Deletion protection is enabled by default to prevent accidental table deletion.
|
|
254
|
+
|
|
255
|
+
#### Disable Deletion Protection
|
|
256
|
+
|
|
257
|
+
Disable it for environments where table deletion is expected, such as short-lived development or preview stacks.
|
|
258
|
+
|
|
259
|
+
<Infrastructure>
|
|
260
|
+
<Fragment slot="cdk">
|
|
261
|
+
|
|
262
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
263
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
264
|
+
|
|
265
|
+
const table = new MyTable(this, 'Table', {
|
|
266
|
+
deletionProtection: false,
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
</Fragment>
|
|
270
|
+
<Fragment slot="terraform">
|
|
271
|
+
|
|
272
|
+
```hcl title="packages/infra/src/main.tf"
|
|
273
|
+
module "my_table" {
|
|
274
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
275
|
+
deletion_protection_enabled = false
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
</Fragment>
|
|
279
|
+
</Infrastructure>
|
|
280
|
+
|
|
281
|
+
### Billing Mode
|
|
282
|
+
|
|
283
|
+
The table defaults to on-demand (`PAY_PER_REQUEST`) billing. Switch to provisioned capacity for predictable, high-throughput workloads.
|
|
284
|
+
|
|
285
|
+
<Infrastructure>
|
|
286
|
+
<Fragment slot="cdk">
|
|
287
|
+
|
|
288
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
289
|
+
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';
|
|
290
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
291
|
+
|
|
292
|
+
const table = new MyTable(this, 'Table', {
|
|
293
|
+
billingMode: BillingMode.PROVISIONED,
|
|
294
|
+
readCapacity: 5,
|
|
295
|
+
writeCapacity: 5,
|
|
296
|
+
});
|
|
297
|
+
```
|
|
298
|
+
</Fragment>
|
|
299
|
+
<Fragment slot="terraform">
|
|
300
|
+
|
|
301
|
+
```hcl title="packages/infra/src/main.tf"
|
|
302
|
+
module "my_table" {
|
|
303
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
304
|
+
billing_mode = "PROVISIONED"
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
</Fragment>
|
|
308
|
+
</Infrastructure>
|
|
309
|
+
|
|
310
|
+
### Point-in-time Recovery
|
|
311
|
+
|
|
312
|
+
[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.
|
|
313
|
+
|
|
314
|
+
#### Disable Point-in-time Recovery
|
|
315
|
+
|
|
316
|
+
<Infrastructure>
|
|
317
|
+
<Fragment slot="cdk">
|
|
318
|
+
|
|
319
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
320
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
321
|
+
|
|
322
|
+
const table = new MyTable(this, 'Table', {
|
|
323
|
+
pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: false },
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
</Fragment>
|
|
327
|
+
<Fragment slot="terraform">
|
|
328
|
+
|
|
329
|
+
```hcl title="packages/infra/src/main.tf"
|
|
330
|
+
module "my_table" {
|
|
331
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
332
|
+
point_in_time_recovery_enabled = false
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
</Fragment>
|
|
336
|
+
</Infrastructure>
|
|
337
|
+
|
|
338
|
+
### Encryption Key Rotation
|
|
339
|
+
|
|
340
|
+
The KMS key used to encrypt the table has automatic key rotation enabled by default. Disable it if your security policy manages rotation externally.
|
|
341
|
+
|
|
342
|
+
#### Disable Encryption Key Rotation
|
|
343
|
+
|
|
344
|
+
<Infrastructure>
|
|
345
|
+
<Fragment slot="cdk">
|
|
346
|
+
|
|
347
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
348
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
349
|
+
|
|
350
|
+
const table = new MyTable(this, 'Table', {
|
|
351
|
+
enableKeyRotation: false,
|
|
352
|
+
});
|
|
353
|
+
```
|
|
354
|
+
</Fragment>
|
|
355
|
+
<Fragment slot="terraform">
|
|
356
|
+
|
|
357
|
+
```hcl title="packages/infra/src/main.tf"
|
|
358
|
+
module "my_table" {
|
|
359
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
360
|
+
enable_key_rotation = false
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
</Fragment>
|
|
364
|
+
</Infrastructure>
|
|
@@ -29,6 +29,12 @@ When you create a new workspace with `@aws/nx-plugin`, the preset generator sets
|
|
|
29
29
|
- aws-nx-plugin.config.mts Nx Plugin for AWS configuration
|
|
30
30
|
- .git-secrets/ Vendored git-secrets bash script for credential scanning
|
|
31
31
|
- .husky/ Git hooks
|
|
32
|
+
- .mcp.json Nx Plugin for AWS MCP server configuration for Claude Code
|
|
33
|
+
- .cursor/mcp.json ...and for Cursor
|
|
34
|
+
- .kiro/settings/mcp.json ...and for Kiro
|
|
35
|
+
- .gemini/settings.json ...and for Gemini CLI
|
|
36
|
+
- .vscode/mcp.json ...and for GitHub Copilot
|
|
37
|
+
- .codex/config.toml ...and for OpenAI Codex
|
|
32
38
|
</FileTree>
|
|
33
39
|
|
|
34
40
|
## Nx
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 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 `getDynamoDBClient()` and `resolveTableName()` connect to the local DynamoDB Local instance instead of AWS.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Lambda DynamoDB Access
|
|
3
|
+
---
|
|
4
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
5
|
+
|
|
6
|
+
To allow Lambda functions to access the DynamoDB table, grant the necessary permissions in your infrastructure.
|
|
7
|
+
|
|
8
|
+
<Infrastructure>
|
|
9
|
+
<Fragment slot="cdk">
|
|
10
|
+
|
|
11
|
+
Call `grantReadWriteData` on the table construct. This grants both the DynamoDB and KMS permissions required by the Lambda execution role:
|
|
12
|
+
|
|
13
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
14
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
15
|
+
|
|
16
|
+
const table = new MyTable(this, 'Table');
|
|
17
|
+
|
|
18
|
+
const api = new Api(this, 'Api', {
|
|
19
|
+
integrations: Api.defaultIntegrations(this).build(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
Object.entries(api.integrations).forEach(([, integration]) => {
|
|
23
|
+
table.grantReadWriteData(integration.handler);
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
:::note
|
|
28
|
+
This example grants every handler in your API access. If only some handlers need access, configure them individually.
|
|
29
|
+
:::
|
|
30
|
+
</Fragment>
|
|
31
|
+
<Fragment slot="terraform">
|
|
32
|
+
|
|
33
|
+
Grant the Lambda execution role permission to access the DynamoDB table and its KMS encryption key:
|
|
34
|
+
|
|
35
|
+
```hcl title="packages/infra/src/main.tf"
|
|
36
|
+
module "my_table" {
|
|
37
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
resource "aws_iam_role_policy" "dynamodb_access" {
|
|
41
|
+
role = module.my_api.lambda_role_name
|
|
42
|
+
|
|
43
|
+
policy = jsonencode({
|
|
44
|
+
Version = "2012-10-17"
|
|
45
|
+
Statement = [
|
|
46
|
+
{
|
|
47
|
+
Effect = "Allow"
|
|
48
|
+
Action = [
|
|
49
|
+
"dynamodb:GetItem",
|
|
50
|
+
"dynamodb:PutItem",
|
|
51
|
+
"dynamodb:UpdateItem",
|
|
52
|
+
"dynamodb:DeleteItem",
|
|
53
|
+
"dynamodb:Query",
|
|
54
|
+
"dynamodb:Scan",
|
|
55
|
+
"dynamodb:BatchGetItem",
|
|
56
|
+
"dynamodb:BatchWriteItem",
|
|
57
|
+
]
|
|
58
|
+
Resource = [
|
|
59
|
+
module.my_table.table_arn,
|
|
60
|
+
"${module.my_table.table_arn}/index/*",
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
Effect = "Allow"
|
|
65
|
+
Action = [
|
|
66
|
+
"kms:Encrypt",
|
|
67
|
+
"kms:Decrypt",
|
|
68
|
+
"kms:ReEncrypt*",
|
|
69
|
+
"kms:GenerateDataKey*",
|
|
70
|
+
"kms:DescribeKey"
|
|
71
|
+
]
|
|
72
|
+
Resource = [module.my_table.kms_key_arn]
|
|
73
|
+
},
|
|
74
|
+
]
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
</Fragment>
|
|
80
|
+
</Infrastructure>
|
package/generators.json
CHANGED
|
@@ -349,6 +349,40 @@
|
|
|
349
349
|
"description": "Connect a ts#mcp-server to a ts#rdb project",
|
|
350
350
|
"metric": "g42",
|
|
351
351
|
"hidden": true
|
|
352
|
+
},
|
|
353
|
+
"ts#dynamodb": {
|
|
354
|
+
"factory": "./src/ts/dynamodb/generator",
|
|
355
|
+
"schema": "./src/ts/dynamodb/schema.json",
|
|
356
|
+
"description": "Create a DynamoDB project",
|
|
357
|
+
"metric": "g43"
|
|
358
|
+
},
|
|
359
|
+
"ts#dynamodb#trpc-connection": {
|
|
360
|
+
"factory": "./src/ts/dynamodb/trpc-connection/generator",
|
|
361
|
+
"schema": "./src/ts/dynamodb/trpc-connection/schema.json",
|
|
362
|
+
"description": "Connect a ts#trpc-api project to a ts#dynamodb project",
|
|
363
|
+
"metric": "g44",
|
|
364
|
+
"hidden": true
|
|
365
|
+
},
|
|
366
|
+
"ts#dynamodb#smithy-connection": {
|
|
367
|
+
"factory": "./src/ts/dynamodb/smithy-connection/generator",
|
|
368
|
+
"schema": "./src/ts/dynamodb/smithy-connection/schema.json",
|
|
369
|
+
"description": "Connect a Smithy backend to a ts#dynamodb project",
|
|
370
|
+
"metric": "g45",
|
|
371
|
+
"hidden": true
|
|
372
|
+
},
|
|
373
|
+
"ts#dynamodb#agent-connection": {
|
|
374
|
+
"factory": "./src/ts/dynamodb/agent-connection/generator",
|
|
375
|
+
"schema": "./src/ts/dynamodb/agent-connection/schema.json",
|
|
376
|
+
"description": "Connect a ts#agent to a ts#dynamodb project",
|
|
377
|
+
"metric": "g46",
|
|
378
|
+
"hidden": true
|
|
379
|
+
},
|
|
380
|
+
"ts#dynamodb#mcp-server-connection": {
|
|
381
|
+
"factory": "./src/ts/dynamodb/mcp-server-connection/generator",
|
|
382
|
+
"schema": "./src/ts/dynamodb/mcp-server-connection/schema.json",
|
|
383
|
+
"description": "Connect a ts#mcp-server to a ts#dynamodb project",
|
|
384
|
+
"metric": "g47",
|
|
385
|
+
"hidden": true
|
|
352
386
|
}
|
|
353
387
|
}
|
|
354
388
|
}
|
package/package.json
CHANGED
package/src/preset/schema.json
CHANGED
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"description": "Whether to configure git-secrets to prevent committing AWS credentials.",
|
|
24
24
|
"default": true
|
|
25
25
|
},
|
|
26
|
+
"mcp": {
|
|
27
|
+
"type": "boolean",
|
|
28
|
+
"description": "Whether to configure the Nx Plugin for AWS MCP server for use by coding agents.",
|
|
29
|
+
"default": true
|
|
30
|
+
},
|
|
26
31
|
"containers": {
|
|
27
32
|
"type": "string",
|
|
28
33
|
"description": "The container engine to use for build/push/login. 'infer' picks docker if installed, otherwise finch (falling back to docker when neither is installed).",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb#agent-connection",
|
|
4
|
+
"title": "ts#dynamodb#agent-connection",
|
|
5
|
+
"description": "Connect a ts#agent to a ts#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project containing the ts#agent to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#dynamodb project to connect to"
|
|
15
|
+
},
|
|
16
|
+
"sourceComponent": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The agent component name"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["sourceProject", "targetProject"]
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb#mcp-server-connection",
|
|
4
|
+
"title": "ts#dynamodb#mcp-server-connection",
|
|
5
|
+
"description": "Connect a ts#mcp-server to a ts#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project containing the ts#mcp-server to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#dynamodb project to connect to"
|
|
15
|
+
},
|
|
16
|
+
"sourceComponent": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The MCP server component name"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["sourceProject", "targetProject"]
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb",
|
|
4
|
+
"title": "ts#dynamodb",
|
|
5
|
+
"description": "Create a DynamoDB project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Name of the DynamoDB project to generate",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"x-priority": "important",
|
|
16
|
+
"x-prompt": "What name would you like your DynamoDB project to have? i.e: MyTable"
|
|
17
|
+
},
|
|
18
|
+
"directory": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The directory to store the project in.",
|
|
21
|
+
"default": "packages",
|
|
22
|
+
"x-priority": "important",
|
|
23
|
+
"x-prompt": "Which directory do you want to create the project in?"
|
|
24
|
+
},
|
|
25
|
+
"subDirectory": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "The sub directory the project is placed in. By default this is the project name.",
|
|
28
|
+
"x-prompt": "Which sub directory do you want to create the project in? (By default this is the project name)"
|
|
29
|
+
},
|
|
30
|
+
"tableName": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "The DynamoDB table name. Defaults to the project name."
|
|
33
|
+
},
|
|
34
|
+
"infra": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"enum": ["dynamodb", "none"],
|
|
37
|
+
"default": "dynamodb",
|
|
38
|
+
"description": "Infrastructure to provision for the DynamoDB table.",
|
|
39
|
+
"x-priority": "important",
|
|
40
|
+
"x-prompt": "Which infrastructure would you like to provision?"
|
|
41
|
+
},
|
|
42
|
+
"iac": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"description": "The preferred IaC provider. By default this is inherited from your initial selection.",
|
|
45
|
+
"enum": ["inherit", "cdk", "terraform"],
|
|
46
|
+
"x-priority": "important",
|
|
47
|
+
"default": "inherit",
|
|
48
|
+
"x-prompt": "Which provider would you like to manage your infrastructure? (default: Inherit)"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"required": ["name"]
|
|
52
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb#smithy-connection",
|
|
4
|
+
"title": "ts#dynamodb#smithy-connection",
|
|
5
|
+
"description": "Connect a Smithy backend to a ts#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The Smithy backend project to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#dynamodb project to connect to"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["sourceProject", "targetProject"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dynamodb#trpc-connection",
|
|
4
|
+
"title": "ts#dynamodb#trpc-connection",
|
|
5
|
+
"description": "Connect a ts#trpc-api project to a ts#dynamodb project",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The ts#trpc-api project to connect from"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The ts#dynamodb project to connect to"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["sourceProject", "targetProject"]
|
|
18
|
+
}
|