@aws/nx-plugin-mcp 1.0.0-rc.3 → 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 +34 -0
- 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
package/bin/aws-nx-mcp.js
CHANGED
|
@@ -19358,6 +19358,40 @@ var generators$1 = {
|
|
|
19358
19358
|
"description": "Connect a ts#mcp-server to a ts#rdb project",
|
|
19359
19359
|
"metric": "g42",
|
|
19360
19360
|
"hidden": true
|
|
19361
|
+
},
|
|
19362
|
+
"ts#dynamodb": {
|
|
19363
|
+
"factory": "./src/ts/dynamodb/generator",
|
|
19364
|
+
"schema": "./src/ts/dynamodb/schema.json",
|
|
19365
|
+
"description": "Create a DynamoDB project",
|
|
19366
|
+
"metric": "g43"
|
|
19367
|
+
},
|
|
19368
|
+
"ts#dynamodb#trpc-connection": {
|
|
19369
|
+
"factory": "./src/ts/dynamodb/trpc-connection/generator",
|
|
19370
|
+
"schema": "./src/ts/dynamodb/trpc-connection/schema.json",
|
|
19371
|
+
"description": "Connect a ts#trpc-api project to a ts#dynamodb project",
|
|
19372
|
+
"metric": "g44",
|
|
19373
|
+
"hidden": true
|
|
19374
|
+
},
|
|
19375
|
+
"ts#dynamodb#smithy-connection": {
|
|
19376
|
+
"factory": "./src/ts/dynamodb/smithy-connection/generator",
|
|
19377
|
+
"schema": "./src/ts/dynamodb/smithy-connection/schema.json",
|
|
19378
|
+
"description": "Connect a Smithy backend to a ts#dynamodb project",
|
|
19379
|
+
"metric": "g45",
|
|
19380
|
+
"hidden": true
|
|
19381
|
+
},
|
|
19382
|
+
"ts#dynamodb#agent-connection": {
|
|
19383
|
+
"factory": "./src/ts/dynamodb/agent-connection/generator",
|
|
19384
|
+
"schema": "./src/ts/dynamodb/agent-connection/schema.json",
|
|
19385
|
+
"description": "Connect a ts#agent to a ts#dynamodb project",
|
|
19386
|
+
"metric": "g46",
|
|
19387
|
+
"hidden": true
|
|
19388
|
+
},
|
|
19389
|
+
"ts#dynamodb#mcp-server-connection": {
|
|
19390
|
+
"factory": "./src/ts/dynamodb/mcp-server-connection/generator",
|
|
19391
|
+
"schema": "./src/ts/dynamodb/mcp-server-connection/schema.json",
|
|
19392
|
+
"description": "Connect a ts#mcp-server to a ts#dynamodb project",
|
|
19393
|
+
"metric": "g47",
|
|
19394
|
+
"hidden": true
|
|
19361
19395
|
}
|
|
19362
19396
|
};
|
|
19363
19397
|
//#endregion
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Smithy API to DynamoDB
|
|
3
|
+
description: Connect a Smithy API to a DynamoDB table
|
|
4
|
+
when:
|
|
5
|
+
sourceType: smithy
|
|
6
|
+
targetType: ts#dynamodb
|
|
7
|
+
---
|
|
8
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
9
|
+
import Link from '@components/link.astro';
|
|
10
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
11
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import Snippet from '@components/snippet.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator wires a <Link path="guides/ts-smithy-api">Smithy API</Link> to a <Link path="guides/ts-dynamodb">DynamoDB</Link> project, configuring local development so both start together automatically.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using this generator, ensure you have:
|
|
20
|
+
|
|
21
|
+
1. A <Link path="guides/ts-smithy-api">`ts#smithy-api`</Link> project (TypeScript backend)
|
|
22
|
+
2. A <Link path="guides/ts-dynamodb">`ts#dynamodb`</Link> project
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Run the Generator
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="connection" />
|
|
29
|
+
|
|
30
|
+
Select your Smithy API backend project as the source and your DynamoDB project as the target.
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
<GeneratorParameters generator="connection" />
|
|
35
|
+
|
|
36
|
+
## Generator Output
|
|
37
|
+
|
|
38
|
+
The generator updates your Smithy API's `project.json` to add a dependency from its `serve-local` target to the DynamoDB project's `serve-local` target. No source files are modified.
|
|
39
|
+
|
|
40
|
+
## Using DynamoDB in Operations
|
|
41
|
+
|
|
42
|
+
Import entity factories from the DynamoDB package and use them inside your operation implementations:
|
|
43
|
+
|
|
44
|
+
```ts title="packages/api/src/operations/list-examples.ts"
|
|
45
|
+
import { createExampleEntity } from ':my-scope/my-table';
|
|
46
|
+
import {
|
|
47
|
+
ListExamplesOperationInput,
|
|
48
|
+
ListExamplesOperationOutput,
|
|
49
|
+
} from '../generated/ssdk/index.js';
|
|
50
|
+
import { ServiceContext } from '../context.js';
|
|
51
|
+
|
|
52
|
+
export const listExamples = async (
|
|
53
|
+
_input: ListExamplesOperationInput,
|
|
54
|
+
_ctx: ServiceContext,
|
|
55
|
+
): Promise<ListExamplesOperationOutput> => {
|
|
56
|
+
const entity = await createExampleEntity();
|
|
57
|
+
const result = await entity.scan.go();
|
|
58
|
+
return { items: result.data };
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Infrastructure
|
|
63
|
+
|
|
64
|
+
<Snippet name="connection/lambda-dynamodb-access" />
|
|
65
|
+
|
|
66
|
+
## Local Development
|
|
67
|
+
|
|
68
|
+
<Snippet name="connection/dynamodb-local-development" />
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: tRPC API to DynamoDB
|
|
3
|
+
description: Connect a tRPC API to a DynamoDB table
|
|
4
|
+
when:
|
|
5
|
+
sourceType: ts#trpc-api
|
|
6
|
+
targetType: ts#dynamodb
|
|
7
|
+
---
|
|
8
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
9
|
+
import Link from '@components/link.astro';
|
|
10
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
11
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import Snippet from '@components/snippet.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator wires a <Link path="guides/trpc">tRPC API</Link> to a <Link path="guides/ts-dynamodb">DynamoDB</Link> project, configuring local development so both start together automatically.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using this generator, ensure you have:
|
|
20
|
+
|
|
21
|
+
1. A <Link path="guides/trpc">`ts#trpc-api`</Link> project
|
|
22
|
+
2. A <Link path="guides/ts-dynamodb">`ts#dynamodb`</Link> project
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Run the Generator
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="connection" />
|
|
29
|
+
|
|
30
|
+
Select your tRPC API project as the source and your DynamoDB project as the target.
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
<GeneratorParameters generator="connection" />
|
|
35
|
+
|
|
36
|
+
## Generator Output
|
|
37
|
+
|
|
38
|
+
The generator updates your tRPC API's `project.json` to add a dependency from its `serve-local` target to the DynamoDB project's `serve-local` target. No source files are modified.
|
|
39
|
+
|
|
40
|
+
## Using DynamoDB in Procedures
|
|
41
|
+
|
|
42
|
+
Import entity factories from the DynamoDB package and use them inside your tRPC procedures:
|
|
43
|
+
|
|
44
|
+
```ts title="packages/api/src/procedures/example.ts"
|
|
45
|
+
import { createExampleEntity } from ':my-scope/my-table';
|
|
46
|
+
import { publicProcedure } from '../init.js';
|
|
47
|
+
|
|
48
|
+
export const listExamples = publicProcedure
|
|
49
|
+
.query(async () => {
|
|
50
|
+
const entity = await createExampleEntity();
|
|
51
|
+
const result = await entity.scan.go();
|
|
52
|
+
return result.data;
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Infrastructure
|
|
57
|
+
|
|
58
|
+
<Snippet name="connection/lambda-dynamodb-access" />
|
|
59
|
+
|
|
60
|
+
## Local Development
|
|
61
|
+
|
|
62
|
+
<Snippet name="connection/dynamodb-local-development" />
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TypeScript Agent to DynamoDB
|
|
3
|
+
description: Connect a TypeScript Agent to a DynamoDB table
|
|
4
|
+
when:
|
|
5
|
+
sourceType: ts#agent
|
|
6
|
+
targetType: ts#dynamodb
|
|
7
|
+
---
|
|
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 NxCommands from '@components/nx-commands.astro';
|
|
12
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
13
|
+
import Snippet from '@components/snippet.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator wires a <Link path="guides/ts-agent">TypeScript Agent</Link> to a <Link path="guides/ts-dynamodb">DynamoDB</Link> project, configuring local development so both start together automatically.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using this generator, ensure you have:
|
|
20
|
+
|
|
21
|
+
1. A <Link path="guides/ts-agent">`ts#agent`</Link> project
|
|
22
|
+
2. A <Link path="guides/ts-dynamodb">`ts#dynamodb`</Link> project
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Run the Generator
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="connection" />
|
|
29
|
+
|
|
30
|
+
Select your Agent project as the source and your DynamoDB project as the target. If the project contains multiple agent components, specify `sourceComponent` to disambiguate.
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
<GeneratorParameters generator="connection" />
|
|
35
|
+
|
|
36
|
+
## Generator Output
|
|
37
|
+
|
|
38
|
+
The generator updates the agent's `<agent-name>-serve-local` target in `project.json` to depend on the DynamoDB project's `serve-local` target. No source files are modified.
|
|
39
|
+
|
|
40
|
+
## Using DynamoDB in Agents
|
|
41
|
+
|
|
42
|
+
Import entity factories from the DynamoDB package and use them inside your agent definition:
|
|
43
|
+
|
|
44
|
+
```ts title="packages/my-service/src/my-agent/agent.ts"
|
|
45
|
+
import { createExampleEntity } from ':my-scope/my-table';
|
|
46
|
+
|
|
47
|
+
export const getAgent = async () => {
|
|
48
|
+
// ...
|
|
49
|
+
return new Agent({
|
|
50
|
+
tools: [
|
|
51
|
+
tool({
|
|
52
|
+
name: 'list_examples',
|
|
53
|
+
description: 'List all example items',
|
|
54
|
+
func: async () => {
|
|
55
|
+
const entity = await createExampleEntity();
|
|
56
|
+
const result = await entity.scan.go();
|
|
57
|
+
return result.data;
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Infrastructure
|
|
66
|
+
|
|
67
|
+
To allow the agent's Lambda function to access the DynamoDB table, grant the necessary permissions in your infrastructure.
|
|
68
|
+
|
|
69
|
+
<Infrastructure>
|
|
70
|
+
<Fragment slot="cdk">
|
|
71
|
+
|
|
72
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
73
|
+
import { MyTable } from ':my-scope/common-constructs';
|
|
74
|
+
|
|
75
|
+
const table = new MyTable(this, 'Table');
|
|
76
|
+
const myAgent = new MyAgent(this, 'MyAgent');
|
|
77
|
+
|
|
78
|
+
table.grantReadWriteData(myAgent);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`grantReadWriteData` grants both the DynamoDB and KMS permissions to the agent's execution role.
|
|
82
|
+
</Fragment>
|
|
83
|
+
<Fragment slot="terraform">
|
|
84
|
+
|
|
85
|
+
```hcl title="packages/infra/src/main.tf"
|
|
86
|
+
module "my_table" {
|
|
87
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
resource "aws_iam_role_policy" "dynamodb_access" {
|
|
91
|
+
role = module.my_agent.lambda_role_name
|
|
92
|
+
|
|
93
|
+
policy = jsonencode({
|
|
94
|
+
Version = "2012-10-17"
|
|
95
|
+
Statement = [
|
|
96
|
+
{
|
|
97
|
+
Effect = "Allow"
|
|
98
|
+
Action = [
|
|
99
|
+
"dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:UpdateItem",
|
|
100
|
+
"dynamodb:DeleteItem", "dynamodb:Query", "dynamodb:Scan",
|
|
101
|
+
"dynamodb:BatchGetItem", "dynamodb:BatchWriteItem",
|
|
102
|
+
]
|
|
103
|
+
Resource = [
|
|
104
|
+
module.my_table.table_arn,
|
|
105
|
+
"${module.my_table.table_arn}/index/*",
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
Effect = "Allow"
|
|
110
|
+
Action = [
|
|
111
|
+
"kms:Encrypt",
|
|
112
|
+
"kms:Decrypt",
|
|
113
|
+
"kms:ReEncrypt*",
|
|
114
|
+
"kms:GenerateDataKey*",
|
|
115
|
+
"kms:DescribeKey"
|
|
116
|
+
]
|
|
117
|
+
Resource = [module.my_table.kms_key_arn]
|
|
118
|
+
},
|
|
119
|
+
]
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
</Fragment>
|
|
124
|
+
</Infrastructure>
|
|
125
|
+
|
|
126
|
+
## Local Development
|
|
127
|
+
|
|
128
|
+
<Snippet name="connection/dynamodb-local-development" />
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: MCP Server to DynamoDB
|
|
3
|
+
description: Connect a TypeScript MCP Server to a DynamoDB table
|
|
4
|
+
when:
|
|
5
|
+
sourceType: ts#mcp-server
|
|
6
|
+
targetType: ts#dynamodb
|
|
7
|
+
---
|
|
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 NxCommands from '@components/nx-commands.astro';
|
|
12
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
13
|
+
import Snippet from '@components/snippet.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator wires a <Link path="guides/ts-mcp-server">TypeScript MCP Server</Link> to a <Link path="guides/ts-dynamodb">DynamoDB</Link> project, configuring local development so both start together automatically.
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
Before using this generator, ensure you have:
|
|
20
|
+
|
|
21
|
+
1. A <Link path="guides/ts-mcp-server">`ts#mcp-server`</Link> project
|
|
22
|
+
2. A <Link path="guides/ts-dynamodb">`ts#dynamodb`</Link> project
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Run the Generator
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="connection" />
|
|
29
|
+
|
|
30
|
+
Select your MCP server project as the source and your DynamoDB project as the target. If the project contains multiple MCP server components, specify `sourceComponent` to disambiguate.
|
|
31
|
+
|
|
32
|
+
### Options
|
|
33
|
+
|
|
34
|
+
<GeneratorParameters generator="connection" />
|
|
35
|
+
|
|
36
|
+
## Generator Output
|
|
37
|
+
|
|
38
|
+
The generator updates the MCP server's `<mcp-server-name>-serve-local` target in `project.json` to depend on the DynamoDB project's `serve-local` target. No source files are modified.
|
|
39
|
+
|
|
40
|
+
## Using DynamoDB in Tools
|
|
41
|
+
|
|
42
|
+
Import entity factories from the DynamoDB package and use them inside `createServer`:
|
|
43
|
+
|
|
44
|
+
```ts title="packages/my-service/src/my-mcp/server.ts"
|
|
45
|
+
import { createExampleEntity } from ':my-scope/my-table';
|
|
46
|
+
|
|
47
|
+
export const createServer = async () => {
|
|
48
|
+
const server = new McpServer({ name: 'my-service', version: '1.0.0' });
|
|
49
|
+
|
|
50
|
+
server.tool('list_examples', 'List all example items', {}, async () => {
|
|
51
|
+
const entity = await createExampleEntity();
|
|
52
|
+
const result = await entity.scan.go();
|
|
53
|
+
return {
|
|
54
|
+
content: [{ type: 'text', text: JSON.stringify(result.data) }],
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return server;
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Infrastructure
|
|
63
|
+
|
|
64
|
+
To allow the MCP server to access the DynamoDB table, grant the necessary permissions in your infrastructure.
|
|
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
|
+
const myMcpServer = new MyMcpServer(this, 'MyMcpServer');
|
|
74
|
+
|
|
75
|
+
table.grantReadWriteData(myMcpServer);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`grantReadWriteData` grants both the DynamoDB and KMS permissions to the MCP server's execution role.
|
|
79
|
+
</Fragment>
|
|
80
|
+
<Fragment slot="terraform">
|
|
81
|
+
|
|
82
|
+
```hcl title="packages/infra/src/main.tf"
|
|
83
|
+
module "my_table" {
|
|
84
|
+
source = "../../common/terraform/src/app/dynamodb/my-table"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
resource "aws_iam_role_policy" "dynamodb_access" {
|
|
88
|
+
role = module.my_mcp_server.lambda_role_name
|
|
89
|
+
|
|
90
|
+
policy = jsonencode({
|
|
91
|
+
Version = "2012-10-17"
|
|
92
|
+
Statement = [
|
|
93
|
+
{
|
|
94
|
+
Effect = "Allow"
|
|
95
|
+
Action = [
|
|
96
|
+
"dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:UpdateItem",
|
|
97
|
+
"dynamodb:DeleteItem", "dynamodb:Query", "dynamodb:Scan",
|
|
98
|
+
"dynamodb:BatchGetItem", "dynamodb:BatchWriteItem",
|
|
99
|
+
]
|
|
100
|
+
Resource = [
|
|
101
|
+
module.my_table.table_arn,
|
|
102
|
+
"${module.my_table.table_arn}/index/*",
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
Effect = "Allow"
|
|
107
|
+
Action = [
|
|
108
|
+
"kms:Encrypt",
|
|
109
|
+
"kms:Decrypt",
|
|
110
|
+
"kms:ReEncrypt*",
|
|
111
|
+
"kms:GenerateDataKey*",
|
|
112
|
+
"kms:DescribeKey",
|
|
113
|
+
]
|
|
114
|
+
Resource = [module.my_table.kms_key_arn]
|
|
115
|
+
},
|
|
116
|
+
]
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
</Fragment>
|
|
121
|
+
</Infrastructure>
|
|
122
|
+
|
|
123
|
+
## Local Development
|
|
124
|
+
|
|
125
|
+
<Snippet name="connection/dynamodb-local-development" />
|
|
@@ -119,6 +119,35 @@ The Connection generator supports the following connections:
|
|
|
119
119
|
source="mcp"
|
|
120
120
|
target="aurora"
|
|
121
121
|
/>
|
|
122
|
+
<ConnectionCard
|
|
123
|
+
title="tRPC API to DynamoDB"
|
|
124
|
+
description="Connect a tRPC API to a DynamoDB table"
|
|
125
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-dynamodb`}
|
|
126
|
+
source="trpc"
|
|
127
|
+
target="dynamodb"
|
|
128
|
+
/>
|
|
129
|
+
<ConnectionCard
|
|
130
|
+
title="Smithy API to DynamoDB"
|
|
131
|
+
description="Connect a Smithy API to a DynamoDB table"
|
|
132
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-dynamodb`}
|
|
133
|
+
source="smithy"
|
|
134
|
+
target="dynamodb"
|
|
135
|
+
/>
|
|
136
|
+
<ConnectionCard
|
|
137
|
+
title="TypeScript Agent to DynamoDB"
|
|
138
|
+
description="Connect a TypeScript Agent to a DynamoDB table"
|
|
139
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-dynamodb`}
|
|
140
|
+
source="strands"
|
|
141
|
+
sourceBadge="typescript"
|
|
142
|
+
target="dynamodb"
|
|
143
|
+
/>
|
|
144
|
+
<ConnectionCard
|
|
145
|
+
title="MCP Server to DynamoDB"
|
|
146
|
+
description="Connect a TypeScript MCP Server to a DynamoDB table"
|
|
147
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-dynamodb`}
|
|
148
|
+
source="mcp"
|
|
149
|
+
target="dynamodb"
|
|
150
|
+
/>
|
|
122
151
|
</CardGrid>
|
|
123
152
|
|
|
124
153
|
:::note[Runtime Configuration]
|
|
@@ -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
|
+
}
|