@aws/nx-plugin-mcp 1.0.0-rc.4 → 1.0.0-rc.41

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.
Files changed (163) hide show
  1. package/bin/aws-nx-mcp.js +2240 -1030
  2. package/docs/get_started/building-with-ai.mdx +116 -0
  3. package/docs/get_started/concepts.mdx +52 -0
  4. package/docs/get_started/existing-project.mdx +176 -0
  5. package/docs/get_started/quick-start.mdx +266 -0
  6. package/docs/get_started/tutorials/contribute-generator.mdx +405 -0
  7. package/docs/get_started/tutorials/dungeon-game/1.mdx +1205 -0
  8. package/docs/get_started/tutorials/dungeon-game/2.mdx +237 -0
  9. package/docs/get_started/tutorials/dungeon-game/3.mdx +76 -0
  10. package/docs/get_started/tutorials/dungeon-game/4.mdx +162 -0
  11. package/docs/get_started/tutorials/dungeon-game/overview.mdx +144 -0
  12. package/docs/get_started/tutorials/dungeon-game/wrap-up.mdx +41 -0
  13. package/docs/get_started/tutorials/existing-project.mdx +4 -0
  14. package/docs/guides/agentcore-gateway.mdx +376 -0
  15. package/docs/guides/connection/agentcore-gateway-gateway.mdx +154 -0
  16. package/docs/guides/connection/agentcore-gateway-mcp.mdx +134 -0
  17. package/docs/guides/connection/py-agent-a2a.mdx +47 -15
  18. package/docs/guides/connection/py-agent-dynamodb.mdx +116 -0
  19. package/docs/guides/connection/py-agent-gateway.mdx +176 -0
  20. package/docs/guides/connection/py-agent-mcp.mdx +42 -13
  21. package/docs/guides/connection/py-agent-rdb.mdx +178 -0
  22. package/docs/guides/connection/py-fast-api-dynamodb.mdx +56 -0
  23. package/docs/guides/connection/py-fast-api-rdb.mdx +184 -0
  24. package/docs/guides/connection/py-mcp-server-dynamodb.mdx +116 -0
  25. package/docs/guides/connection/py-mcp-server-rdb.mdx +187 -0
  26. package/docs/guides/connection/react-agui.mdx +4 -4
  27. package/docs/guides/connection/react-fastapi.mdx +38 -2
  28. package/docs/guides/connection/react-py-agent.mdx +7 -13
  29. package/docs/guides/connection/react-smithy.mdx +3 -3
  30. package/docs/guides/connection/react-trpc.mdx +1 -1
  31. package/docs/guides/connection/react-ts-agent.mdx +8 -8
  32. package/docs/guides/connection/smithy-dynamodb.mdx +4 -4
  33. package/docs/guides/connection/smithy-rdb.mdx +5 -5
  34. package/docs/guides/connection/trpc-dynamodb.mdx +4 -4
  35. package/docs/guides/connection/trpc-rdb.mdx +5 -5
  36. package/docs/guides/connection/ts-agent-a2a.mdx +12 -9
  37. package/docs/guides/connection/ts-agent-dynamodb.mdx +3 -3
  38. package/docs/guides/connection/ts-agent-gateway.mdx +141 -0
  39. package/docs/guides/connection/ts-agent-mcp.mdx +11 -8
  40. package/docs/guides/connection/ts-agent-rdb.mdx +66 -21
  41. package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +3 -3
  42. package/docs/guides/connection/ts-mcp-server-rdb.mdx +66 -16
  43. package/docs/guides/connection.mdx +104 -5
  44. package/docs/guides/docker-bundling.mdx +68 -8
  45. package/docs/guides/fastapi.mdx +244 -4
  46. package/docs/guides/license.mdx +264 -109
  47. package/docs/guides/local-development.mdx +87 -0
  48. package/docs/guides/nx-generator.mdx +7 -2
  49. package/docs/guides/py-agent.mdx +257 -49
  50. package/docs/guides/py-dynamodb.mdx +476 -0
  51. package/docs/guides/py-mcp-server.mdx +61 -2
  52. package/docs/guides/py-rdb.mdx +254 -0
  53. package/docs/guides/react-website-auth.mdx +58 -1
  54. package/docs/guides/react-website.mdx +130 -19
  55. package/docs/guides/security.mdx +75 -0
  56. package/docs/guides/terraform-project.mdx +1 -1
  57. package/docs/guides/trpc.mdx +45 -9
  58. package/docs/guides/ts-agent.mdx +149 -9
  59. package/docs/guides/ts-dynamodb.mdx +62 -239
  60. package/docs/guides/ts-mcp-server.mdx +66 -3
  61. package/docs/guides/ts-nx-plugin.mdx +1 -1
  62. package/docs/guides/ts-rdb.mdx +117 -470
  63. package/docs/guides/ts-smithy-api.mdx +183 -4
  64. package/docs/guides/typescript-infrastructure.mdx +9 -1
  65. package/docs/guides/typescript-project.mdx +5 -10
  66. package/docs/guides/workspace.mdx +2 -2
  67. package/docs/snippets/agent/architecture.mdx +1 -1
  68. package/docs/snippets/agent/bedrock-deployment.mdx +4 -0
  69. package/docs/snippets/agent/runtime-arn.mdx +21 -0
  70. package/docs/snippets/agent/securing-your-agent.mdx +39 -0
  71. package/docs/snippets/api/access-logging.mdx +33 -0
  72. package/docs/snippets/api/type-safe-api-integrations.mdx +31 -0
  73. package/docs/snippets/api/waf-configuration.mdx +1 -1
  74. package/docs/snippets/connection/dynamodb-local-development.mdx +2 -2
  75. package/docs/snippets/connection/py-dynamodb-local-development.mdx +7 -0
  76. package/docs/snippets/connection/py-lambda-rdb-ssl-requirements.mdx +7 -0
  77. package/docs/snippets/connection/rdb-api-infrastructure.mdx +50 -18
  78. package/docs/snippets/dynamodb/deploying-table.mdx +166 -0
  79. package/docs/snippets/dynamodb/gsi-config.mdx +38 -0
  80. package/docs/snippets/dynamodb/infrastructure.mdx +33 -0
  81. package/docs/snippets/dynamodb/local-dev-start.mdx +13 -0
  82. package/docs/snippets/dynamodb/local-dev-windows.mdx +15 -0
  83. package/docs/snippets/mcp/architecture.mdx +1 -1
  84. package/docs/snippets/mcp/bedrock-deployment.mdx +4 -0
  85. package/docs/snippets/mcp/config.mdx +3 -2
  86. package/docs/snippets/rdb/architecture.mdx +38 -0
  87. package/docs/snippets/rdb/cluster-instances.mdx +31 -0
  88. package/docs/snippets/rdb/deletion-protection.mdx +34 -0
  89. package/docs/snippets/rdb/deploying.mdx +187 -0
  90. package/docs/snippets/rdb/encryption-key-rotation.mdx +30 -0
  91. package/docs/snippets/rdb/engine-version.mdx +63 -0
  92. package/docs/snippets/rdb/infrastructure.mdx +35 -0
  93. package/docs/snippets/rdb/logging.mdx +32 -0
  94. package/docs/snippets/rdb/rds-proxy.mdx +50 -0
  95. package/docs/snippets/rdb/removal-policy.mdx +57 -0
  96. package/docs/snippets/rdb/serverless-capacity.mdx +32 -0
  97. package/docs/snippets/required-prerequisites.mdx +1 -1
  98. package/docs/snippets/trivy-image-scan.mdx +27 -0
  99. package/generators.json +101 -2
  100. package/package.json +1 -1
  101. package/src/agentcore-gateway/gateway-connection/schema.json +31 -0
  102. package/src/agentcore-gateway/mcp-connection/schema.json +31 -0
  103. package/src/agentcore-gateway/schema.json +70 -0
  104. package/src/connection/schema.json +5 -0
  105. package/src/infra/app/schema.json +5 -0
  106. package/src/init/schema.json +35 -0
  107. package/src/license/schema.json +11 -0
  108. package/src/preset/schema.json +11 -5
  109. package/src/py/agent/a2a-connection/schema.json +5 -0
  110. package/src/py/agent/gateway-connection/schema.json +31 -0
  111. package/src/py/agent/mcp-connection/schema.json +5 -0
  112. package/src/py/agent/react-connection/schema.json +5 -0
  113. package/src/py/agent/schema.json +6 -1
  114. package/src/py/api/schema.json +5 -0
  115. package/src/py/dynamodb/agent-connection/schema.json +27 -0
  116. package/src/py/dynamodb/fast-api-connection/schema.json +23 -0
  117. package/src/py/dynamodb/mcp-server-connection/schema.json +27 -0
  118. package/src/py/dynamodb/schema.json +75 -0
  119. package/src/py/fast-api/react/schema.json +5 -0
  120. package/src/py/fast-api/schema.json +5 -0
  121. package/src/py/lambda-function/schema.json +5 -0
  122. package/src/py/mcp-server/schema.json +5 -0
  123. package/src/py/project/schema.json +5 -0
  124. package/src/py/rdb/agent-connection/schema.json +27 -0
  125. package/src/py/rdb/fast-api-connection/schema.json +23 -0
  126. package/src/py/rdb/mcp-server-connection/schema.json +27 -0
  127. package/src/py/rdb/schema.json +77 -0
  128. package/src/smithy/project/schema.json +5 -0
  129. package/src/smithy/react-connection/schema.json +5 -0
  130. package/src/smithy/ts/api/schema.json +5 -0
  131. package/src/terraform/project/schema.json +5 -0
  132. package/src/trpc/backend/schema.json +5 -0
  133. package/src/trpc/react/schema.json +5 -0
  134. package/src/ts/agent/a2a-connection/schema.json +5 -0
  135. package/src/ts/agent/gateway-connection/schema.json +31 -0
  136. package/src/ts/agent/mcp-connection/schema.json +5 -0
  137. package/src/ts/agent/react-connection/schema.json +5 -0
  138. package/src/ts/agent/schema.json +5 -0
  139. package/src/ts/api/schema.json +5 -0
  140. package/src/ts/astro-docs/schema.json +3 -3
  141. package/src/ts/docs/schema.json +3 -3
  142. package/src/ts/dynamodb/agent-connection/schema.json +5 -0
  143. package/src/ts/dynamodb/mcp-server-connection/schema.json +5 -0
  144. package/src/ts/dynamodb/schema.json +25 -2
  145. package/src/ts/dynamodb/smithy-connection/schema.json +5 -0
  146. package/src/ts/dynamodb/trpc-connection/schema.json +5 -0
  147. package/src/ts/lambda-function/schema.json +5 -0
  148. package/src/ts/lib/schema.json +5 -0
  149. package/src/ts/mcp-server/schema.json +5 -0
  150. package/src/ts/nx-generator/schema.json +5 -0
  151. package/src/ts/nx-plugin/schema.json +5 -0
  152. package/src/ts/rdb/agent-connection/schema.json +5 -0
  153. package/src/ts/rdb/mcp-server-connection/schema.json +5 -0
  154. package/src/ts/rdb/schema.json +6 -1
  155. package/src/ts/rdb/smithy-connection/schema.json +5 -0
  156. package/src/ts/rdb/trpc-connection/schema.json +5 -0
  157. package/src/ts/react-website/app/schema.json +11 -6
  158. package/src/ts/react-website/cognito-auth/schema.json +5 -0
  159. package/src/ts/react-website/runtime-config/schema.json +5 -0
  160. package/src/ts/website/app/schema.json +11 -6
  161. package/src/ts/website/auth/schema.json +5 -0
  162. /package/docs/snippets/connection/{lambda-rdb-ssl-requirements.mdx → ts-lambda-rdb-ssl-requirements.mdx} +0 -0
  163. /package/docs/snippets/connection/{mcp-server-rdb-ssl-requirements.mdx → ts-mcp-server-rdb-ssl-requirements.mdx} +0 -0
@@ -1,16 +1,17 @@
1
1
  ---
2
- title: Relational Database
2
+ title: TypeScript Relational Database
3
3
  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, Tabs, TabItem } from '@astrojs/starlight/components';
8
+ import Astro from '@astrojs/react';
9
+ import ConnectionCard from '@components/connection-card.astro';
10
+ import Infrastructure from '@components/infrastructure.astro';
8
11
  import Link from '@components/link.astro';
9
12
  import RunGenerator from '@components/run-generator.astro';
10
13
  import GeneratorParameters from '@components/generator-parameters.astro';
11
- import Infrastructure from '@components/infrastructure.astro';
12
14
  import NxCommands from '@components/nx-commands.astro';
13
- import PackageManagerExecCommand from '@components/package-manager-exec-command.astro';
14
15
  import Snippet from '@components/snippet.astro';
15
16
  import OptionFilter from '@components/option-filter.astro';
16
17
 
@@ -37,92 +38,36 @@ The generator will create the following project structure in the `<directory>/<n
37
38
  - models
38
39
  - example.prisma Example model definition
39
40
  - 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
41
  - src
45
42
  - index.ts Project entry point
46
- - constants.ts Local development connection details and runtime config key
47
43
  - prisma.ts Prisma runtime client wrapper
48
44
  - utils.ts Runtime config and secret helpers
49
45
  - create-db-user-handler.ts Lambda handler used to create the application database user during deployment
50
46
  - migration-handler.ts Lambda handler used to run database migrations during deployment
51
47
  - .gitignore Git ignore entries including generated Prisma client output
48
+ - config.json Local development connection details and runtime config key
52
49
  - Dockerfile Container image definition for the migration handler
53
50
  - project.json Project configuration and build targets
54
51
  - prisma.config.ts Configuration for Prisma CLI
55
52
  </FileTree>
56
53
 
57
- ### Infrastructure
58
-
59
- <Snippet name="shared-constructs" />
60
-
61
- <Infrastructure>
62
- <Fragment slot="cdk">
63
- <FileTree>
64
- - packages/common/constructs/src
65
- - app
66
- - dbs
67
- - \<name>.ts Infrastructure specific to your database
68
- - core
69
- - rdb
70
- - aurora.ts Generic Aurora database construct
71
- </FileTree>
72
- </Fragment>
73
- <Fragment slot="terraform">
74
- <FileTree>
75
- - packages/common/terraform/src
76
- - app
77
- - dbs
78
- - \<name>
79
- - \<name>.tf Module specific to your database
80
- - core
81
- - rdb
82
- - aurora
83
- - aurora.tf Generic Aurora module
84
- </FileTree>
85
- </Fragment>
86
- </Infrastructure>
87
-
88
- #### Architecture
89
-
90
- The deployed database has the following architecture. By default, an [Amazon RDS Proxy](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy.html) sits in front of the Aurora cluster to pool connections and to enable [IAM authentication](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html) — see [Disable RDS Proxy](#disable-rds-proxy) for the alternative. The architecture is the same whether you select the PostgreSQL or MySQL engine; only the Aurora engine flavor differs.
91
-
92
- ```d2 inline=true
93
- direction: right
94
-
95
- app: Application\n(Lambda, Agent, ...) {
96
- shape: hexagon
97
- }
54
+ Local development scripts are shared across all database projects and generated into `packages/common/scripts/`:
98
55
 
99
- migrations: Migrations Lambda {
100
- shape: image
101
- icon: /nx-plugin-for-aws/icons/aws/lambda.svg
102
- near: top-right
103
- }
56
+ <FileTree>
57
+ - packages/common/scripts/src/rdb
58
+ - pull-image.ts Pulls the database container image
59
+ - start-container.ts Starts a local database container
60
+ - wait-for-postgres-db.ts Waits for the local database to be ready (PostgreSQL)
61
+ - wait-for-mysql-db.ts Waits for the local database to be ready (MySQL)
62
+ </FileTree>
104
63
 
105
- proxy: RDS Proxy {
106
- shape: image
107
- icon: /nx-plugin-for-aws/icons/aws/rds.svg
108
- }
64
+ ### Infrastructure
109
65
 
110
- aurora: Aurora\n(PostgreSQL or MySQL) {
111
- shape: image
112
- icon: /nx-plugin-for-aws/icons/aws/aurora.svg
113
- }
66
+ <Snippet name="rdb/infrastructure" />
114
67
 
115
- secrets: Secrets Manager\n(DB credentials) {
116
- shape: image
117
- icon: /nx-plugin-for-aws/icons/aws/secrets-manager.svg
118
- near: bottom-right
119
- }
68
+ #### Architecture
120
69
 
121
- app -> proxy: SQL (IAM auth)
122
- proxy -> aurora
123
- migrations -> aurora: Schema migrations
124
- proxy -> secrets: Master credential rotation
125
- ```
70
+ <Snippet name="rdb/architecture" />
126
71
 
127
72
  ## Local Development
128
73
 
@@ -156,7 +101,6 @@ Use the `prisma` target to run Prisma CLI commands from the workspace root:
156
101
 
157
102
  The runtime wrapper in `src/prisma.ts` exports:
158
103
 
159
- - `DB_PACKAGE_NAME` - the key used under the `database` runtime config namespace in AWS AppConfig
160
104
  - `getPrisma()` - loads database connection settings from AWS AppConfig and creates a Prisma client using IAM authentication
161
105
 
162
106
  The client automatically:
@@ -169,7 +113,7 @@ The client automatically:
169
113
 
170
114
  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
115
 
172
- The generated `prisma` target automatically starts a local database via Docker before running:
116
+ The generated `prisma` target automatically starts a local database container before running:
173
117
 
174
118
  <NxCommands commands={['run <project>:prisma migrate dev']} />
175
119
 
@@ -204,12 +148,26 @@ The generated `prisma` target exposes the Prisma CLI, so you can use it to run a
204
148
 
205
149
  <NxCommands commands={['run <project>:prisma <prisma-command>']} />
206
150
 
207
- ### Prisma Studio
151
+ ### Using Prisma Studio
208
152
 
209
153
  [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
154
 
211
155
  <NxCommands commands={['run <project>:prisma studio']} />
212
156
 
157
+ ### Stopping the Local Database
158
+
159
+ Stopping `dev` (e.g. with `Ctrl+C`) automatically removes the local database container, but preserves the named volume so your data persists across restarts.
160
+
161
+ :::caution[Windows]
162
+ 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:
163
+
164
+ ```bash
165
+ <engine> rm -f <scope>-<db-name>
166
+ ```
167
+
168
+ 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`).
169
+ :::
170
+
213
171
  ## Connecting to the Database
214
172
 
215
173
  In any TypeScript project, import `getPrisma` from your database package and call it to get a type-safe Prisma client:
@@ -225,467 +183,120 @@ const users = await prisma.user.findMany({ orderBy: { id: 'asc' } });
225
183
 
226
184
  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
185
 
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
186
  ## Deploying your Database
238
187
 
239
- The relational database generator creates CDK or Terraform infrastructure based on your selected `iacProvider`.
188
+ <Snippet name="rdb/deploying" parentHeading="Deploying your Database" />
240
189
 
241
- <Infrastructure>
242
- <Fragment slot="cdk">
243
- The CDK construct is created in `common/constructs`. Example usage:
190
+ ### Image Scanning
244
191
 
245
- ```ts title="packages/infra/src/stacks/application-stack.ts"
246
- import { MyDatabase } from ':my-scope/common-constructs';
247
-
248
- export class ApplicationStack extends Stack {
249
- constructor(scope: Construct, id: string, props?: StackProps) {
250
- super(scope, id, props);
251
- ...
252
- const db = new MyDatabase(this, 'Db', {
253
- vpc,
254
- vpcSubnets: {
255
- subnetType: SubnetType.PRIVATE_ISOLATED,
256
- }
257
- });
258
- }
259
- }
260
- ```
192
+ <Snippet name="trivy-image-scan" parentHeading="Image Scanning" />
261
193
 
262
- This provisions an Aurora cluster with RDS Proxy, admin credentials, application database user, runtime config registration, and migration handler.
194
+ ### RDS Proxy Configuration
263
195
 
264
- The generated infrastructure creates two database users:
265
- - **Admin user** - Created during cluster provisioning with credentials stored in AWS Secrets Manager
266
- - **Application user** - Created via a Lambda custom resource with IAM authentication enabled and full privileges on the application database
267
- </Fragment>
268
- <Fragment slot="terraform">
269
- The Terraform module is created in `common/terraform`. Example usage:
196
+ <Snippet name="rdb/rds-proxy" parentHeading="RDS Proxy Configuration" />
270
197
 
271
- ```hcl title="packages/infra/src/main.tf"
272
- module "my_database" {
273
- source = "../../common/terraform/src/app/dbs/my-database"
198
+ #### SSL Requirements When Connecting Without RDS Proxy
274
199
 
275
- vpc_id = module.vpc.vpc_id
276
- database_subnet_ids = module.vpc.private_isolated_subnet_ids
277
- lambda_subnet_ids = module.vpc.private_subnet_ids
200
+ When connecting directly to the Aurora cluster (without RDS Proxy), the runtime that calls `getPrisma()` must trust the Amazon RDS CA bundle. The generated Prisma client enables certificate verification; how you make the CA bundle available depends on the runtime that connects to the database.
278
201
 
279
- tags = local.common_tags
280
- }
281
- ```
202
+ For Amazon RDS, use the global CA bundle from:
282
203
 
283
- This provisions an Aurora cluster with RDS Proxy, admin credentials, create-db-user Lambda, runtime config registration, migration Lambda, and container registry resources.
204
+ ```text
205
+ https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
206
+ ```
284
207
 
285
- The generated infrastructure creates two database users:
286
- - **Admin user** - Created during cluster provisioning with credentials stored in AWS Secrets Manager
287
- - **Application user** - Created via a Lambda function with IAM authentication enabled and full privileges on the application database
288
- </Fragment>
289
- </Infrastructure>
208
+ ##### Runtime Container Images
290
209
 
291
- The application user is automatically created with a random name and IAM authentication. `getPrisma()` is already configured to authenticate as this user using short-lived RDS tokens, so your application code never handles database passwords.
210
+ If you prepare your own container image for the runtime, download the RDS CA bundle in your Dockerfile and add it to the operating system trust store.
292
211
 
293
- Your VPC should include public subnets, private subnets with egress, and private isolated subnets. The database can run in private isolated subnets, while API Lambda functions should run in private subnets with egress so they can reach AWS services such as AppConfig.
212
+ <Tabs>
213
+ <TabItem label="Amazon Linux">
294
214
 
295
- <Infrastructure>
296
- <Fragment slot="cdk">
297
-
298
- ```ts title="packages/infra/src/stacks/application-stack.ts"
299
- const vpc = new Vpc(this, 'Vpc', {
300
- subnetConfiguration: [
301
- {
302
- name: 'public',
303
- subnetType: SubnetType.PUBLIC,
304
- },
305
- {
306
- name: 'private_with_egress',
307
- subnetType: SubnetType.PRIVATE_WITH_EGRESS,
308
- },
309
- {
310
- name: 'private_isolated',
311
- subnetType: SubnetType.PRIVATE_ISOLATED,
312
- },
313
- ],
314
- });
215
+ ```dockerfile
216
+ RUN curl -fsSL "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem" \
217
+ -o /etc/pki/ca-trust/source/anchors/rds-bundle.pem && \
218
+ update-ca-trust
315
219
  ```
316
220
 
317
- </Fragment>
318
- <Fragment slot="terraform">
319
-
320
- ```hcl title="packages/infra/src/main.tf"
321
- module "vpc" {
322
- source = "terraform-aws-modules/vpc/aws"
323
- version = "~> 6.0"
221
+ </TabItem>
222
+ <TabItem label="Debian">
324
223
 
325
- name = "app"
326
- ...
327
- public_subnet_names = ["public"]
328
- private_subnet_names = ["private_with_egress"]
329
- intra_subnet_names = ["private_isolated"]
330
-
331
- enable_nat_gateway = true
332
- single_nat_gateway = true
333
- }
224
+ ```dockerfile
225
+ RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates && \
226
+ rm -rf /var/lib/apt/lists/* && \
227
+ curl -fsSL "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem" \
228
+ -o /usr/local/share/ca-certificates/rds-bundle.crt && \
229
+ update-ca-certificates
334
230
  ```
335
231
 
336
- </Fragment>
337
- </Infrastructure>
232
+ </TabItem>
233
+ </Tabs>
234
+
235
+ ##### Zipped Lambda Functions
338
236
 
339
- ### Connecting an API to the Database
237
+ For zipped Lambda functions using Node.js 20 or later runtimes, load the Amazon RDS CA bundle by setting `NODE_EXTRA_CA_CERTS`:
340
238
 
341
239
  <Infrastructure>
342
240
  <Fragment slot="cdk">
343
241
 
344
- In your application stack, deploy the API into the same VPC as the database, then call `allowDefaultPortFrom` and `grantConnect` to open the network path and grant IAM `rds-db:connect` permission to each Lambda handler:
345
-
346
242
  ```ts title="packages/infra/src/stacks/application-stack.ts"
347
- import { MyDatabase } from ':my-scope/common-constructs';
348
-
349
- const db = new MyDatabase(this, 'Db', { vpc, ... });
350
-
351
243
  const api = new Api(this, 'Api', {
352
244
  integrations: Api.defaultIntegrations(this)
353
245
  .withDefaultOptions({
354
- vpc,
355
- vpcSubnets: { subnetType: SubnetType.PRIVATE_WITH_EGRESS },
246
+ environment: {
247
+ NODE_EXTRA_CA_CERTS: '/var/runtime/ca-cert.pem',
248
+ },
356
249
  })
357
250
  .build(),
358
251
  });
359
-
360
- Object.entries(api.integrations).forEach(([operation, integration]) => {
361
- db.allowDefaultPortFrom(integration.handler, `Allow ${operation} to connect to the database`);
362
- db.grantConnect(integration.handler);
363
- });
364
252
  ```
365
253
 
366
- Deploy the API Lambda functions into a **private subnet with egress** (recommended) or a public subnet, not a private isolated subnet. At runtime, `getPrisma()` retrieves database connection details from AWS AppConfig, which is a public AWS service endpoint. Lambda functions in a private isolated subnet have no outbound internet access and cannot reach AppConfig. Private subnets with egress route outbound traffic through a NAT Gateway which sits in a public subnet.
367
254
  </Fragment>
368
255
  <Fragment slot="terraform">
369
256
 
370
- Pass the database module outputs into your compute module so it can reach the database and read its runtime configuration:
371
-
372
257
  ```hcl title="packages/infra/src/main.tf"
373
- module "my_database" {
374
- source = "../../common/terraform/src/app/dbs/my-database"
375
- vpc_id = module.vpc.vpc_id
376
- database_subnet_ids = module.vpc.private_isolated_subnet_ids
377
- lambda_subnet_ids = module.vpc.private_subnet_ids
378
- }
379
-
380
258
  module "api" {
381
- source = "..."
382
- vpc_id = module.vpc.vpc_id
383
- private_subnet_ids = module.vpc.private_subnet_ids
384
-
385
- # Allow the API to read runtime config from AppConfig
386
- appconfig_application_id = module.my_database.appconfig_application_id
387
-
388
- # Grant rds-db:connect for the application database user
389
- database_cluster_resource_id = module.my_database.cluster_resource_id
390
- database_runtime_user = module.my_database.database_runtime_user
391
-
392
- # Allow network access to the database port
393
- database_security_group_id = module.my_database.security_group_id
394
- database_port = module.my_database.cluster_port
259
+ source = "..."
260
+ ...
395
261
 
396
262
  environment_variables = {
397
- RUNTIME_CONFIG_APP_ID = module.my_database.appconfig_application_id
263
+ NODE_EXTRA_CA_CERTS = "/var/runtime/ca-cert.pem"
398
264
  }
399
265
  }
400
266
  ```
401
267
 
402
- Deploy the API Lambda functions into **private subnets with egress** (recommended) or public subnets, not private isolated subnets. At runtime, `getPrisma()` retrieves database connection details from AWS AppConfig, which is a public AWS service endpoint. Lambda functions in a private isolated subnet have no outbound internet access and cannot reach AppConfig. Private subnets with egress route outbound traffic through a NAT Gateway which requires a public subnet.
403
-
404
- Ensure the API Lambda role has `rds-db:connect` on `arn:aws:rds-db:<region>:<account>:dbuser:<cluster_resource_id>/<database_runtime_user>` and AppConfig read permissions, that the API's security group can reach the database security group on the database port, and that the Lambda environment includes `RUNTIME_CONFIG_APP_ID`.
405
- </Fragment>
406
- </Infrastructure>
407
-
408
- :::note
409
- This example grants every handler in your API access, but if only some handlers need access it's better to configure individually.
410
- :::
411
-
412
- ### RDS Proxy Configuration
413
-
414
- The generated infrastructure includes an RDS Proxy by default, which sits between your application and the Aurora cluster. RDS Proxy provides several benefits:
415
-
416
- - **Connection pooling** - Maintains a pool of database connections that can be shared across application instances, reducing the overhead of establishing new connections
417
- - **Connection resilience** - Automatically handles failovers and reconnects during Aurora instance replacements or maintenance
418
- - **IAM authentication** - Supports IAM-based database authentication, eliminating the need to manage database credentials in your application code
419
- - **Improved security** - Enforces TLS encryption for all connections
420
-
421
- :::note[Additional Cost]
422
- RDS Proxy is enabled by default but incurs additional charges on top of the Aurora cluster cost. See [AWS RDS Proxy pricing](https://aws.amazon.com/rds/proxy/pricing/) for details. If you would prefer to disable the proxy, see the section below.
423
- :::
424
-
425
- #### Disable RDS Proxy
426
-
427
- You can disable the RDS proxy as follows:
428
-
429
- <Infrastructure>
430
- <Fragment slot="cdk">
431
-
432
-
433
- ```ts title="packages/infra/src/stacks/application-stack.ts"
434
- import { MyDatabase } from ':my-scope/common-constructs';
435
-
436
- const db = new MyDatabase(this, 'Db', {
437
- ...
438
- enableRdsProxy: false,
439
- });
440
- ```
441
-
442
- When RDS Proxy is disabled, your application connects directly to the Aurora cluster endpoint.
443
- </Fragment>
444
- <Fragment slot="terraform">
445
-
446
- By default, RDS Proxy is enabled. The generated runtime client (`getPrisma()`) automatically connects through the proxy endpoint. You can disable it if needed:
447
-
448
- ```hcl title="packages/infra/src/main.tf"
449
- module "my_database" {
450
- source = "../../common/terraform/src/app/dbs/my-database"
451
- ...
452
- enable_rds_proxy = false
453
- }
454
- ```
455
-
456
- When RDS Proxy is disabled, your application connects directly to the Aurora cluster endpoint.
457
268
  </Fragment>
458
269
  </Infrastructure>
459
270
 
460
- <Snippet name="connection/lambda-rdb-ssl-requirements" parentHeading="Disable RDS Proxy" />
461
-
462
- The generated infrastructure can be customised to match your workload requirements. The following examples demonstrate a few common customisation options available.
271
+ For more details, see the AWS Lambda [SSL/TLS requirements for Amazon RDS connections](https://docs.aws.amazon.com/lambda/latest/dg/services-rds.html#services-rds-tls). When using RDS Proxy, you do not need to configure the RDS CA bundle in the runtime that connects to the database.
463
272
 
464
273
  ### Cluster Instances
465
274
 
466
- Configure the writer and reader instances for your Aurora cluster.
467
-
468
- <Infrastructure>
469
- <Fragment slot="cdk">
470
-
471
- ```ts title="packages/infra/src/stacks/application-stack.ts"
472
- import { MyDatabase } from ':my-scope/common-constructs';
473
-
474
- const db = new MyDatabase(this, 'Db', {
475
- ...
476
- writer: ClusterInstance.serverlessV2('writer'),
477
- readers: [ClusterInstance.serverlessV2('reader')],
478
- });
479
- ```
480
- </Fragment>
481
- <Fragment slot="terraform">
482
-
483
- ```hcl title="packages/infra/src/main.tf"
484
- module "my_database" {
485
- source = "../../common/terraform/src/app/dbs/my-database"
486
- ...
487
- instance_count = 2 # 1 writer + 1 reader
488
- }
489
- ```
490
- </Fragment>
491
- </Infrastructure>
275
+ <Snippet name="rdb/cluster-instances" />
492
276
 
493
277
  ### Serverless Capacity
494
278
 
495
- Control Aurora Serverless v2 scaling limits to match your workload.
496
-
497
- <Infrastructure>
498
- <Fragment slot="cdk">
499
-
500
- ```ts title="packages/infra/src/stacks/application-stack.ts"
501
- import { MyDatabase } from ':my-scope/common-constructs';
502
-
503
- const db = new MyDatabase(this, 'Db', {
504
- ...
505
- serverlessV2MinCapacity: 0.5,
506
- serverlessV2MaxCapacity: 8,
507
- });
508
- ```
509
- </Fragment>
510
- <Fragment slot="terraform">
511
-
512
- ```hcl title="packages/infra/src/main.tf"
513
- module "my_database" {
514
- source = "../../common/terraform/src/app/dbs/my-database"
515
- ...
516
- serverless_min_capacity = 0.5
517
- serverless_max_capacity = 8
518
- }
519
- ```
520
- </Fragment>
521
- </Infrastructure>
279
+ <Snippet name="rdb/serverless-capacity" />
522
280
 
523
281
  ### Engine Version
524
282
 
525
- Pin a specific Aurora engine version.
526
-
527
- By default, the generated local Docker database image matches the default Aurora engine version. If you change the Aurora engine version, it's recommended to also use a matching local Docker database 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
-
529
- The local database image is configured in the generated database project's `serve-local` target in `project.json`. Update the image argument passed to `scripts/docker-start.ts` when you change engine versions.
530
-
531
- <OptionFilter when={{ engine: 'postgres' }}>
532
- <Infrastructure>
533
- <Fragment slot="cdk">
534
-
535
- ```ts title="packages/infra/src/stacks/application-stack.ts"
536
- import { MyDatabase } from ':my-scope/common-constructs';
537
-
538
- const db = new MyDatabase(this, 'Db', {
539
- ...
540
- engineVersion: AuroraPostgresEngineVersion.VER_17_7,
541
- });
542
- ```
543
- </Fragment>
544
- <Fragment slot="terraform">
545
-
546
- ```hcl title="packages/infra/src/main.tf"
547
- module "my_database" {
548
- source = "../../common/terraform/src/app/dbs/my-database"
549
- ...
550
- engine_version = "17.7"
551
- }
552
- ```
553
- </Fragment>
554
- </Infrastructure>
555
- </OptionFilter>
556
-
557
- <OptionFilter when={{ engine: 'mysql' }}>
558
- <Infrastructure>
559
- <Fragment slot="cdk">
560
-
561
- ```ts title="packages/infra/src/stacks/application-stack.ts"
562
- import { MyDatabase } from ':my-scope/common-constructs';
563
-
564
- const db = new MyDatabase(this, 'Db', {
565
- ...
566
- engineVersion: AuroraMysqlEngineVersion.VER_3_12_0,
567
- });
568
- ```
569
- </Fragment>
570
- <Fragment slot="terraform">
571
-
572
- ```hcl title="packages/infra/src/main.tf"
573
- module "my_database" {
574
- source = "../../common/terraform/src/app/dbs/my-database"
575
- ...
576
- engine_version = "8.0.mysql_aurora.3.12.0"
577
- }
578
- ```
579
- </Fragment>
580
- </Infrastructure>
581
- </OptionFilter>
283
+ <Snippet name="rdb/engine-version" />
582
284
 
583
285
  ### Deletion Protection
584
286
 
585
- Deletion protection is enabled by default (`deletionProtection: true` in CDK, `deletion_protection = true` in Terraform) to protect the Aurora cluster from accidental deletion.
586
-
587
- #### Disable Deletion Protection
588
-
589
- You can disable deletion protection for environments where database deletion is expected, such as short-lived development or preview stacks.
590
-
591
- <Infrastructure>
592
- <Fragment slot="cdk">
593
-
594
- ```ts title="packages/infra/src/stacks/application-stack.ts"
595
- import { MyDatabase } from ':my-scope/common-constructs';
596
-
597
- const db = new MyDatabase(this, 'Db', {
598
- ...
599
- deletionProtection: false,
600
- });
601
- ```
602
- </Fragment>
603
- <Fragment slot="terraform">
604
-
605
- ```hcl title="packages/infra/src/main.tf"
606
- module "my_database" {
607
- source = "../../common/terraform/src/app/dbs/my-database"
608
- ...
609
- deletion_protection = false
610
- }
611
- ```
612
- </Fragment>
613
- </Infrastructure>
287
+ <Snippet name="rdb/deletion-protection" />
614
288
 
615
289
  ### Removal Policy
616
290
 
617
- The CDK construct retains the Aurora cluster by default (`removalPolicy: RemovalPolicy.RETAIN`). Change this when you want CDK stack deletion to snapshot or destroy the cluster instead.
618
-
619
- When using `RemovalPolicy.DESTROY`, deletion protection must also be disabled before the cluster can be deleted.
620
-
621
- <Infrastructure>
622
- <Fragment slot="cdk">
623
-
624
- ```ts title="packages/infra/src/stacks/application-stack.ts"
625
- import { RemovalPolicy } from 'aws-cdk-lib';
626
- import { MyDatabase } from ':my-scope/common-constructs';
627
-
628
- const db = new MyDatabase(this, 'Db', {
629
- ...
630
- removalPolicy: RemovalPolicy.SNAPSHOT,
631
- });
632
- ```
633
-
634
- For an ephemeral environment where the database should be deleted with the stack:
635
-
636
- ```ts title="packages/infra/src/stacks/application-stack.ts"
637
- import { RemovalPolicy } from 'aws-cdk-lib';
638
- import { MyDatabase } from ':my-scope/common-constructs';
639
-
640
- const db = new MyDatabase(this, 'Db', {
641
- ...
642
- deletionProtection: false,
643
- removalPolicy: RemovalPolicy.DESTROY,
644
- });
645
- ```
646
- </Fragment>
647
- <Fragment slot="terraform">
291
+ <Snippet name="rdb/removal-policy" />
648
292
 
649
- Terraform does not use CDK removal policies. By default, the module creates a final snapshot on deletion (`skip_final_snapshot = false`). To skip the final snapshot for an ephemeral environment:
293
+ ### Logging and Monitoring
650
294
 
651
- ```hcl title="packages/infra/src/main.tf"
652
- module "my_database" {
653
- source = "../../common/terraform/src/app/dbs/my-database"
654
- ...
655
- deletion_protection = false
656
- skip_final_snapshot = true
657
- }
658
- ```
659
- </Fragment>
660
- </Infrastructure>
295
+ <Snippet name="rdb/logging" />
661
296
 
662
297
  ### Encryption Key Rotation
663
298
 
664
- 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.
665
-
666
- <Infrastructure>
667
- <Fragment slot="cdk">
668
-
669
- ```ts title="packages/infra/src/stacks/application-stack.ts"
670
- import { MyDatabase } from ':my-scope/common-constructs';
671
-
672
- const db = new MyDatabase(this, 'Db', {
673
- ...
674
- enableKeyRotation: false,
675
- });
676
- ```
677
- </Fragment>
678
- <Fragment slot="terraform">
679
-
680
- ```hcl title="packages/infra/src/main.tf"
681
- module "my_database" {
682
- source = "../../common/terraform/src/app/dbs/my-database"
683
- ...
684
- enable_key_rotation = false
685
- }
686
- ```
687
- </Fragment>
688
- </Infrastructure>
299
+ <Snippet name="rdb/encryption-key-rotation" />
689
300
 
690
301
  ## Limitations
691
302
 
@@ -757,3 +368,39 @@ Be cautious with tasks running longer than 15 minutes. If the MySQL client needs
757
368
  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
369
 
759
370
  </OptionFilter>
371
+
372
+ ## Connections
373
+
374
+ Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
375
+
376
+ <CardGrid>
377
+ <ConnectionCard
378
+ title="tRPC API to Relational Database"
379
+ description="Connect a tRPC API to an Aurora relational database"
380
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-rdb`}
381
+ source="trpc"
382
+ target="aurora"
383
+ />
384
+ <ConnectionCard
385
+ title="Smithy API to Relational Database"
386
+ description="Connect a Smithy API to an Aurora relational database"
387
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-rdb`}
388
+ source="smithy"
389
+ target="aurora"
390
+ />
391
+ <ConnectionCard
392
+ title="TypeScript Agent to Relational Database"
393
+ description="Connect a TypeScript Agent to an Aurora relational database"
394
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-rdb`}
395
+ source="strands"
396
+ sourceBadge="typescript"
397
+ target="aurora"
398
+ />
399
+ <ConnectionCard
400
+ title="MCP Server to Relational Database"
401
+ description="Connect a TypeScript MCP Server to an Aurora relational database"
402
+ href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-rdb`}
403
+ source="mcp"
404
+ target="aurora"
405
+ />
406
+ </CardGrid>