@aws/nx-plugin-mcp 1.7.2 → 1.9.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.
|
@@ -381,6 +381,29 @@ function UserList() {
|
|
|
381
381
|
}
|
|
382
382
|
```
|
|
383
383
|
|
|
384
|
+
### Prefetching in Route Loaders
|
|
385
|
+
|
|
386
|
+
If your website uses TanStack Router, the generator also adds the query client and the tRPC options proxy to the router context. The context property is named after the API in camel case, so a `MyApi` API is available as `context.myApi` and several APIs can be connected to the same website. Use them to prefetch data in a route `loader`, before the route renders:
|
|
387
|
+
|
|
388
|
+
```tsx {5-7}
|
|
389
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
390
|
+
|
|
391
|
+
export const Route = createFileRoute('/users')({
|
|
392
|
+
loader: async ({ context }) => {
|
|
393
|
+
// The context properties are optional, so use a non-null assertion or a guard
|
|
394
|
+
const { queryClient, myApi } = context;
|
|
395
|
+
await queryClient!.ensureQueryData(myApi!.users.list.queryOptions());
|
|
396
|
+
},
|
|
397
|
+
component: UserList,
|
|
398
|
+
});
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
The component can then read the prefetched data with `useQuery(trpc.users.list.queryOptions())`, which resolves immediately from the cache.
|
|
402
|
+
|
|
403
|
+
:::note
|
|
404
|
+
An API named `Auth`, `QueryClient` or `RuntimeConfig` would clash with the `auth`, `queryClient` and `runtimeConfig` context properties, so it is not added to the router context and the generator logs a warning. Use a different API name if you need it in the router context.
|
|
405
|
+
:::
|
|
406
|
+
|
|
384
407
|
### Infinite Queries
|
|
385
408
|
|
|
386
409
|
Handle pagination with infinite queries:
|
|
@@ -57,10 +57,10 @@ The generator adds the following files to your project. The source folder is nam
|
|
|
57
57
|
- Dockerfile Container image definition
|
|
58
58
|
- .dockerignore Files left out of the image build context
|
|
59
59
|
- pyproject.toml Updated with FastAPI and uvicorn dependencies
|
|
60
|
-
- project.json Updated with the `bundle-arm`
|
|
60
|
+
- project.json Updated with a bundle target for the service's CPU architecture (`bundle-arm` or `bundle-x86`), the aggregate `bundle` target, and the `<name>-serve`, `<name>-docker` and `<name>-trivy` targets for your service
|
|
61
61
|
</FileTree>
|
|
62
62
|
|
|
63
|
-
Target names start with the `name` option, or with `container` if you leave it out. For example, the targets are `container-serve`, `container-docker` and `container-trivy` without a name, and `orders-serve`, `orders-docker` and `orders-trivy` for `--name=orders`. The
|
|
63
|
+
Target names start with the `name` option, or with `container` if you leave it out. For example, the targets are `container-serve`, `container-docker` and `container-trivy` without a name, and `orders-serve`, `orders-docker` and `orders-trivy` for `--name=orders`. The bundle targets are shared by everything the project bundles.
|
|
64
64
|
|
|
65
65
|
<OptionFilter when={{ infra: 'ecs' }} description="ECS service infrastructure">
|
|
66
66
|
### Infrastructure
|
|
@@ -129,7 +129,7 @@ The server also has a sample route that you replace with your own routes. `GET /
|
|
|
129
129
|
|
|
130
130
|
## Building and Scanning the Image
|
|
131
131
|
|
|
132
|
-
The `<name>-docker` target builds
|
|
132
|
+
The `<name>-docker` target builds an image of your service for the CPU architecture in the `architecture` option, `linux/arm64` or `linux/amd64`. It runs the matching bundle target first, `bundle-arm` or `bundle-x86`, which writes your code and its dependencies for that architecture to `dist/<project root>/bundle-arm` or `dist/<project root>/bundle-x86`. The aggregate `bundle` target depends on it. The `<name>-docker` target then copies that folder, the `Dockerfile` and the `.dockerignore` into `dist/<project root>/docker/<name>`, and builds the image with that folder as the build context (the files the image build can read). It uses the container engine your workspace is set up with, `docker` or [Finch](https://runfinch.com/). The target runs as part of the aggregate `docker` target, which builds every image in the project.
|
|
133
133
|
|
|
134
134
|
<NxCommands commands={['run your-project:container-docker']} />
|
|
135
135
|
|
|
@@ -362,6 +362,33 @@ secrets = { API_KEY = aws_secretsmanager_secret.api_key.arn }
|
|
|
362
362
|
</Fragment>
|
|
363
363
|
</Infrastructure>
|
|
364
364
|
|
|
365
|
+
#### CPU Architecture
|
|
366
|
+
|
|
367
|
+
The `architecture` option sets the CPU the tasks run on, the platform the image is built for, and the platform the bundle resolves its Python wheels for: `ARM64` or `X86_64`. ARM64 runs on [AWS Graviton](https://aws.amazon.com/ec2/graviton/) processors, which AWS Fargate bills at a lower rate per vCPU and per GB of memory than X86_64. See [AWS Fargate pricing](https://aws.amazon.com/fargate/pricing/) for the rates in your Region.
|
|
368
|
+
|
|
369
|
+
Leave the option out and the generator uses the architecture of the machine you run it on, so `nx run your-project:container-docker` builds natively and needs no emulator. Re-running the generator keeps the architecture it generated the first time, whatever machine you re-run it on, because that architecture is already in your deployed task definition and in the name of your bundle target.
|
|
370
|
+
|
|
371
|
+
The architecture is fixed when the service is first generated. The generator never rewrites the infrastructure it vended, so moving an existing service to the other architecture takes two steps:
|
|
372
|
+
|
|
373
|
+
1. Change the architecture in the vended code. In CDK, the `architecture:` line in `packages/common/constructs/src/app/services/<name>.ts`. In Terraform, `cpu_architecture` in the `module "ecs_service"` block of `packages/common/terraform/src/app/services/<name>/<name>.tf`.
|
|
374
|
+
2. Re-run the generator with `--architecture` set to the same value, so the `<name>-docker` target builds for it and the bundle resolves wheels for it.
|
|
375
|
+
|
|
376
|
+
Then redeploy. If you pass an architecture that differs from the one the generator recorded, it warns and names the file you have to change.
|
|
377
|
+
|
|
378
|
+
Doing step 2 and forgetting step 1 fails differently per provider, and neither failure is loud. In Terraform, the task definition keeps the old architecture while the image Terraform pushes has the new one, so the task does not start. In CDK, the deployed image is built from the vended construct, so it has the old architecture, while the bundle inside it holds wheels for the architecture you asked for: the container then crashes on its first compiled import.
|
|
379
|
+
|
|
380
|
+
A switch also leaves the previous architecture's bundle target in place, because the bundle targets are shared by everything in the project that bundles for their platform. The warning names it; remove it once nothing else uses it.
|
|
381
|
+
|
|
382
|
+
`architecture` is also a prop of the vended service construct, so a stack can pass a different one for a single instantiation. That changes what deploys but not what the `<name>-docker` and `<name>-trivy` targets build, so keep the two in step yourself.
|
|
383
|
+
|
|
384
|
+
Building an ARM64 image on an x86_64 machine, or an X86_64 image on an arm64 machine, fails with `exec format error` unless you install an emulator. The generator warns you when the architecture it is about to generate is not the one your machine runs. See <Link path="/troubleshooting/docker">Troubleshooting Docker</Link>.
|
|
385
|
+
|
|
386
|
+
| Setting | CDK prop | Terraform variable | Default |
|
|
387
|
+
| --- | --- | --- | --- |
|
|
388
|
+
| CPU architecture | `architecture` | `cpu_architecture` | `'ARM64'` |
|
|
389
|
+
|
|
390
|
+
The generator writes the architecture it chose into your service's construct and module, so that default applies only when you use the generic `EcsService` construct or the `ecs-service` module yourself.
|
|
391
|
+
|
|
365
392
|
#### Sizing and Scaling
|
|
366
393
|
|
|
367
394
|
Each task gets 256 CPU units (a quarter of a vCPU) and 512 MiB of memory by default. The service starts one task, and autoscaling keeps between one and two tasks running, adding tasks when average CPU use goes above 70%.
|
|
@@ -129,7 +129,7 @@ The server also has a sample route that you replace with your own routes. `GET /
|
|
|
129
129
|
|
|
130
130
|
## Building and Scanning the Image
|
|
131
131
|
|
|
132
|
-
The `<name>-docker` target builds
|
|
132
|
+
The `<name>-docker` target builds an image of your service for the CPU architecture in the `architecture` option, `linux/arm64` or `linux/amd64`. It runs the `bundle` target first, so the image holds the bundled server. It then copies the `Dockerfile` and `.dockerignore` into the bundle output folder, `dist/<project root>/bundle/container/<name>`, and builds the image with that folder as the build context (the files the image build can read). It uses the container engine your workspace is set up with, `docker` or [Finch](https://runfinch.com/). The target runs as part of the aggregate `docker` target, which builds every image in the project.
|
|
133
133
|
|
|
134
134
|
<NxCommands commands={['run your-project:container-docker']} />
|
|
135
135
|
|
|
@@ -362,6 +362,31 @@ secrets = { API_KEY = aws_secretsmanager_secret.api_key.arn }
|
|
|
362
362
|
</Fragment>
|
|
363
363
|
</Infrastructure>
|
|
364
364
|
|
|
365
|
+
#### CPU Architecture
|
|
366
|
+
|
|
367
|
+
The `architecture` option sets the CPU the tasks run on and the platform the image is built for: `ARM64` or `X86_64`. ARM64 runs on [AWS Graviton](https://aws.amazon.com/ec2/graviton/) processors, which AWS Fargate bills at a lower rate per vCPU and per GB of memory than X86_64. See [AWS Fargate pricing](https://aws.amazon.com/fargate/pricing/) for the rates in your Region.
|
|
368
|
+
|
|
369
|
+
Leave the option out and the generator uses the architecture of the machine you run it on, so `nx run your-project:container-docker` builds natively and needs no emulator. Re-running the generator keeps the architecture it generated the first time, whatever machine you re-run it on, because that architecture is already in your deployed task definition.
|
|
370
|
+
|
|
371
|
+
The architecture is fixed when the service is first generated. The generator never rewrites the infrastructure it vended, so moving an existing service to the other architecture takes two steps:
|
|
372
|
+
|
|
373
|
+
1. Change the architecture in the vended code. In CDK, the `architecture:` line in `packages/common/constructs/src/app/services/<name>.ts`. In Terraform, `cpu_architecture` in the `module "ecs_service"` block of `packages/common/terraform/src/app/services/<name>/<name>.tf`.
|
|
374
|
+
2. Re-run the generator with `--architecture` set to the same value, so the `<name>-docker` target builds for it.
|
|
375
|
+
|
|
376
|
+
Then redeploy. If you pass an architecture that differs from the one the generator recorded, it warns and names the file you have to change.
|
|
377
|
+
|
|
378
|
+
Doing step 2 and forgetting step 1 fails differently per provider, and neither failure is loud. In Terraform, the task definition keeps the old architecture while the image Terraform pushes has the new one, so the task does not start. In CDK, the deployed image is built from the vended construct, so the service keeps running on the old architecture and the image you built and scanned locally is the other one, which is never deployed.
|
|
379
|
+
|
|
380
|
+
`architecture` is also a prop of the vended service construct, so a stack can pass a different one for a single instantiation. That changes what deploys but not what the `<name>-docker` and `<name>-trivy` targets build, so keep the two in step yourself.
|
|
381
|
+
|
|
382
|
+
Building an ARM64 image on an x86_64 machine, or an X86_64 image on an arm64 machine, fails with `exec format error` unless you install an emulator. The generator warns you when the architecture it is about to generate is not the one your machine runs. See <Link path="/troubleshooting/docker">Troubleshooting Docker</Link>.
|
|
383
|
+
|
|
384
|
+
| Setting | CDK prop | Terraform variable | Default |
|
|
385
|
+
| --- | --- | --- | --- |
|
|
386
|
+
| CPU architecture | `architecture` | `cpu_architecture` | `'ARM64'` |
|
|
387
|
+
|
|
388
|
+
The generator writes the architecture it chose into your service's construct and module, so that default applies only when you use the generic `EcsService` construct or the `ecs-service` module yourself.
|
|
389
|
+
|
|
365
390
|
#### Sizing and Scaling
|
|
366
391
|
|
|
367
392
|
Each task gets 256 CPU units (a quarter of a vCPU) and 512 MiB of memory by default. The service starts one task, and autoscaling keeps between one and two tasks running, adding tasks when average CPU use goes above 70%.
|
package/package.json
CHANGED
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"default": "inherit",
|
|
38
38
|
"x-prompt": "Which provider would you like to manage your infrastructure? (default: inherit)"
|
|
39
39
|
},
|
|
40
|
+
"architecture": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "The CPU architecture your container image is built for and its ECS task runs on. ARM64 runs on AWS Graviton, which costs less per task on AWS Fargate. By default this is the architecture of the machine you run the generator on, and re-running keeps the architecture already generated.",
|
|
43
|
+
"enum": ["ARM64", "X86_64"]
|
|
44
|
+
},
|
|
40
45
|
"preferInstallDependencies": {
|
|
41
46
|
"type": "boolean",
|
|
42
47
|
"description": "Whether to prefer installing dependencies after the generator runs. Set to false to defer installing when batching multiple generators (an install still runs if needed so subsequent generators can compute the Nx project graph); install once at the end.",
|
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"default": "inherit",
|
|
38
38
|
"x-prompt": "Which provider would you like to manage your infrastructure? (default: inherit)"
|
|
39
39
|
},
|
|
40
|
+
"architecture": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "The CPU architecture your container image is built for and its ECS task runs on. ARM64 runs on AWS Graviton, which costs less per task on AWS Fargate. By default this is the architecture of the machine you run the generator on, and re-running keeps the architecture already generated.",
|
|
43
|
+
"enum": ["ARM64", "X86_64"]
|
|
44
|
+
},
|
|
40
45
|
"preferInstallDependencies": {
|
|
41
46
|
"type": "boolean",
|
|
42
47
|
"description": "Whether to prefer installing dependencies after the generator runs. Set to false to defer installing when batching multiple generators (an install still runs if needed so subsequent generators can compute the Nx project graph); install once at the end.",
|