@aws/nx-plugin-mcp 0.120.0 → 0.121.0
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 +23 -35
- package/docs/guides/astro-docs.mdx +142 -0
- package/docs/guides/connection/py-agent-a2a.mdx +105 -0
- package/docs/guides/connection/py-agent-mcp.mdx +147 -0
- package/docs/guides/connection/react-agui.mdx +240 -0
- package/docs/guides/connection/react-fastapi.mdx +1476 -0
- package/docs/guides/connection/react-py-agent.mdx +198 -0
- package/docs/guides/connection/react-smithy.mdx +1355 -0
- package/docs/guides/connection/react-trpc.mdx +447 -0
- package/docs/guides/connection/react-ts-agent.mdx +198 -0
- package/docs/guides/connection/smithy-rdb.mdx +161 -0
- package/docs/guides/connection/trpc-rdb.mdx +127 -0
- package/docs/guides/connection/ts-agent-a2a.mdx +106 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +144 -0
- package/docs/guides/connection/ts-agent-rdb.mdx +141 -0
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +135 -0
- package/docs/guides/connection.mdx +126 -0
- package/docs/guides/docker-bundling.mdx +403 -0
- package/docs/guides/fastapi.mdx +509 -0
- package/docs/guides/license.mdx +293 -0
- package/docs/guides/nx-generator.mdx +588 -0
- package/docs/guides/py-agent.mdx +483 -0
- package/docs/guides/py-mcp-server.mdx +161 -0
- package/docs/guides/python-lambda-function.mdx +207 -0
- package/docs/guides/python-project.mdx +228 -0
- package/docs/guides/react-website-auth.mdx +216 -0
- package/docs/guides/react-website.mdx +421 -0
- package/docs/guides/runtime-config.mdx +312 -0
- package/docs/guides/terraform-project.mdx +317 -0
- package/docs/guides/trpc.mdx +816 -0
- package/docs/guides/ts-agent.mdx +436 -0
- package/docs/guides/ts-lambda-function.mdx +218 -0
- package/docs/guides/ts-mcp-server.mdx +169 -0
- package/docs/guides/ts-nx-plugin.mdx +159 -0
- package/docs/guides/ts-rdb.mdx +759 -0
- package/docs/guides/ts-smithy-api.mdx +661 -0
- package/docs/guides/typescript-infrastructure.mdx +408 -0
- package/docs/guides/typescript-project.mdx +312 -0
- package/docs/guides/workspace.mdx +181 -0
- package/docs/snippets/agent/architecture.mdx +72 -0
- package/docs/snippets/agent/bedrock-deployment.mdx +172 -0
- package/docs/snippets/agent/runtime-arn.mdx +64 -0
- package/docs/snippets/api/api-architecture.mdx +93 -0
- package/docs/snippets/api/api-choice-note.mdx +6 -0
- package/docs/snippets/api/cors-configuration-cdk-note.mdx +25 -0
- package/docs/snippets/api/cors-configuration-terraform-note.mdx +28 -0
- package/docs/snippets/api/shared-constructs.mdx +38 -0
- package/docs/snippets/api/type-safe-api-integrations.mdx +643 -0
- package/docs/snippets/api/waf-configuration.mdx +37 -0
- package/docs/snippets/connection/a2a-infrastructure.mdx +63 -0
- package/docs/snippets/connection/lambda-rdb-ssl-requirements.mdx +40 -0
- package/docs/snippets/connection/mcp-server-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/connection/rdb-api-infrastructure.mdx +72 -0
- package/docs/snippets/connection/react-agent-infrastructure.mdx +61 -0
- package/docs/snippets/connection/strands-agent-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/lambda-function/architecture.mdx +36 -0
- package/docs/snippets/lambda-function/deploying-your-function.mdx +118 -0
- package/docs/snippets/mcp/architecture.mdx +58 -0
- package/docs/snippets/mcp/assistant-docs.mdx +10 -0
- package/docs/snippets/mcp/bedrock-deployment.mdx +167 -0
- package/docs/snippets/mcp/config.mdx +13 -0
- package/docs/snippets/mcp/configuration-py.mdx +42 -0
- package/docs/snippets/mcp/configuration-ts.mdx +53 -0
- package/docs/snippets/mcp/observability.mdx +8 -0
- package/docs/snippets/mcp/shared-constructs.mdx +32 -0
- package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +602 -0
- package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +915 -0
- package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +161 -0
- package/docs/snippets/pdk-migration/example/04-deploy.mdx +229 -0
- package/docs/snippets/pdk-migration/faq/aws-arch.mdx +17 -0
- package/docs/snippets/pdk-migration/faq/cdk-graph.mdx +29 -0
- package/docs/snippets/pdk-migration/faq/infrastructure-python-java.mdx +19 -0
- package/docs/snippets/pdk-migration/faq/pdk-nag.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/pipeline.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +310 -0
- package/docs/snippets/pdk-migration/faq/use-of-projen.mdx +15 -0
- package/docs/snippets/prerequisites.mdx +20 -0
- package/docs/snippets/required-prerequisites.mdx +12 -0
- package/docs/snippets/shared-constructs.mdx +40 -0
- package/docs/snippets/tools/acurl.mdx +73 -0
- package/docs/snippets/ts-bundle.mdx +14 -0
- package/package.json +1 -1
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TypeScript Projects
|
|
3
|
+
description: Reference documentation for TypeScript projects
|
|
4
|
+
generator: ts#project
|
|
5
|
+
---
|
|
6
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
8
|
+
import InstallCommand from '@components/install-command.astro';
|
|
9
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
10
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
11
|
+
import PackageManagerShortCommand from '@components/package-manager-short-command.astro';
|
|
12
|
+
import Link from '@components/link.astro';
|
|
13
|
+
|
|
14
|
+
The TypeScript project generator can be used to create a modern [TypeScript](https://www.typescriptlang.org/) library or application configured with best practices such as [ECMAScript Modules (ESM)](https://www.typescriptlang.org/docs/handbook/modules/reference.html), TypeScript [project references](https://www.typescriptlang.org/docs/handbook/project-references.html), [Vitest](https://vitest.dev/) for running tests and [ESLint](https://eslint.org/) for static analysis.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Generate a TypeScript Project
|
|
19
|
+
|
|
20
|
+
You can generate a new TypeScript project in two ways:
|
|
21
|
+
|
|
22
|
+
<RunGenerator generator="ts#project" />
|
|
23
|
+
|
|
24
|
+
### Options
|
|
25
|
+
|
|
26
|
+
<GeneratorParameters generator="ts#project" />
|
|
27
|
+
|
|
28
|
+
## Generator Output
|
|
29
|
+
|
|
30
|
+
The generator will create the following project structure in the `<directory>/<name>` directory:
|
|
31
|
+
|
|
32
|
+
<FileTree>
|
|
33
|
+
|
|
34
|
+
- src TypeScript source code
|
|
35
|
+
- index.ts
|
|
36
|
+
- project.json Project configuration and build targets
|
|
37
|
+
- tsconfig.json Base TypeScript configuration for this project (extends workspace root tsconfig.base.json)
|
|
38
|
+
- tsconfig.lib.json TypeScript configuration for your library (your runtime or packaged source)
|
|
39
|
+
- tsconfig.spec.json TypeScript configuration for your tests
|
|
40
|
+
- vitest.config.mts Configuration for Vitest
|
|
41
|
+
- eslint.config.mjs Configuration for ESLint
|
|
42
|
+
|
|
43
|
+
</FileTree>
|
|
44
|
+
|
|
45
|
+
:::tip[No package.json Needed]
|
|
46
|
+
Notice that no `package.json` file is created for this project! You can find out why [below](#dependencies).
|
|
47
|
+
:::
|
|
48
|
+
|
|
49
|
+
You will also notice some changes to the following files in your workspace root:
|
|
50
|
+
|
|
51
|
+
<FileTree>
|
|
52
|
+
|
|
53
|
+
- nx.json Nx configuration is updated to configure the @nx/js/typescript plugin for your project
|
|
54
|
+
- tsconfig.base.json a TypeScript alias is set up for your project so that it can be imported by other projects in your workspace
|
|
55
|
+
- tsconfig.json a TypeScript project reference is added for your project
|
|
56
|
+
|
|
57
|
+
</FileTree>
|
|
58
|
+
|
|
59
|
+
## Writing TypeScript Source Code
|
|
60
|
+
|
|
61
|
+
Add your TypeScript code in the `src` directory.
|
|
62
|
+
|
|
63
|
+
### ESM Import Syntax
|
|
64
|
+
|
|
65
|
+
Since your TypeScript project is an ES Module, be sure to write your import statements with the correct ESM syntax, explicitly referencing the file extension:
|
|
66
|
+
|
|
67
|
+
```ts title="index.ts" ".js"
|
|
68
|
+
import { sayHello } from './hello.js';
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
:::note[TypeScript References]
|
|
72
|
+
Even though we're using TypeScript, and `sayHello` is defined in `hello.ts`, we use the `.js` file extension in our import. You can read more about this [here](https://www.typescriptlang.org/docs/handbook/modules/reference.html).
|
|
73
|
+
:::
|
|
74
|
+
|
|
75
|
+
### Exporting for Other TypeScript Projects
|
|
76
|
+
|
|
77
|
+
The entry point for your TypeScript project is `src/index.ts`. You can add exports here for anything you'd like other projects to be able to import:
|
|
78
|
+
|
|
79
|
+
```ts title="src/index.ts"
|
|
80
|
+
export { sayHello } from './hello.js';
|
|
81
|
+
export * from './algorithms/index.js';
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Importing your Library Code in Other Projects
|
|
85
|
+
|
|
86
|
+
[TypeScript aliases](https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths) for your project are configured in your workspace `tsconfig.base.json`, which allows you to reference your TypeScript project from other TypeScript projects:
|
|
87
|
+
|
|
88
|
+
```ts title="packages/my-other-project/src/index.ts"
|
|
89
|
+
import { sayHello } from ':my-scope/my-library';
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
:::note[Project Aliases]
|
|
93
|
+
Aliases for your TypeScript projects begin with a `:` rather than the traditional `@`, since this avoids the possibility of name conflicts between local packages in your workspace and remote packages in [NPM](https://www.npmjs.com/).
|
|
94
|
+
:::
|
|
95
|
+
|
|
96
|
+
When you add an import statement for a new project in your workspace for the first time, you will likely see an error in your IDE similar to the below:
|
|
97
|
+
|
|
98
|
+
<details>
|
|
99
|
+
<summary>Import error</summary>
|
|
100
|
+
|
|
101
|
+
```bash wrap
|
|
102
|
+
File '/path/to/my/workspace/packages/my-library/src/index.ts' is not under 'rootDir' '/path/to/my/workspace/packages/my-consumer'. 'rootDir' is expected to contain all source files.
|
|
103
|
+
File is ECMAScript module because '/path/to/my/workspace/package.json' has field "type" with value "module" ts(6059)
|
|
104
|
+
File '/path/to/my/workspace/packages/my-library/src/index.ts' is not listed within the file list of project '/path/to/my/workspace/packages/my-consumer/tsconfig.lib.json'. Projects must list all files or use an 'include' pattern.
|
|
105
|
+
File is ECMAScript module because '/path/to/my/workspace/package.json' has field "type" with value "module" ts(6307)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
</details>
|
|
109
|
+
|
|
110
|
+
This is because a [project reference](https://www.typescriptlang.org/docs/handbook/project-references.html) has not yet been set up.
|
|
111
|
+
|
|
112
|
+
TypeScript projects are configured with the Nx TypeScript Sync generator out of the box, saving you from needing to manually configure the project reference. Simply run the following command and Nx will add the required configuration:
|
|
113
|
+
|
|
114
|
+
<NxCommands commands={['sync']} />
|
|
115
|
+
|
|
116
|
+
After this, the error in your IDE should be gone and you are ready to use your library.
|
|
117
|
+
|
|
118
|
+
:::tip[Build Shortcut]
|
|
119
|
+
You can also just build your project and you'll be prompted with a message such as:
|
|
120
|
+
|
|
121
|
+
```bash wrap
|
|
122
|
+
[@nx/js:typescript-sync]: Some TypeScript configuration files are missing project references to the projects they depend on or contain outdated project references.
|
|
123
|
+
|
|
124
|
+
This will result in an error in CI.
|
|
125
|
+
|
|
126
|
+
? Would you like to sync the identified changes to get your workspace up to date?
|
|
127
|
+
Yes, sync the changes and run the tasks
|
|
128
|
+
No, run the tasks without syncing the changes
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Select `Yes` to allow Nx to update your project references.
|
|
132
|
+
:::
|
|
133
|
+
|
|
134
|
+
### Keeping Path Aliases In Sync
|
|
135
|
+
|
|
136
|
+
If you add custom `compilerOptions.paths` entries in a project's `tsconfig.json`, TypeScript stops inheriting the workspace aliases defined in `tsconfig.base.json`. The hidden `ts#sync` generator runs before the `compile` target (configured in `nx.json`) to copy any missing base aliases into `tsconfig.json`, `tsconfig.lib.json` and `tsconfig.app.json` files that already declare `paths`. To opt out, remove `@aws/nx-plugin:ts#sync` from `targetDefaults.compile.syncGenerators` in `nx.json`.
|
|
137
|
+
|
|
138
|
+
### Dependencies
|
|
139
|
+
|
|
140
|
+
You will notice that your TypeScript project does not have a `package.json` file, which might be unexpected if you are used to traditional TypeScript monorepos.
|
|
141
|
+
|
|
142
|
+
To add a dependency for any TypeScript package in your monorepo, simply add the dependency to the `package.json` in the root of your workspace. You can do this via the command line for your package manager:
|
|
143
|
+
|
|
144
|
+
<InstallCommand pkg="some-npm-package" />
|
|
145
|
+
|
|
146
|
+
The dependency is then available for any of the TypeScript projects in your workspace to use.
|
|
147
|
+
|
|
148
|
+
#### Runtime Code
|
|
149
|
+
|
|
150
|
+
When you use your TypeScript project as runtime code (for example as the handler for an AWS Lambda function), it's recommended that you use a tool such as [Rolldown](https://rolldown.rs/) to bundle your project, since this can [tree-shake](https://rolldown.rs/in-depth/why-bundlers) to ensure that only the dependencies your project actually references are included.
|
|
151
|
+
|
|
152
|
+
You can achieve this by adding a target such as the following to your `project.json` file:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
...
|
|
157
|
+
"targets": {
|
|
158
|
+
...
|
|
159
|
+
"bundle": {
|
|
160
|
+
"cache": true,
|
|
161
|
+
"executor": "nx:run-commands",
|
|
162
|
+
"outputs": ["{workspaceRoot}/dist/packages/my-library/bundle"],
|
|
163
|
+
"options": {
|
|
164
|
+
"command": "rolldown -c rolldown.config.ts"
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
And adding the `rolldown.config.ts` file as follows:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
// rolldown.config.ts
|
|
175
|
+
import { defineConfig } from 'rolldown';
|
|
176
|
+
|
|
177
|
+
export default defineConfig([
|
|
178
|
+
{
|
|
179
|
+
input: 'src/index.ts',
|
|
180
|
+
output: {
|
|
181
|
+
file: '../../dist/packages/my-library/bundle/index.js',
|
|
182
|
+
format: 'cjs',
|
|
183
|
+
inlineDynamicImports: true,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
:::note[Bundle Configuration]
|
|
190
|
+
Note that in the above target, we chose `src/index.ts` as our entrypoint for the bundle, which means that code exported from this file will be included in the bundle, along with all of its dependencies.
|
|
191
|
+
:::
|
|
192
|
+
|
|
193
|
+
:::tip[Lambda Functions]
|
|
194
|
+
If you're building an AWS Lambda function, check out the <Link path="/guides/ts-lambda-function">`ts#lambda-function`</Link> generator as this configures bundling for you, as well as generating infrastructure and adding observability and type-safety.
|
|
195
|
+
:::
|
|
196
|
+
|
|
197
|
+
#### Publishing to NPM
|
|
198
|
+
|
|
199
|
+
If you are publishing your TypeScript project to NPM, you must create a `package.json` file for it.
|
|
200
|
+
|
|
201
|
+
This must declare the dependencies that your project references. Since at build time your project will resolve dependencies installed via the workspace root `package.json`, it's recommended to configure the [Nx Dependency Checks ESLint Plugin](https://nx.dev/nx-api/eslint-plugin/documents/dependency-checks) to ensure that your published project's `package.json` includes all dependencies you use in your project.
|
|
202
|
+
|
|
203
|
+
### Building
|
|
204
|
+
|
|
205
|
+
Your TypeScript project is configured with a `build` target (defined in `project.json`), which you can run via:
|
|
206
|
+
|
|
207
|
+
<NxCommands commands={['build <project-name>']} />
|
|
208
|
+
|
|
209
|
+
Where `<project-name>` is the fully qualified name of your project.
|
|
210
|
+
|
|
211
|
+
The `build` target will compile, lint and test your project.
|
|
212
|
+
|
|
213
|
+
Build output can be found in the root `dist` folder in your workspace, inside a directory for your package and target, for example `dist/packages/<my-library>/tsc`
|
|
214
|
+
|
|
215
|
+
To build all of the projects in your workspace, run:
|
|
216
|
+
|
|
217
|
+
<NxCommands commands={['run-many --target build']} />
|
|
218
|
+
|
|
219
|
+
Or use the shorthand command:
|
|
220
|
+
|
|
221
|
+
<PackageManagerShortCommand commands={["build"]} />
|
|
222
|
+
|
|
223
|
+
## Testing
|
|
224
|
+
|
|
225
|
+
[Vitest](https://vitest.dev/) is configured for testing your project.
|
|
226
|
+
|
|
227
|
+
### Writing Tests
|
|
228
|
+
|
|
229
|
+
Tests should be written in `.spec.ts` or `.test.ts` files, co-located in your project's `src` folder.
|
|
230
|
+
|
|
231
|
+
For example:
|
|
232
|
+
|
|
233
|
+
<FileTree>
|
|
234
|
+
- src
|
|
235
|
+
- hello.ts Library source code
|
|
236
|
+
- hello.spec.ts Tests for hello.ts
|
|
237
|
+
</FileTree>
|
|
238
|
+
|
|
239
|
+
Vitest provides Jest-like syntax for defining tests, with utilities such as `describe`, `it`, `test` and `expect`.
|
|
240
|
+
|
|
241
|
+
```ts title="hello.spec.ts"
|
|
242
|
+
import { sayHello } from './hello.js';
|
|
243
|
+
|
|
244
|
+
describe('sayHello', () => {
|
|
245
|
+
|
|
246
|
+
it('should greet the caller', () => {
|
|
247
|
+
expect(sayHello('Darth Vader')).toBe('Hello, Darth Vader!');
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
For more details about how to write tests, and features such as mocking dependencies, refer to the [Vitest documentation](https://vitest.dev/guide/#writing-tests)
|
|
255
|
+
|
|
256
|
+
### Running Tests
|
|
257
|
+
|
|
258
|
+
Tests will run as part of the `build` target for your project, but you can also run them separately by running the `test` target:
|
|
259
|
+
|
|
260
|
+
<NxCommands commands={['test <project-name>']} />
|
|
261
|
+
|
|
262
|
+
You can run an individual test or suite of tests using Vitest's `-t` flag. Pass it after a `--` separator so Nx forwards it to Vitest rather than consuming it as its own `--target` option:
|
|
263
|
+
|
|
264
|
+
<NxCommands commands={["test <project-name> -- -t 'sayHello'"]} />
|
|
265
|
+
|
|
266
|
+
:::tip[VSCode Integration]
|
|
267
|
+
If you are a VSCode user, we recommend installing the [Vitest Runner for VSCode that actually works](https://marketplace.visualstudio.com/items?itemName=rluvaton.vscode-vitest) extension, which allows you to run, watch or debug tests from your IDE.
|
|
268
|
+
:::
|
|
269
|
+
|
|
270
|
+
## Linting
|
|
271
|
+
|
|
272
|
+
TypeScript projects use [ESLint](https://eslint.org/) for linting, along with [Prettier](https://prettier.io/) for formatting.
|
|
273
|
+
|
|
274
|
+
We recommend configuring ESLint in the workspace root `eslint.config.mjs` file, as changes to this will apply to all TypeScript projects in your workspace and ensure consistency.
|
|
275
|
+
|
|
276
|
+
Likewise, you can configure Prettier in the root `.prettierrc` file.
|
|
277
|
+
|
|
278
|
+
### Running the Linter
|
|
279
|
+
|
|
280
|
+
To invoke the linter to check your project, you can run the `lint` target.
|
|
281
|
+
|
|
282
|
+
<NxCommands commands={["lint <project-name>"]} />
|
|
283
|
+
|
|
284
|
+
### Fixing Lint Issues
|
|
285
|
+
|
|
286
|
+
The majority of linting or formatting issues can be fixed automatically. You can tell ESLint to fix lint issues by running with the `--configuration=fix` argument.
|
|
287
|
+
|
|
288
|
+
<NxCommands commands={["lint <project-name> --configuration=fix"]} />
|
|
289
|
+
|
|
290
|
+
Similarly if you would like to fix all lint issues in all packages in your workspace, you can run:
|
|
291
|
+
|
|
292
|
+
<NxCommands commands={["run-many --target lint --all --configuration=fix"]} />
|
|
293
|
+
|
|
294
|
+
:::tip[Shorthand Command]
|
|
295
|
+
This has a shorthand command from the root of your workspace:
|
|
296
|
+
|
|
297
|
+
<PackageManagerShortCommand commands={["lint"]} />
|
|
298
|
+
:::
|
|
299
|
+
|
|
300
|
+
### Skipping Lint Issues
|
|
301
|
+
|
|
302
|
+
To avoid linting issues slowing you down during development (particularly if you have non auto-fixable issues in your project), you can run a build with the `skip-lint` configuration:
|
|
303
|
+
|
|
304
|
+
<NxCommands commands={["run-many --target build --configuration=skip-lint"]} />
|
|
305
|
+
|
|
306
|
+
This will still run ESLint as part of the build, but the lint target will always be considered successful.
|
|
307
|
+
|
|
308
|
+
:::tip[Shorthand Command]
|
|
309
|
+
This has a shorthand command from the root of your workspace:
|
|
310
|
+
|
|
311
|
+
<PackageManagerShortCommand commands={["build:skip-lint"]} />
|
|
312
|
+
:::
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Workspace
|
|
3
|
+
description: Reference documentation for workspaces
|
|
4
|
+
---
|
|
5
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
6
|
+
import Link from '@components/link.astro';
|
|
7
|
+
import CreateNxWorkspaceCommand from '@components/create-nx-workspace-command.astro';
|
|
8
|
+
import PackageManagerShortCommand from '@components/package-manager-short-command.astro';
|
|
9
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
10
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
11
|
+
|
|
12
|
+
When you create a new workspace with `@aws/nx-plugin`, the preset generator sets up an [Nx monorepo](https://nx.dev) with sensible defaults for building on AWS.
|
|
13
|
+
|
|
14
|
+
## Creating a Workspace
|
|
15
|
+
|
|
16
|
+
<CreateNxWorkspaceCommand workspace="my-project" />
|
|
17
|
+
|
|
18
|
+
### Options
|
|
19
|
+
|
|
20
|
+
<GeneratorParameters generator="preset" />
|
|
21
|
+
|
|
22
|
+
### Workspace Structure
|
|
23
|
+
|
|
24
|
+
<FileTree>
|
|
25
|
+
- packages/ Your projects live here
|
|
26
|
+
- package.json Root package.json for your monorepo
|
|
27
|
+
- nx.json Nx configuration (common targets, sync generators, caching)
|
|
28
|
+
- tsconfig.base.json Root TypeScript configuration
|
|
29
|
+
- aws-nx-plugin.config.mts Nx Plugin for AWS configuration
|
|
30
|
+
- .git-secrets/ Vendored git-secrets bash script for credential scanning
|
|
31
|
+
- .husky/ Git hooks
|
|
32
|
+
</FileTree>
|
|
33
|
+
|
|
34
|
+
## Nx
|
|
35
|
+
|
|
36
|
+
Nx is a language-agnostic build system for monorepos, managing dependencies between projects written in any programming language and the tasks to build them. You can learn more on the [Nx website](https://nx.dev/getting-started/intro).
|
|
37
|
+
|
|
38
|
+
### Projects
|
|
39
|
+
|
|
40
|
+
An Nx monorepo is made up of one or more projects, each with a `project.json` file. The `project.json` defines a project's tasks, known as _targets_, which define how a project is built, run locally, tested, etc. It also defines dependencies between targets within or across projects.
|
|
41
|
+
|
|
42
|
+
For example, a `project.json` might define a `build` target that depends on all upstream projects being built first:
|
|
43
|
+
|
|
44
|
+
```json title="packages/my-project/project.json"
|
|
45
|
+
{
|
|
46
|
+
"name": "@my-workspace/my-project",
|
|
47
|
+
"targets": {
|
|
48
|
+
"build": {
|
|
49
|
+
"executor": "@nx/js:tsc",
|
|
50
|
+
"dependsOn": ["^build"]
|
|
51
|
+
},
|
|
52
|
+
"test": {
|
|
53
|
+
"command": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
:::tip
|
|
60
|
+
For projects in languages not directly supported by the Nx Plugin for AWS, you can often find a generator in the [Nx Plugin Registry](https://nx.dev/plugin-registry) to help. It's simple to add a project of any language into your monorepo however — just add a `project.json` file and define its `build` target to run the specific build command for a project of that language.
|
|
61
|
+
:::
|
|
62
|
+
|
|
63
|
+
For details on how TypeScript and Python projects are set up, refer to the <Link path="guides/typescript-project">ts#project</Link> and <Link path="guides/python-project">py#project</Link> generator guides.
|
|
64
|
+
|
|
65
|
+
### Caching
|
|
66
|
+
|
|
67
|
+
Nx caches the output of previously executed targets and replays them when the inputs haven't changed. This dramatically speeds up builds, tests, and linting — especially in CI. If you encounter stale or unexpected behaviour, reset the cache with:
|
|
68
|
+
|
|
69
|
+
<NxCommands commands={['reset']} />
|
|
70
|
+
|
|
71
|
+
For more details, see the [Nx caching documentation](https://nx.dev/features/cache-task-results).
|
|
72
|
+
|
|
73
|
+
## Single Version Policy
|
|
74
|
+
|
|
75
|
+
The default monorepo setup uses a [single version policy](https://nx.dev/concepts/decisions/dependency-management#single-version-policy) for both Node and Python based projects.
|
|
76
|
+
|
|
77
|
+
This means that all projects within your monorepo use the same version of dependencies by default, reducing issues related to packages in the same monorepo running into version mismatch issues.
|
|
78
|
+
|
|
79
|
+
From a Node perspective this means a single lockfile at the root with a single `node_modules` containing all dependencies. If you need to add a new dependency, add it in the root `package.json`.
|
|
80
|
+
|
|
81
|
+
From a Python perspective, this means a single `.venv` in the root of the monorepo with all dependencies installed into it. Each Python project has its own `pyproject.toml`, but the versions of those dependencies are managed by the UV workspace and subsequently written out to the `uv.lock` file in the root.
|
|
82
|
+
|
|
83
|
+
## Common Commands
|
|
84
|
+
|
|
85
|
+
### Build
|
|
86
|
+
|
|
87
|
+
Build all projects in the workspace:
|
|
88
|
+
|
|
89
|
+
<PackageManagerShortCommand commands={["build"]} />
|
|
90
|
+
|
|
91
|
+
### Lint
|
|
92
|
+
|
|
93
|
+
Lint and auto-fix all projects:
|
|
94
|
+
|
|
95
|
+
<PackageManagerShortCommand commands={["lint"]} />
|
|
96
|
+
|
|
97
|
+
### Test
|
|
98
|
+
|
|
99
|
+
Run tests across all projects:
|
|
100
|
+
|
|
101
|
+
<PackageManagerShortCommand commands={["test"]} />
|
|
102
|
+
|
|
103
|
+
### Dev
|
|
104
|
+
|
|
105
|
+
If you have a <Link path="guides/react-website">website</Link>, start it and all connected components locally:
|
|
106
|
+
|
|
107
|
+
<PackageManagerShortCommand commands={["dev"]} />
|
|
108
|
+
|
|
109
|
+
### Sync
|
|
110
|
+
|
|
111
|
+
Run any [sync generators](https://nx.dev/concepts/sync-generators), which for example synchronise TypeScript project references (refer to the <Link path="guides/typescript-project">ts#project</Link> generator guide for more details):
|
|
112
|
+
|
|
113
|
+
<NxCommands commands={['sync']} />
|
|
114
|
+
|
|
115
|
+
### Run Specific Targets
|
|
116
|
+
|
|
117
|
+
You can run specific targets for specific projects with:
|
|
118
|
+
|
|
119
|
+
<NxCommands commands={['<target> <project>']} />
|
|
120
|
+
|
|
121
|
+
For example:
|
|
122
|
+
|
|
123
|
+
<NxCommands commands={['build website']} />
|
|
124
|
+
|
|
125
|
+
This will run the chosen target as well as the targets it depends on.
|
|
126
|
+
|
|
127
|
+
## What's Included
|
|
128
|
+
|
|
129
|
+
### Linting
|
|
130
|
+
|
|
131
|
+
New workspaces are configured with [ESLint](https://eslint.org/) for static analysis and [Prettier](https://prettier.io/) for code formatting. Running `lint` applies both to all projects.
|
|
132
|
+
|
|
133
|
+
### Git Secrets
|
|
134
|
+
|
|
135
|
+
New workspaces include [git-secrets](https://github.com/awslabs/git-secrets) pre-commit hooks that scan staged files for AWS credential patterns before each commit. This prevents accidentally committing access keys, secret keys, and other sensitive values.
|
|
136
|
+
|
|
137
|
+
#### Suppressing False Positives
|
|
138
|
+
|
|
139
|
+
Patterns in git-secrets use [egrep-compatible regular expressions](https://github.com/awslabs/git-secrets#options-for-add). If git-secrets blocks a commit that does not contain real credentials:
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
# Allow a specific regex pattern
|
|
143
|
+
git secrets --add --allowed 'my-regex-pattern'
|
|
144
|
+
|
|
145
|
+
# Allow a literal string (special characters are escaped)
|
|
146
|
+
git secrets --add --allowed --literal 'my-literal+string'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
You can also create a `.gitallowed` file at the repository root with one egrep-compatible regex per line (shared with your team via version control):
|
|
150
|
+
|
|
151
|
+
```text title=".gitallowed"
|
|
152
|
+
# Allow test fixtures
|
|
153
|
+
tests/fixtures/.*
|
|
154
|
+
# Allow a specific string
|
|
155
|
+
EXAMPLE[A-Z]{16}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
For full details on managing patterns, see the [git-secrets documentation](https://github.com/awslabs/git-secrets#readme).
|
|
159
|
+
|
|
160
|
+
## Nx Plugin for AWS Configuration
|
|
161
|
+
|
|
162
|
+
The workspace ships with an `aws-nx-plugin.config.mts` file at the root. Generators read this file to pick sensible defaults so you don't have to pass the same flags every time. Two settings are particularly useful:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// aws-nx-plugin.config.mts
|
|
166
|
+
import { AwsNxPluginConfig } from '@aws/nx-plugin';
|
|
167
|
+
|
|
168
|
+
export default {
|
|
169
|
+
iac: {
|
|
170
|
+
provider: 'CDK', // or 'Terraform'
|
|
171
|
+
},
|
|
172
|
+
containers: {
|
|
173
|
+
engine: 'docker', // or 'finch'
|
|
174
|
+
},
|
|
175
|
+
} satisfies AwsNxPluginConfig;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
- **`iac.provider`** — the default infrastructure-as-code provider (`CDK` or `Terraform`) used by generators that emit infrastructure (e.g. `ts#infra`, `ts#trpc-api`, `py#fast-api`). Generators that accept an `--iacProvider` flag default to `Inherit`, which reads this value.
|
|
179
|
+
- **`containers.engine`** — the container CLI (`docker` or `finch`) baked into generated build/push/login commands. CDK image-asset builds also pick this up via the `CDK_DOCKER` environment variable. See the <Link path="guides/docker-bundling">Docker bundling guide</Link> for details.
|
|
180
|
+
|
|
181
|
+
You can edit either setting at any time — subsequent generator runs will pick up the new value.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Agent Architecture
|
|
3
|
+
---
|
|
4
|
+
import { Tabs, TabItem } from '@astrojs/starlight/components';
|
|
5
|
+
|
|
6
|
+
<Tabs syncKey="computeType">
|
|
7
|
+
<TabItem label="Bedrock AgentCore Runtime" _filter={{ computeType: 'BedrockAgentCoreRuntime' }}>
|
|
8
|
+
|
|
9
|
+
When deployed to [Bedrock AgentCore Runtime](https://aws.amazon.com/bedrock/agentcore/), the agent is built into a container image, pushed to Amazon ECR and run in AgentCore Runtime. Clients invoke the AgentCore Runtime data plane endpoint, which forwards requests to your agent. The agent calls Amazon Bedrock for model inference and may invoke tools, MCP servers, or downstream APIs.
|
|
10
|
+
|
|
11
|
+
```d2 inline=true
|
|
12
|
+
direction: right
|
|
13
|
+
|
|
14
|
+
client: Client {
|
|
15
|
+
shape: image
|
|
16
|
+
icon: /nx-plugin-for-aws/icons/aws/client.svg
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ecr: ECR {
|
|
20
|
+
shape: image
|
|
21
|
+
icon: /nx-plugin-for-aws/icons/aws/ecr.svg
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
agentcore: Strands Agent\n(AgentCore Runtime) {
|
|
25
|
+
shape: image
|
|
26
|
+
icon: /nx-plugin-for-aws/icons/aws/bedrock-agentcore.svg
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
bedrock: Bedrock\n(Model Inference) {
|
|
30
|
+
shape: image
|
|
31
|
+
icon: /nx-plugin-for-aws/icons/aws/bedrock.svg
|
|
32
|
+
near: top-right
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
cw: CloudWatch\n(Logs, Metrics) {
|
|
36
|
+
shape: image
|
|
37
|
+
icon: /nx-plugin-for-aws/icons/aws/cloudwatch.svg
|
|
38
|
+
near: bottom-right
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
client -> agentcore
|
|
42
|
+
ecr -> agentcore: Container\nimage
|
|
43
|
+
agentcore -> bedrock: InvokeModel
|
|
44
|
+
agentcore -> cw
|
|
45
|
+
```
|
|
46
|
+
</TabItem>
|
|
47
|
+
<TabItem label="None (local only)" _filter={{ computeType: 'None' }}>
|
|
48
|
+
|
|
49
|
+
With `computeType: None`, no AWS infrastructure is generated. The agent runs as a local process and calls Amazon Bedrock for model inference.
|
|
50
|
+
|
|
51
|
+
```d2 inline=true
|
|
52
|
+
direction: right
|
|
53
|
+
|
|
54
|
+
client: Client {
|
|
55
|
+
shape: image
|
|
56
|
+
icon: /nx-plugin-for-aws/icons/aws/client.svg
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
agent: Strands Agent\n(local process) {
|
|
60
|
+
shape: rectangle
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
bedrock: Bedrock\n(Model Inference) {
|
|
64
|
+
shape: image
|
|
65
|
+
icon: /nx-plugin-for-aws/icons/aws/bedrock.svg
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
client -> agent
|
|
69
|
+
agent -> bedrock: InvokeModel
|
|
70
|
+
```
|
|
71
|
+
</TabItem>
|
|
72
|
+
</Tabs>
|