@aws/nx-plugin-mcp 1.0.0-rc.3 → 1.0.0-rc.30
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 +4312 -3360
- package/docs/guides/agentcore-gateway.mdx +376 -0
- package/docs/guides/connection/agentcore-gateway-gateway.mdx +154 -0
- package/docs/guides/connection/agentcore-gateway-mcp.mdx +134 -0
- package/docs/guides/connection/py-agent-a2a.mdx +47 -15
- package/docs/guides/connection/py-agent-dynamodb.mdx +116 -0
- package/docs/guides/connection/py-agent-gateway.mdx +176 -0
- package/docs/guides/connection/py-agent-mcp.mdx +42 -13
- 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/react-agui.mdx +4 -4
- package/docs/guides/connection/react-fastapi.mdx +2 -2
- package/docs/guides/connection/react-py-agent.mdx +3 -3
- package/docs/guides/connection/react-smithy.mdx +3 -3
- package/docs/guides/connection/react-trpc.mdx +1 -1
- package/docs/guides/connection/react-ts-agent.mdx +5 -5
- package/docs/guides/connection/smithy-dynamodb.mdx +68 -0
- package/docs/guides/connection/smithy-rdb.mdx +4 -4
- package/docs/guides/connection/trpc-dynamodb.mdx +62 -0
- package/docs/guides/connection/trpc-rdb.mdx +4 -4
- package/docs/guides/connection/ts-agent-a2a.mdx +12 -9
- package/docs/guides/connection/ts-agent-dynamodb.mdx +128 -0
- package/docs/guides/connection/ts-agent-gateway.mdx +141 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +11 -8
- package/docs/guides/connection/ts-agent-rdb.mdx +3 -3
- package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +125 -0
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +3 -3
- package/docs/guides/connection.mdx +101 -0
- package/docs/guides/docker-bundling.mdx +13 -7
- package/docs/guides/fastapi.mdx +244 -4
- package/docs/guides/license.mdx +264 -109
- package/docs/guides/local-development.mdx +87 -0
- package/docs/guides/nx-generator.mdx +7 -2
- package/docs/guides/py-agent.mdx +204 -44
- package/docs/guides/py-dynamodb.mdx +476 -0
- package/docs/guides/py-mcp-server.mdx +57 -2
- package/docs/guides/react-website-auth.mdx +58 -1
- package/docs/guides/react-website.mdx +87 -19
- package/docs/guides/terraform-project.mdx +1 -1
- package/docs/guides/trpc.mdx +45 -9
- package/docs/guides/ts-agent.mdx +120 -6
- package/docs/guides/ts-dynamodb.mdx +187 -0
- package/docs/guides/ts-mcp-server.mdx +62 -2
- package/docs/guides/ts-rdb.mdx +98 -20
- package/docs/guides/ts-smithy-api.mdx +183 -4
- package/docs/guides/typescript-infrastructure.mdx +9 -1
- package/docs/guides/typescript-project.mdx +5 -10
- package/docs/guides/workspace.mdx +8 -2
- package/docs/snippets/agent/bedrock-deployment.mdx +4 -0
- package/docs/snippets/api/access-logging.mdx +33 -0
- package/docs/snippets/api/type-safe-api-integrations.mdx +31 -0
- package/docs/snippets/api/waf-configuration.mdx +1 -1
- package/docs/snippets/connection/dynamodb-local-development.mdx +7 -0
- package/docs/snippets/connection/lambda-dynamodb-access.mdx +80 -0
- 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/local-dev-start.mdx +13 -0
- package/docs/snippets/dynamodb/local-dev-windows.mdx +15 -0
- package/docs/snippets/mcp/bedrock-deployment.mdx +4 -0
- package/docs/snippets/mcp/config.mdx +2 -1
- package/docs/snippets/required-prerequisites.mdx +1 -1
- package/generators.json +100 -1
- package/package.json +1 -1
- package/src/agentcore-gateway/gateway-connection/schema.json +31 -0
- package/src/agentcore-gateway/mcp-connection/schema.json +31 -0
- package/src/agentcore-gateway/schema.json +70 -0
- package/src/connection/schema.json +5 -0
- package/src/infra/app/schema.json +5 -0
- package/src/license/schema.json +11 -0
- package/src/preset/schema.json +10 -5
- package/src/py/agent/a2a-connection/schema.json +5 -0
- package/src/py/agent/gateway-connection/schema.json +31 -0
- package/src/py/agent/mcp-connection/schema.json +5 -0
- package/src/py/agent/react-connection/schema.json +5 -0
- package/src/py/agent/schema.json +6 -1
- package/src/py/api/schema.json +5 -0
- package/src/py/dynamodb/agent-connection/schema.json +27 -0
- package/src/py/dynamodb/fast-api-connection/schema.json +23 -0
- package/src/py/dynamodb/mcp-server-connection/schema.json +27 -0
- package/src/py/dynamodb/schema.json +75 -0
- package/src/py/fast-api/react/schema.json +5 -0
- package/src/py/fast-api/schema.json +5 -0
- package/src/py/lambda-function/schema.json +5 -0
- package/src/py/mcp-server/schema.json +5 -0
- package/src/py/project/schema.json +5 -0
- package/src/smithy/project/schema.json +5 -0
- package/src/smithy/react-connection/schema.json +5 -0
- package/src/smithy/ts/api/schema.json +5 -0
- package/src/terraform/project/schema.json +5 -0
- package/src/trpc/backend/schema.json +5 -0
- package/src/trpc/react/schema.json +5 -0
- package/src/ts/agent/a2a-connection/schema.json +5 -0
- package/src/ts/agent/gateway-connection/schema.json +31 -0
- package/src/ts/agent/mcp-connection/schema.json +5 -0
- package/src/ts/agent/react-connection/schema.json +5 -0
- package/src/ts/agent/schema.json +5 -0
- package/src/ts/api/schema.json +5 -0
- package/src/ts/astro-docs/schema.json +3 -3
- package/src/ts/docs/schema.json +3 -3
- package/src/ts/dynamodb/agent-connection/schema.json +27 -0
- package/src/ts/dynamodb/mcp-server-connection/schema.json +27 -0
- package/src/ts/dynamodb/schema.json +75 -0
- package/src/ts/dynamodb/smithy-connection/schema.json +23 -0
- package/src/ts/dynamodb/trpc-connection/schema.json +23 -0
- package/src/ts/lambda-function/schema.json +5 -0
- package/src/ts/lib/schema.json +5 -0
- package/src/ts/mcp-server/schema.json +5 -0
- package/src/ts/nx-generator/schema.json +5 -0
- package/src/ts/nx-plugin/schema.json +5 -0
- package/src/ts/rdb/agent-connection/schema.json +5 -0
- package/src/ts/rdb/mcp-server-connection/schema.json +5 -0
- package/src/ts/rdb/schema.json +5 -0
- package/src/ts/rdb/smithy-connection/schema.json +5 -0
- package/src/ts/rdb/trpc-connection/schema.json +5 -0
- package/src/ts/react-website/app/schema.json +11 -6
- package/src/ts/react-website/cognito-auth/schema.json +5 -0
- package/src/ts/react-website/runtime-config/schema.json +5 -0
- package/src/ts/website/app/schema.json +11 -6
- package/src/ts/website/auth/schema.json +5 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TypeScript DynamoDB
|
|
3
|
+
description: Create a TypeScript DynamoDB project
|
|
4
|
+
generator: ts#dynamodb
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
import { FileTree, CardGrid } from '@astrojs/starlight/components';
|
|
8
|
+
import Astro from '@astrojs/react';
|
|
9
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
10
|
+
import Link from '@components/link.astro';
|
|
11
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
12
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
13
|
+
import Snippet from '@components/snippet.astro';
|
|
14
|
+
|
|
15
|
+
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
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Generate a TypeScript DynamoDB Project
|
|
20
|
+
|
|
21
|
+
<RunGenerator generator="ts#dynamodb" />
|
|
22
|
+
|
|
23
|
+
### Options
|
|
24
|
+
|
|
25
|
+
<GeneratorParameters generator="ts#dynamodb" />
|
|
26
|
+
|
|
27
|
+
## Generator Output
|
|
28
|
+
|
|
29
|
+
The generator creates the following project structure in the `<directory>/<name>` directory:
|
|
30
|
+
|
|
31
|
+
<FileTree>
|
|
32
|
+
- src
|
|
33
|
+
- index.ts Project entry point and exports
|
|
34
|
+
- client.ts DynamoDB client singleton and table name resolution
|
|
35
|
+
- entities
|
|
36
|
+
- example.ts Example ElectroDB entity definition
|
|
37
|
+
- index.ts Entity exports
|
|
38
|
+
- config.json Table configuration including GSI definitions and local development settings
|
|
39
|
+
- project.json Project configuration and build targets
|
|
40
|
+
</FileTree>
|
|
41
|
+
|
|
42
|
+
The local development scripts are shared across all DynamoDB projects (both TypeScript and Python) and generated once into:
|
|
43
|
+
|
|
44
|
+
<FileTree>
|
|
45
|
+
- packages/common/scripts/src/dynamodb
|
|
46
|
+
- create-local-table.ts Creates the DynamoDB table in the local DynamoDB Local instance
|
|
47
|
+
- pull-image.ts Pulls the DynamoDB Local image
|
|
48
|
+
- start-container.ts Starts the DynamoDB Local container
|
|
49
|
+
</FileTree>
|
|
50
|
+
|
|
51
|
+
### Infrastructure
|
|
52
|
+
|
|
53
|
+
<Snippet name="dynamodb/infrastructure" />
|
|
54
|
+
|
|
55
|
+
## Local Development
|
|
56
|
+
|
|
57
|
+
### Starting Local DynamoDB
|
|
58
|
+
|
|
59
|
+
<Snippet name="dynamodb/local-dev-start" />
|
|
60
|
+
|
|
61
|
+
### Data Modelling
|
|
62
|
+
|
|
63
|
+
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.
|
|
64
|
+
|
|
65
|
+
Example entity definition:
|
|
66
|
+
|
|
67
|
+
```ts title="packages/my-table/src/entities/example.ts"
|
|
68
|
+
import { Entity } from 'electrodb';
|
|
69
|
+
import { getDynamoDBClient, resolveTableName } from '../client.js';
|
|
70
|
+
|
|
71
|
+
export const createExampleEntity = async () =>
|
|
72
|
+
new Entity(
|
|
73
|
+
{
|
|
74
|
+
model: {
|
|
75
|
+
entity: 'example',
|
|
76
|
+
version: '1',
|
|
77
|
+
service: 'MyTable',
|
|
78
|
+
},
|
|
79
|
+
attributes: {
|
|
80
|
+
id: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
required: true,
|
|
83
|
+
},
|
|
84
|
+
createdAt: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
required: true,
|
|
87
|
+
default: () => new Date().toISOString(),
|
|
88
|
+
readOnly: true,
|
|
89
|
+
},
|
|
90
|
+
updatedAt: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
required: true,
|
|
93
|
+
default: () => new Date().toISOString(),
|
|
94
|
+
watch: '*',
|
|
95
|
+
set: () => new Date().toISOString(),
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
indexes: {
|
|
99
|
+
primary: {
|
|
100
|
+
pk: {
|
|
101
|
+
field: 'pk',
|
|
102
|
+
composite: ['id'],
|
|
103
|
+
},
|
|
104
|
+
sk: {
|
|
105
|
+
field: 'sk',
|
|
106
|
+
composite: [],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{ client: getDynamoDBClient(), table: await resolveTableName() },
|
|
112
|
+
);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
For more details, see the [ElectroDB entity documentation](https://electrodb.dev/en/modeling/entities/).
|
|
116
|
+
|
|
117
|
+
### Using the DynamoDB Client
|
|
118
|
+
|
|
119
|
+
The generated `src/client.ts` exports two key utilities:
|
|
120
|
+
|
|
121
|
+
- `getDynamoDBClient()` — returns a cached singleton `DynamoDBClient`. When `LOCAL_DEV=true`, connects to the local DynamoDB Local instance; otherwise creates an AWS client using the default credential chain.
|
|
122
|
+
- `resolveTableName()` — returns the DynamoDB table name. When `LOCAL_DEV=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.
|
|
123
|
+
|
|
124
|
+
### Stopping Local DynamoDB
|
|
125
|
+
|
|
126
|
+
<Snippet name="dynamodb/local-dev-windows" />
|
|
127
|
+
|
|
128
|
+
## Adding/Removing Global Secondary Indexes
|
|
129
|
+
|
|
130
|
+
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:
|
|
131
|
+
|
|
132
|
+
<Snippet name="dynamodb/gsi-config" parentHeading="Adding/Removing Global Secondary Indexes" />
|
|
133
|
+
|
|
134
|
+
## Connecting to the Table
|
|
135
|
+
|
|
136
|
+
In any TypeScript project, import entity factories from your DynamoDB package and use them directly:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { createExampleEntity } from ':my-scope/my-table';
|
|
140
|
+
|
|
141
|
+
const entity = await createExampleEntity();
|
|
142
|
+
const result = await entity.query.primary({ id: '123' }).go();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
:::note[Runtime config]
|
|
146
|
+
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>.
|
|
147
|
+
:::
|
|
148
|
+
|
|
149
|
+
## Deploying your Table
|
|
150
|
+
|
|
151
|
+
<Snippet name="dynamodb/deploying-table" parentHeading="Deploying your Table" />
|
|
152
|
+
|
|
153
|
+
## Connections
|
|
154
|
+
|
|
155
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
156
|
+
|
|
157
|
+
<CardGrid>
|
|
158
|
+
<ConnectionCard
|
|
159
|
+
title="tRPC API to TypeScript DynamoDB"
|
|
160
|
+
description="Connect a tRPC API to a DynamoDB table"
|
|
161
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-dynamodb`}
|
|
162
|
+
source="trpc"
|
|
163
|
+
target="dynamodb"
|
|
164
|
+
/>
|
|
165
|
+
<ConnectionCard
|
|
166
|
+
title="Smithy API to TypeScript DynamoDB"
|
|
167
|
+
description="Connect a Smithy API to a DynamoDB table"
|
|
168
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-dynamodb`}
|
|
169
|
+
source="smithy"
|
|
170
|
+
target="dynamodb"
|
|
171
|
+
/>
|
|
172
|
+
<ConnectionCard
|
|
173
|
+
title="TypeScript Agent to TypeScript DynamoDB"
|
|
174
|
+
description="Connect a TypeScript Agent to a DynamoDB table"
|
|
175
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-dynamodb`}
|
|
176
|
+
source="strands"
|
|
177
|
+
sourceBadge="typescript"
|
|
178
|
+
target="dynamodb"
|
|
179
|
+
/>
|
|
180
|
+
<ConnectionCard
|
|
181
|
+
title="MCP Server to TypeScript DynamoDB"
|
|
182
|
+
description="Connect a TypeScript MCP Server to a DynamoDB table"
|
|
183
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-dynamodb`}
|
|
184
|
+
source="mcp"
|
|
185
|
+
target="dynamodb"
|
|
186
|
+
/>
|
|
187
|
+
</CardGrid>
|
|
@@ -4,7 +4,9 @@ description: Generate a TypeScript Model Context Protocol (MCP) server for provi
|
|
|
4
4
|
generator: ts#mcp-server
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import { FileTree, CardGrid } from '@astrojs/starlight/components';
|
|
8
|
+
import Astro from '@astrojs/react';
|
|
9
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
8
10
|
import RunGenerator from '@components/run-generator.astro';
|
|
9
11
|
import NxCommands from '@components/nx-commands.astro';
|
|
10
12
|
import Link from '@components/link.astro';
|
|
@@ -120,14 +122,28 @@ server.registerResource('dynamic-resource', 'dynamic://resource', {}, async (uri
|
|
|
120
122
|
|
|
121
123
|
## Running Your MCP Server
|
|
122
124
|
|
|
125
|
+
### Local Development
|
|
126
|
+
|
|
127
|
+
To run your MCP server (and everything connected to it, such as a local database) locally, use the project's `dev` target:
|
|
128
|
+
|
|
129
|
+
<NxCommands commands={['dev your-project']} />
|
|
130
|
+
|
|
131
|
+
If you have added multiple components to your project (MCP servers, agents, etc.), this starts them all. To run just this MCP server, target its `<your-server-name>-dev` target:
|
|
132
|
+
|
|
133
|
+
<NxCommands commands={['your-server-name-dev your-project']} />
|
|
134
|
+
|
|
123
135
|
### Inspector
|
|
124
136
|
|
|
125
|
-
The generator configures a target named `<your-server-name>-inspect`, which starts the [MCP Inspector](https://github.com/modelcontextprotocol/inspector)
|
|
137
|
+
The generator configures a target named `<your-server-name>-inspect`, which starts your MCP server locally (via the `<your-server-name>-dev` target, including any connected dependencies such as a local database) and launches the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) pre-configured to connect to it over Streamable HTTP transport.
|
|
126
138
|
|
|
127
139
|
<NxCommands commands={['your-server-name-inspect your-project']} />
|
|
128
140
|
|
|
129
141
|
This will start the inspector at `http://localhost:6274`. Get started by clicking on the "Connect" button.
|
|
130
142
|
|
|
143
|
+
:::tip
|
|
144
|
+
To inspect the server using STDIO transport instead, use the `<your-server-name>-inspect-stdio` target, which launches the inspector against a STDIO instance of your server.
|
|
145
|
+
:::
|
|
146
|
+
|
|
131
147
|
### STDIO
|
|
132
148
|
|
|
133
149
|
The easiest way to test and use an MCP server is by using the inspector or configuring it with an AI assistant (as above).
|
|
@@ -167,3 +183,47 @@ A `docker` target is also generated which prepares the docker context for all MC
|
|
|
167
183
|
|
|
168
184
|
<Snippet name="mcp/observability" parentHeading="Observability" />
|
|
169
185
|
</OptionFilter>
|
|
186
|
+
|
|
187
|
+
## Connections
|
|
188
|
+
|
|
189
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
190
|
+
|
|
191
|
+
<CardGrid>
|
|
192
|
+
<ConnectionCard
|
|
193
|
+
title="TypeScript Agent to MCP"
|
|
194
|
+
description="Connect a TypeScript Agent to an MCP server"
|
|
195
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-mcp`}
|
|
196
|
+
source="strands"
|
|
197
|
+
sourceBadge="typescript"
|
|
198
|
+
target="mcp"
|
|
199
|
+
/>
|
|
200
|
+
<ConnectionCard
|
|
201
|
+
title="Python Agent to MCP"
|
|
202
|
+
description="Connect a Python Agent to an MCP server"
|
|
203
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-agent-mcp`}
|
|
204
|
+
source="strands"
|
|
205
|
+
sourceBadge="python"
|
|
206
|
+
target="mcp"
|
|
207
|
+
/>
|
|
208
|
+
<ConnectionCard
|
|
209
|
+
title="MCP Server to Relational Database"
|
|
210
|
+
description="Connect a TypeScript MCP Server to an Aurora relational database"
|
|
211
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-rdb`}
|
|
212
|
+
source="mcp"
|
|
213
|
+
target="aurora"
|
|
214
|
+
/>
|
|
215
|
+
<ConnectionCard
|
|
216
|
+
title="MCP Server to TypeScript DynamoDB"
|
|
217
|
+
description="Connect a TypeScript MCP Server to a DynamoDB table"
|
|
218
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-dynamodb`}
|
|
219
|
+
source="mcp"
|
|
220
|
+
target="dynamodb"
|
|
221
|
+
/>
|
|
222
|
+
<ConnectionCard
|
|
223
|
+
title="AgentCore Gateway to MCP Server"
|
|
224
|
+
description="Aggregate an MCP server behind an AgentCore Gateway"
|
|
225
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-mcp`}
|
|
226
|
+
source="agentcore"
|
|
227
|
+
target="mcp"
|
|
228
|
+
/>
|
|
229
|
+
</CardGrid>
|
package/docs/guides/ts-rdb.mdx
CHANGED
|
@@ -4,7 +4,9 @@ description: Create a relational database project
|
|
|
4
4
|
generator: ts#rdb
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import { FileTree, CardGrid } from '@astrojs/starlight/components';
|
|
8
|
+
import Astro from '@astrojs/react';
|
|
9
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
8
10
|
import Link from '@components/link.astro';
|
|
9
11
|
import RunGenerator from '@components/run-generator.astro';
|
|
10
12
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
@@ -37,23 +39,29 @@ The generator will create the following project structure in the `<directory>/<n
|
|
|
37
39
|
- models
|
|
38
40
|
- example.prisma Example model definition
|
|
39
41
|
- schema.prisma Main Prisma schema (references models)
|
|
40
|
-
- scripts
|
|
41
|
-
- docker-pull.ts Pulls the database Docker image for local development
|
|
42
|
-
- docker-start.ts Starts a local database container
|
|
43
|
-
- wait-for-db.ts Waits for the local database to be ready
|
|
44
42
|
- src
|
|
45
43
|
- index.ts Project entry point
|
|
46
|
-
- constants.ts Local development connection details and runtime config key
|
|
47
44
|
- prisma.ts Prisma runtime client wrapper
|
|
48
45
|
- utils.ts Runtime config and secret helpers
|
|
49
46
|
- create-db-user-handler.ts Lambda handler used to create the application database user during deployment
|
|
50
47
|
- migration-handler.ts Lambda handler used to run database migrations during deployment
|
|
51
48
|
- .gitignore Git ignore entries including generated Prisma client output
|
|
49
|
+
- config.json Local development connection details and runtime config key
|
|
52
50
|
- Dockerfile Container image definition for the migration handler
|
|
53
51
|
- project.json Project configuration and build targets
|
|
54
52
|
- prisma.config.ts Configuration for Prisma CLI
|
|
55
53
|
</FileTree>
|
|
56
54
|
|
|
55
|
+
Local development scripts are shared across all database projects and generated into `packages/common/scripts/`:
|
|
56
|
+
|
|
57
|
+
<FileTree>
|
|
58
|
+
- packages/common/scripts/src/rdb
|
|
59
|
+
- pull-image.ts Pulls the database container image
|
|
60
|
+
- start-container.ts Starts a local database container
|
|
61
|
+
- wait-for-postgres-db.ts Waits for the local database to be ready (PostgreSQL)
|
|
62
|
+
- wait-for-mysql-db.ts Waits for the local database to be ready (MySQL)
|
|
63
|
+
</FileTree>
|
|
64
|
+
|
|
57
65
|
### Infrastructure
|
|
58
66
|
|
|
59
67
|
<Snippet name="shared-constructs" />
|
|
@@ -156,7 +164,6 @@ Use the `prisma` target to run Prisma CLI commands from the workspace root:
|
|
|
156
164
|
|
|
157
165
|
The runtime wrapper in `src/prisma.ts` exports:
|
|
158
166
|
|
|
159
|
-
- `DB_PACKAGE_NAME` - the key used under the `database` runtime config namespace in AWS AppConfig
|
|
160
167
|
- `getPrisma()` - loads database connection settings from AWS AppConfig and creates a Prisma client using IAM authentication
|
|
161
168
|
|
|
162
169
|
The client automatically:
|
|
@@ -169,7 +176,7 @@ The client automatically:
|
|
|
169
176
|
|
|
170
177
|
After adding or updating models under `prisma/models/`, use `migrate dev` to generate migration files and apply them to your local database at the same time.
|
|
171
178
|
|
|
172
|
-
The generated `prisma` target automatically starts a local database
|
|
179
|
+
The generated `prisma` target automatically starts a local database container before running:
|
|
173
180
|
|
|
174
181
|
<NxCommands commands={['run <project>:prisma migrate dev']} />
|
|
175
182
|
|
|
@@ -204,12 +211,26 @@ The generated `prisma` target exposes the Prisma CLI, so you can use it to run a
|
|
|
204
211
|
|
|
205
212
|
<NxCommands commands={['run <project>:prisma <prisma-command>']} />
|
|
206
213
|
|
|
207
|
-
### Prisma Studio
|
|
214
|
+
### Using Prisma Studio
|
|
208
215
|
|
|
209
216
|
[Prisma Studio](https://www.prisma.io/studio) is a visual editor for your local database. Use it to browse tables, inspect and edit records, filter data, follow relations, and run raw SQL via the built-in SQL console. It is useful for verifying migrations and seeding test data during development. Launch it with:
|
|
210
217
|
|
|
211
218
|
<NxCommands commands={['run <project>:prisma studio']} />
|
|
212
219
|
|
|
220
|
+
### Stopping the Local Database
|
|
221
|
+
|
|
222
|
+
Stopping `dev` (e.g. with `Ctrl+C`) automatically removes the local database container, but preserves the named volume so your data persists across restarts.
|
|
223
|
+
|
|
224
|
+
:::caution[Windows]
|
|
225
|
+
Due to limitations with signal handling on Windows, the container is not automatically removed when `dev` is stopped. You will need to remove it manually:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
<engine> rm -f <scope>-<db-name>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Replace `<engine>` with your container engine (`docker` or `finch`), `<scope>` with your Nx workspace scope (e.g. `proj`), and `<db-name>` with your database project name (e.g. `my-db`).
|
|
232
|
+
:::
|
|
233
|
+
|
|
213
234
|
## Connecting to the Database
|
|
214
235
|
|
|
215
236
|
In any TypeScript project, import `getPrisma` from your database package and call it to get a type-safe Prisma client:
|
|
@@ -225,15 +246,6 @@ const users = await prisma.user.findMany({ orderBy: { id: 'asc' } });
|
|
|
225
246
|
|
|
226
247
|
The Prisma client exposes fully typed models derived from your `prisma/models/` schema, giving you end-to-end type safety from the database all the way through to your API response.
|
|
227
248
|
|
|
228
|
-
### Connection Generators
|
|
229
|
-
|
|
230
|
-
For specific project types, use the `connection` generator to automatically wire up the database — it handles imports, context injection, and local development dependencies:
|
|
231
|
-
|
|
232
|
-
- <Link path="guides/connection/trpc-rdb">tRPC API → Relational Database</Link>
|
|
233
|
-
- <Link path="guides/connection/smithy-rdb">Smithy API → Relational Database</Link>
|
|
234
|
-
- <Link path="guides/connection/ts-agent-rdb">TypeScript Agent → Relational Database</Link>
|
|
235
|
-
- <Link path="guides/connection/ts-mcp-server-rdb">MCP Server → Relational Database</Link>
|
|
236
|
-
|
|
237
249
|
## Deploying your Database
|
|
238
250
|
|
|
239
251
|
The relational database generator creates CDK or Terraform infrastructure based on your selected `iacProvider`.
|
|
@@ -524,9 +536,9 @@ module "my_database" {
|
|
|
524
536
|
|
|
525
537
|
Pin a specific Aurora engine version.
|
|
526
538
|
|
|
527
|
-
By default, the generated local
|
|
539
|
+
By default, the generated local database container image matches the default Aurora engine version. If you change the Aurora engine version, it's recommended to also use a matching local container image version for maximum compatibility. See the AWS release notes for [Aurora PostgreSQL versions](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQLReleaseNotes/aurorapostgresql-release-calendar.html) and [Aurora MySQL versions](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraMySQLReleaseNotes/AuroraMySQL.Updates.30Updates.html) to identify the corresponding community database version.
|
|
528
540
|
|
|
529
|
-
The local database image is configured in the
|
|
541
|
+
The local database image is configured in the `localDev.image` field of the generated `config.json` file in your database project root. Update that value when you change engine versions.
|
|
530
542
|
|
|
531
543
|
<OptionFilter when={{ engine: 'postgres' }}>
|
|
532
544
|
<Infrastructure>
|
|
@@ -659,6 +671,36 @@ module "my_database" {
|
|
|
659
671
|
</Fragment>
|
|
660
672
|
</Infrastructure>
|
|
661
673
|
|
|
674
|
+
### Logging and Monitoring
|
|
675
|
+
|
|
676
|
+
Performance Insights is enabled on the Aurora writer instance by default (encrypted with the cluster's KMS key). You can also export the Aurora engine logs to [CloudWatch Logs](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.html) (`postgresql` for [Aurora PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.CloudWatch.html); `audit`, `error`, `general` and `slowquery` for [Aurora MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.CloudWatch.html)). Enable log export per database:
|
|
677
|
+
|
|
678
|
+
<Infrastructure>
|
|
679
|
+
<Fragment slot="cdk">
|
|
680
|
+
|
|
681
|
+
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
682
|
+
import { MyDatabase } from ':my-scope/common-constructs';
|
|
683
|
+
|
|
684
|
+
const db = new MyDatabase(this, 'Db', {
|
|
685
|
+
...
|
|
686
|
+
enableCloudwatchLogs: true,
|
|
687
|
+
enablePerformanceInsights: false, // disable if not required
|
|
688
|
+
});
|
|
689
|
+
```
|
|
690
|
+
</Fragment>
|
|
691
|
+
<Fragment slot="terraform">
|
|
692
|
+
|
|
693
|
+
```hcl title="packages/infra/src/main.tf"
|
|
694
|
+
module "my_database" {
|
|
695
|
+
source = "../../common/terraform/src/app/dbs/my-database"
|
|
696
|
+
...
|
|
697
|
+
enable_cloudwatch_logs = true
|
|
698
|
+
enable_performance_insights = false # disable if not required
|
|
699
|
+
}
|
|
700
|
+
```
|
|
701
|
+
</Fragment>
|
|
702
|
+
</Infrastructure>
|
|
703
|
+
|
|
662
704
|
### Encryption Key Rotation
|
|
663
705
|
|
|
664
706
|
The KMS key used to encrypt the Aurora cluster and its credentials secret has automatic key rotation enabled by default. Disable it if your security policy manages rotation externally.
|
|
@@ -757,3 +799,39 @@ Be cautious with tasks running longer than 15 minutes. If the MySQL client needs
|
|
|
757
799
|
For long-running tasks such as batch jobs or data migrations, call `getPrisma()` at the start of each unit of work rather than once for the entire operation. Because `getPrisma()` always creates a fresh client and fetches a new IAM token for MySQL, this ensures each connection authenticates with a valid token.
|
|
758
800
|
|
|
759
801
|
</OptionFilter>
|
|
802
|
+
|
|
803
|
+
## Connections
|
|
804
|
+
|
|
805
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
806
|
+
|
|
807
|
+
<CardGrid>
|
|
808
|
+
<ConnectionCard
|
|
809
|
+
title="tRPC API to Relational Database"
|
|
810
|
+
description="Connect a tRPC API to an Aurora relational database"
|
|
811
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-rdb`}
|
|
812
|
+
source="trpc"
|
|
813
|
+
target="aurora"
|
|
814
|
+
/>
|
|
815
|
+
<ConnectionCard
|
|
816
|
+
title="Smithy API to Relational Database"
|
|
817
|
+
description="Connect a Smithy API to an Aurora relational database"
|
|
818
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-rdb`}
|
|
819
|
+
source="smithy"
|
|
820
|
+
target="aurora"
|
|
821
|
+
/>
|
|
822
|
+
<ConnectionCard
|
|
823
|
+
title="TypeScript Agent to Relational Database"
|
|
824
|
+
description="Connect a TypeScript Agent to an Aurora relational database"
|
|
825
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-rdb`}
|
|
826
|
+
source="strands"
|
|
827
|
+
sourceBadge="typescript"
|
|
828
|
+
target="aurora"
|
|
829
|
+
/>
|
|
830
|
+
<ConnectionCard
|
|
831
|
+
title="MCP Server to Relational Database"
|
|
832
|
+
description="Connect a TypeScript MCP Server to an Aurora relational database"
|
|
833
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-rdb`}
|
|
834
|
+
source="mcp"
|
|
835
|
+
target="aurora"
|
|
836
|
+
/>
|
|
837
|
+
</CardGrid>
|