@aws/nx-plugin-mcp 1.0.0-rc.9 → 1.0.0-rc.91
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 +13439 -11631
- package/docs/get_started/building-with-ai.mdx +116 -0
- package/docs/get_started/concepts.mdx +67 -0
- package/docs/get_started/existing-project.mdx +180 -0
- package/docs/get_started/graph-builder.mdx +39 -0
- package/docs/get_started/quick-start.mdx +277 -0
- package/docs/get_started/tutorials/contribute-generator.mdx +408 -0
- package/docs/get_started/tutorials/dungeon-game/1.mdx +1578 -0
- package/docs/get_started/tutorials/dungeon-game/2.mdx +245 -0
- package/docs/get_started/tutorials/dungeon-game/3.mdx +66 -0
- package/docs/get_started/tutorials/dungeon-game/4.mdx +164 -0
- package/docs/get_started/tutorials/dungeon-game/overview.mdx +145 -0
- package/docs/get_started/tutorials/dungeon-game/wrap-up.mdx +41 -0
- package/docs/get_started/upgrading.mdx +157 -0
- package/docs/guides/agentcore-gateway.mdx +490 -0
- package/docs/guides/agentcore-harness.mdx +312 -0
- package/docs/guides/astro-docs.mdx +8 -0
- package/docs/guides/connection/agentcore-gateway-agent.mdx +222 -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 +48 -16
- package/docs/guides/connection/py-agent-dynamodb.mdx +115 -0
- package/docs/guides/connection/py-agent-gateway.mdx +182 -0
- package/docs/guides/connection/py-agent-mcp.mdx +43 -14
- package/docs/guides/connection/py-agent-rdb.mdx +169 -0
- package/docs/guides/connection/py-fast-api-dynamodb.mdx +56 -0
- package/docs/guides/connection/py-fast-api-rdb.mdx +175 -0
- package/docs/guides/connection/py-mcp-server-dynamodb.mdx +115 -0
- package/docs/guides/connection/py-mcp-server-rdb.mdx +178 -0
- package/docs/guides/connection/react-agentcore-gateway.mdx +112 -0
- package/docs/guides/connection/react-agui.mdx +33 -14
- package/docs/guides/connection/react-fastapi.mdx +39 -3
- package/docs/guides/connection/react-py-agent.mdx +10 -16
- package/docs/guides/connection/react-smithy.mdx +4 -4
- package/docs/guides/connection/react-trpc.mdx +1 -1
- package/docs/guides/connection/react-ts-agent.mdx +9 -9
- package/docs/guides/connection/smithy-dynamodb.mdx +5 -5
- package/docs/guides/connection/smithy-rdb.mdx +9 -9
- package/docs/guides/connection/trpc-dynamodb.mdx +4 -4
- package/docs/guides/connection/trpc-rdb.mdx +5 -5
- package/docs/guides/connection/ts-agent-a2a.mdx +14 -11
- package/docs/guides/connection/ts-agent-dynamodb.mdx +35 -36
- package/docs/guides/connection/ts-agent-gateway.mdx +147 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +12 -9
- package/docs/guides/connection/ts-agent-rdb.mdx +61 -25
- package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +35 -36
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +59 -18
- package/docs/guides/connection.mdx +122 -5
- package/docs/guides/docker-bundling.mdx +82 -14
- package/docs/guides/fastapi.mdx +253 -12
- package/docs/guides/local-development.mdx +87 -0
- package/docs/guides/nx-generator.mdx +4 -3
- package/docs/guides/nx-migration.mdx +165 -0
- package/docs/guides/py-agent.mdx +332 -55
- package/docs/guides/py-dynamodb.mdx +476 -0
- package/docs/guides/py-mcp-server.mdx +57 -2
- package/docs/guides/py-rdb.mdx +269 -0
- package/docs/guides/python-lambda-function.mdx +1 -1
- package/docs/guides/python-project.mdx +31 -0
- package/docs/guides/react-website-auth.mdx +104 -5
- package/docs/guides/react-website.mdx +409 -95
- package/docs/guides/runtime-config.mdx +17 -4
- package/docs/guides/security.mdx +75 -0
- package/docs/guides/smithy-project.mdx +167 -0
- package/docs/guides/terraform-project.mdx +119 -8
- package/docs/guides/trpc.mdx +55 -14
- package/docs/guides/ts-agent.mdx +207 -23
- package/docs/guides/ts-dcr-proxy.mdx +569 -0
- package/docs/guides/ts-dynamodb.mdx +66 -242
- package/docs/guides/ts-lambda-function.mdx +1 -1
- package/docs/guides/ts-mcp-server.mdx +111 -29
- package/docs/guides/ts-nx-plugin.mdx +4 -4
- package/docs/guides/ts-rdb.mdx +116 -466
- package/docs/guides/ts-smithy-api.mdx +260 -16
- package/docs/guides/typescript-infrastructure.mdx +79 -25
- package/docs/guides/typescript-project.mdx +157 -24
- package/docs/guides/workspace.mdx +31 -2
- package/docs/snippets/agent/architecture.mdx +1 -1
- package/docs/snippets/agent/bedrock-deployment.mdx +9 -5
- package/docs/snippets/agent/runtime-arn.mdx +23 -2
- package/docs/snippets/agent/securing-your-agent.mdx +39 -0
- package/docs/snippets/api/access-logging.mdx +38 -0
- package/docs/snippets/api/cors-configuration-cdk-note.mdx +1 -1
- package/docs/snippets/api/cors-configuration-terraform-note.mdx +1 -1
- package/docs/snippets/api/type-safe-api-integrations.mdx +218 -373
- package/docs/snippets/api/waf-configuration.mdx +3 -3
- package/docs/snippets/connection/a2a-infrastructure.mdx +1 -1
- package/docs/snippets/connection/dynamodb-local-development.mdx +2 -2
- package/docs/snippets/connection/lambda-dynamodb-access.mdx +2 -2
- package/docs/snippets/connection/py-dynamodb-local-development.mdx +7 -0
- package/docs/snippets/connection/py-lambda-rdb-ssl-requirements.mdx +7 -0
- package/docs/snippets/connection/rdb-api-infrastructure.mdx +42 -19
- package/docs/snippets/dynamodb/deploying-table.mdx +176 -0
- package/docs/snippets/dynamodb/encryption-options.mdx +168 -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/experimental-generator.mdx +8 -0
- package/docs/snippets/lambda-function/deploying-your-function.mdx +3 -3
- package/docs/snippets/mcp/architecture.mdx +1 -1
- package/docs/snippets/mcp/bedrock-deployment.mdx +9 -5
- package/docs/snippets/mcp/config.mdx +3 -2
- package/docs/snippets/mcp/shared-constructs.mdx +4 -5
- package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +7 -5
- package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +29 -10
- package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +4 -4
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +5 -111
- package/docs/snippets/prerequisites.mdx +1 -4
- package/docs/snippets/rdb/admin-credentials.mdx +42 -0
- package/docs/snippets/rdb/architecture.mdx +39 -0
- package/docs/snippets/rdb/cluster-instances.mdx +31 -0
- package/docs/snippets/rdb/deletion-protection.mdx +64 -0
- package/docs/snippets/rdb/deploying.mdx +178 -0
- package/docs/snippets/rdb/encryption-key-rotation.mdx +30 -0
- package/docs/snippets/rdb/engine-version.mdx +63 -0
- package/docs/snippets/rdb/infrastructure.mdx +35 -0
- package/docs/snippets/rdb/logging-mysql.mdx +5 -0
- package/docs/snippets/rdb/logging-postgres.mdx +5 -0
- package/docs/snippets/rdb/performance-insights.mdx +36 -0
- package/docs/snippets/rdb/rds-proxy.mdx +50 -0
- package/docs/snippets/rdb/removal-policy.mdx +57 -0
- package/docs/snippets/rdb/serverless-capacity.mdx +32 -0
- package/docs/snippets/recommended-prerequisites.mdx +10 -0
- package/docs/snippets/required-prerequisites.mdx +1 -4
- package/docs/snippets/runtime-config-app-id-note.mdx +8 -0
- package/docs/snippets/shared-constructs.mdx +1 -1
- package/docs/snippets/trivy-image-scan.mdx +37 -0
- package/generators.json +170 -10
- package/package.json +1 -1
- package/src/agentcore-gateway/agent-connection/schema.json +31 -0
- package/src/agentcore-gateway/gateway-connection/schema.json +31 -0
- package/src/agentcore-gateway/mcp-connection/schema.json +31 -0
- package/src/agentcore-gateway/react-connection/schema.json +31 -0
- package/src/agentcore-gateway/schema.json +72 -0
- package/src/agentcore-harness/schema.json +53 -0
- package/src/connection/schema.json +5 -0
- package/src/infra/app/schema.json +5 -0
- package/src/init/schema.json +35 -0
- package/src/internal/test-matrix/schema.json +21 -0
- package/src/license/schema.json +5 -0
- package/src/open-api/json-metadata/schema.json +20 -0
- package/src/preset/schema.json +16 -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 +15 -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 +76 -0
- package/src/py/fast-api/react/schema.json +5 -0
- package/src/py/fast-api/schema.json +6 -0
- package/src/py/lambda-function/schema.json +6 -1
- package/src/py/mcp-server/schema.json +6 -0
- package/src/py/project/schema.json +6 -0
- package/src/py/rdb/agent-connection/schema.json +27 -0
- package/src/py/rdb/fast-api-connection/schema.json +23 -0
- package/src/py/rdb/mcp-server-connection/schema.json +27 -0
- package/src/py/rdb/schema.json +78 -0
- package/src/smithy/project/schema.json +28 -1
- package/src/smithy/react-connection/schema.json +5 -0
- package/src/smithy/ts/api/schema.json +6 -0
- package/src/terraform/project/schema.json +5 -0
- package/src/trpc/backend/schema.json +6 -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 +14 -0
- package/src/ts/api/schema.json +5 -0
- package/src/ts/astro-docs/schema.json +3 -3
- package/src/ts/dcr-proxy/schema.json +44 -0
- package/src/ts/docs/schema.json +3 -3
- package/src/ts/dynamodb/agent-connection/schema.json +5 -0
- package/src/ts/dynamodb/mcp-server-connection/schema.json +5 -0
- package/src/ts/dynamodb/schema.json +26 -2
- package/src/ts/dynamodb/smithy-connection/schema.json +5 -0
- package/src/ts/dynamodb/trpc-connection/schema.json +5 -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 +6 -0
- package/src/ts/nx-generator/schema.json +5 -0
- package/src/ts/nx-migration/schema.json +63 -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 +7 -1
- 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 +12 -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
- /package/docs/snippets/connection/{lambda-rdb-ssl-requirements.mdx → ts-lambda-rdb-ssl-requirements.mdx} +0 -0
- /package/docs/snippets/connection/{mcp-server-rdb-ssl-requirements.mdx → ts-mcp-server-rdb-ssl-requirements.mdx} +0 -0
|
@@ -12,17 +12,19 @@ Runtime configuration is the mechanism used by Nx Plugin for AWS to pass deploy-
|
|
|
12
12
|
|
|
13
13
|
Runtime configuration is organised into **namespaces**. Each namespace is a logical grouping of related configuration values. At deploy time, all namespaces are stored in **AWS AppConfig** as Configuration Profiles.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Four built-in namespaces are used by generated constructs:
|
|
16
16
|
|
|
17
17
|
- **`connection`** — configuration that enables generated projects to connect to each other:
|
|
18
18
|
- **API URLs** — registered automatically by API constructs
|
|
19
19
|
- **Cognito settings** — registered automatically by the UserIdentity construct
|
|
20
20
|
- **Agent runtime ARNs** — added by the connection generator when you connect a React website to an Agent
|
|
21
21
|
- **`agentcore`** — AgentCore runtime ARNs for agents and MCP servers. Registered automatically by the agent/MCP constructs and used for server-side discovery (agent → agent via A2A, agent → MCP server).
|
|
22
|
+
- **`dynamodb`** — table names, registered automatically by DynamoDB table constructs and read by the generated table client.
|
|
23
|
+
- **`database`** — Aurora connection details, registered automatically by relational database constructs and read by the generated database client.
|
|
22
24
|
|
|
23
|
-
The `connection` namespace is also deployed as a `runtime-config.json` file to your website's S3 bucket, enabling client-side discovery of backend resources. The
|
|
25
|
+
The `connection` namespace is also deployed as a `runtime-config.json` file to your website's S3 bucket, enabling client-side discovery of backend resources. The other namespaces are server-side only (via AppConfig), so values such as agent runtime ARNs and table names are not exposed to the frontend unless you explicitly connect a website to them.
|
|
24
26
|
|
|
25
|
-
You can define as many additional namespaces as you like, providing a convenient alternative to environment variables for passing deploy-time values
|
|
27
|
+
You can define as many additional namespaces as you like, providing a convenient alternative to environment variables for passing deploy-time values to your Lambda functions or other compute resources.
|
|
26
28
|
|
|
27
29
|
```d2
|
|
28
30
|
direction: down
|
|
@@ -70,7 +72,7 @@ Generated constructs automatically write relevant configuration to the `connecti
|
|
|
70
72
|
The `RuntimeConfig` CDK construct is a stage-scoped singleton. Use `set()` to write a key into a namespace:
|
|
71
73
|
|
|
72
74
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
73
|
-
import { RuntimeConfig } from '
|
|
75
|
+
import { RuntimeConfig } from '@my-scope/common-constructs';
|
|
74
76
|
|
|
75
77
|
const rc = RuntimeConfig.ensure(this);
|
|
76
78
|
|
|
@@ -107,6 +109,17 @@ Terraform wires runtime configuration across three `core/runtime-config/*` modul
|
|
|
107
109
|
}
|
|
108
110
|
```
|
|
109
111
|
|
|
112
|
+
The `namespaces` variable defaults to every built-in namespace, so generated modules work without configuring it. To add namespaces of your own, list them alongside the built-in ones:
|
|
113
|
+
|
|
114
|
+
```hcl title="packages/infra/src/main.tf"
|
|
115
|
+
module "runtime_config_appconfig" {
|
|
116
|
+
source = "../../common/terraform/src/core/runtime-config/appconfig"
|
|
117
|
+
|
|
118
|
+
application_name = "my-app-runtime-config"
|
|
119
|
+
namespaces = ["connection", "agentcore", "database", "dynamodb", "tables"]
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
110
123
|
2. **`core/runtime-config/entry`** — one invocation per contribution. Generated API, agent and MCP modules call this internally to publish their URLs and ARNs. Call it directly to publish custom configuration.
|
|
111
124
|
|
|
112
125
|
```hcl title="packages/infra/src/main.tf"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Security
|
|
3
|
+
description: Security features included in projects generated by the Nx Plugin for AWS
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import Link from '@components/link.astro';
|
|
7
|
+
|
|
8
|
+
:::caution[Reporting Security Issues]
|
|
9
|
+
To report a potential security issue in the Nx Plugin for AWS itself, please refer to [SECURITY.md](https://github.com/awslabs/nx-plugin-for-aws/blob/main/SECURITY.md) — do not create a public GitHub issue.
|
|
10
|
+
:::
|
|
11
|
+
|
|
12
|
+
## Security Controls
|
|
13
|
+
|
|
14
|
+
Projects scaffolded by the Nx Plugin for AWS include a number of security controls out of the box. This page provides an overview of those controls and links to the relevant guides for more detail.
|
|
15
|
+
|
|
16
|
+
### Infrastructure Scanning
|
|
17
|
+
|
|
18
|
+
Infrastructure projects are configured with [Checkov](https://www.checkov.io/) as part of the `build` target, so insecure infrastructure configuration fails the build:
|
|
19
|
+
|
|
20
|
+
- CDK projects synthesize CloudFormation templates which are scanned by Checkov. See <Link path="/guides/typescript-infrastructure#security-testing">Security Testing</Link> for details.
|
|
21
|
+
- Terraform projects run Checkov directly against your Terraform code. See <Link path="/guides/terraform-project">Terraform Projects</Link>.
|
|
22
|
+
|
|
23
|
+
Where vended infrastructure suppresses a Checkov rule, the suppression is scoped to the specific resource and annotated with a justification. The shared `suppressRules` helper requires a reason for every suppression, and we recommend following the same practice in your own code. See <Link path="/guides/typescript-infrastructure#suppressing-checkov-checks">Suppressing Checkov Checks</Link>.
|
|
24
|
+
|
|
25
|
+
### Container Image Scanning
|
|
26
|
+
|
|
27
|
+
Projects which build container images (for example agents, MCP servers, and database migration images) include a `trivy` target which scans images for HIGH and CRITICAL vulnerabilities, exiting non-zero on findings. See <Link path="/guides/docker-bundling">Docker Bundling</Link> for details, including how to suppress findings with a `.trivyignore` file.
|
|
28
|
+
|
|
29
|
+
### Credential Scanning
|
|
30
|
+
|
|
31
|
+
Workspaces include [git-secrets](https://github.com/awslabs/git-secrets) pre-commit hooks which scan staged files for AWS credential patterns, preventing accidental commits of access keys and other sensitive values. See the <Link path="/guides/workspace#git-secrets">Git Secrets</Link> section of the workspace guide.
|
|
32
|
+
|
|
33
|
+
### Authentication
|
|
34
|
+
|
|
35
|
+
APIs, agents, and MCP servers use AWS IAM (SigV4) authentication by default:
|
|
36
|
+
|
|
37
|
+
- <Link path="/guides/trpc">tRPC</Link>, <Link path="/guides/fastapi">FastAPI</Link>, and <Link path="/guides/ts-smithy-api">Smithy</Link> APIs default to IAM authentication, with Cognito and custom authorizers available as options. The vended custom authorizer stub denies requests by default.
|
|
38
|
+
- <Link path="/guides/ts-agent">Agents</Link> and <Link path="/guides/ts-mcp-server">MCP servers</Link> deployed to Amazon Bedrock AgentCore Runtime use IAM (SigV4) authentication by default, with JWT-based Cognito authentication as an option.
|
|
39
|
+
- The <Link path="/guides/react-website-auth">website auth generator</Link> vends an Amazon Cognito user pool with multi-factor authentication (MFA) required, a strong password policy, and deletion protection enabled.
|
|
40
|
+
|
|
41
|
+
### Encryption
|
|
42
|
+
|
|
43
|
+
Vended infrastructure encrypts data in transit and at rest:
|
|
44
|
+
|
|
45
|
+
- Websites are served via CloudFront with HTTP redirected to HTTPS, and a response headers policy including HTTP Strict Transport Security (HSTS), a Content Security Policy, and other <Link path="/guides/react-website#security-headers">security headers</Link>. A WAF with AWS managed rules is associated with the distribution.
|
|
46
|
+
- S3 buckets block all public access, enforce SSL-only access via bucket policies, are encrypted (KMS with key rotation for website content), and deliver server access logs to CloudWatch log groups encrypted with customer-managed KMS keys, where they can be queried with Logs Insights and alarmed on.
|
|
47
|
+
- API access logs are written to CloudWatch log groups encrypted with customer-managed KMS keys with rotation enabled.
|
|
48
|
+
- <Link path="/guides/ts-rdb">Aurora databases</Link> enable storage encryption with a customer-managed KMS key, generate credentials in AWS Secrets Manager (never hardcoded), and support automatic credential rotation.
|
|
49
|
+
|
|
50
|
+
### Least Privilege
|
|
51
|
+
|
|
52
|
+
Vended CDK constructs and Terraform modules follow least privilege:
|
|
53
|
+
|
|
54
|
+
- Constructs expose `grant*` methods (for example `grantInvokeAccess` on APIs and agents, `grantConnect` on databases) so consumers grant only the access they need.
|
|
55
|
+
- IAM policies in vended infrastructure are scoped to specific resources and actions. Where a wildcard resource is required by the AWS service (for example `ecr:GetAuthorizationToken`), it is limited to those actions and scoped with conditions where supported.
|
|
56
|
+
|
|
57
|
+
### Dependency Licensing
|
|
58
|
+
|
|
59
|
+
The <Link path="/guides/license">license generator</Link> configures automated license header management and dependency license checking against an allowlist of approved licenses, helping you catch problematic transitive dependencies before they ship.
|
|
60
|
+
|
|
61
|
+
## Responsibility
|
|
62
|
+
|
|
63
|
+
Security and compliance is a shared responsibility. AWS describes this through the [Shared Responsibility Model](https://aws.amazon.com/compliance/shared-responsibility-model/), which distinguishes between security *of* the cloud (the responsibility of AWS) and security *in* the cloud (your responsibility as the customer).
|
|
64
|
+
|
|
65
|
+
The Nx Plugin for AWS helps you address parts of your side of that model. Its generators vend secure foundations and encode AWS best practices within the scope of the code they produce — the controls described above. This reduces the effort required to build securely, but it does not transfer ownership of security to the plugin.
|
|
66
|
+
|
|
67
|
+
**You own the code that is generated into your workspace and remain responsible for its security.** Once vended, generated code is yours to modify, extend, and operate, and it must be treated the same as any other code you author.
|
|
68
|
+
|
|
69
|
+
In particular:
|
|
70
|
+
|
|
71
|
+
- **The scope of the plugin is limited to its generators.** The plugin has no knowledge of your application's business logic, data classification, threat model, or regulatory obligations, and cannot make decisions that depend on them.
|
|
72
|
+
- **Authentication is configured, but authorization is not.** APIs are protected with authentication by default (for example IAM/SigV4), but the plugin cannot determine *which* authenticated principals should be permitted to perform *which* operations on *which* resources. Fine-grained authorization depends on your business logic and must be designed, implemented, and tested by you.
|
|
73
|
+
- **Generated code is a starting point, not a finished product.** As you add functionality, you introduce security considerations the plugin cannot anticipate — input validation, data handling, secrets management, dependency choices, and integrations with other systems.
|
|
74
|
+
|
|
75
|
+
Accordingly, you should review generated code and the applications you build on top of it in line with your own organisation's security policies, standards, and review processes, and subject them to the same threat modelling, security testing, and approval gates you apply to any production workload. The controls vended by the plugin are intended to complement those processes, not to replace them.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Smithy Projects
|
|
3
|
+
description: Reference documentation for the Smithy project generator
|
|
4
|
+
generator: smithy#project
|
|
5
|
+
---
|
|
6
|
+
import { FileTree, Steps } from '@astrojs/starlight/components';
|
|
7
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
8
|
+
import Link from '@components/link.astro';
|
|
9
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
10
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
11
|
+
import OptionFilter from '@components/option-filter.astro';
|
|
12
|
+
|
|
13
|
+
[Smithy](https://smithy.io/) is an interface definition language for describing services and the data they exchange. The Smithy project generator creates a project containing a Smithy model.
|
|
14
|
+
|
|
15
|
+
There are two kinds of Smithy project:
|
|
16
|
+
|
|
17
|
+
- **Service** (`--type=service`) — a model which defines a service and its operations. This is what the <Link path="guides/ts-smithy-api">`ts#api --framework=smithy` generator</Link> creates for you alongside a TypeScript implementation.
|
|
18
|
+
- **Shape library** (`--type=shapes`) — a model which defines reusable shapes but no service. Connect a shape library to your Smithy projects to share shapes between them, rather than duplicating the definitions in each.
|
|
19
|
+
|
|
20
|
+
:::tip
|
|
21
|
+
If you want an API with an implementation, use the <Link path="guides/ts-smithy-api">`ts#api` generator</Link> instead. It creates a Smithy model project _and_ a TypeScript server which implements it.
|
|
22
|
+
:::
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Generate a Smithy Project
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="smithy#project" requiredParameters={{ name: 'my-shapes' }} />
|
|
29
|
+
|
|
30
|
+
### Options
|
|
31
|
+
|
|
32
|
+
<GeneratorParameters generator="smithy#project" />
|
|
33
|
+
|
|
34
|
+
## Generator Output
|
|
35
|
+
|
|
36
|
+
<OptionFilter when={{ type: 'shapes' }} description="Shape library: a model with no service">
|
|
37
|
+
|
|
38
|
+
### Shape Library
|
|
39
|
+
|
|
40
|
+
<FileTree>
|
|
41
|
+
|
|
42
|
+
- my-shapes
|
|
43
|
+
- src
|
|
44
|
+
- main.smithy Your shared shape definitions
|
|
45
|
+
- smithy-build.json Smithy build configuration
|
|
46
|
+
- project.json Project configuration and build targets
|
|
47
|
+
|
|
48
|
+
</FileTree>
|
|
49
|
+
|
|
50
|
+
A shape library defines shapes and nothing else:
|
|
51
|
+
|
|
52
|
+
```smithy
|
|
53
|
+
$version: "2.0"
|
|
54
|
+
|
|
55
|
+
namespace com.example
|
|
56
|
+
|
|
57
|
+
structure Customer {
|
|
58
|
+
@required
|
|
59
|
+
id: String
|
|
60
|
+
|
|
61
|
+
name: String
|
|
62
|
+
email: String
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Since a shape library has no service, its `smithy-build.json` configures no code generation — building it validates the model and assembles it into a single JSON model file at `dist/<my-shapes>/build/model.json`.
|
|
67
|
+
|
|
68
|
+
</OptionFilter>
|
|
69
|
+
|
|
70
|
+
<OptionFilter when={{ type: 'service' }} description="Service: a model which defines a service and its operations">
|
|
71
|
+
|
|
72
|
+
### Service
|
|
73
|
+
|
|
74
|
+
<FileTree>
|
|
75
|
+
|
|
76
|
+
- my-service
|
|
77
|
+
- src
|
|
78
|
+
- main.smithy Your service definition
|
|
79
|
+
- operations
|
|
80
|
+
- echo.smithy An example operation
|
|
81
|
+
- smithy-build.json Smithy build configuration, including code generation
|
|
82
|
+
- ssdk.rolldown.config.mjs Bundles the generated TypeScript Server SDK
|
|
83
|
+
- project.json Project configuration and build targets
|
|
84
|
+
|
|
85
|
+
</FileTree>
|
|
86
|
+
|
|
87
|
+
A service model defines a service shape and the operations it exposes:
|
|
88
|
+
|
|
89
|
+
```smithy
|
|
90
|
+
$version: "2.0"
|
|
91
|
+
|
|
92
|
+
namespace com.example
|
|
93
|
+
|
|
94
|
+
use aws.protocols#restJson1
|
|
95
|
+
|
|
96
|
+
@title("MyService")
|
|
97
|
+
@restJson1
|
|
98
|
+
service MyService {
|
|
99
|
+
version: "1.0.0"
|
|
100
|
+
operations: [
|
|
101
|
+
Echo
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Building a service project generates an OpenAPI specification and a TypeScript Server SDK into `dist/<my-service>/build/`.
|
|
107
|
+
|
|
108
|
+
</OptionFilter>
|
|
109
|
+
|
|
110
|
+
## Building
|
|
111
|
+
|
|
112
|
+
Smithy projects build with the [Smithy CLI](https://smithy.io/2.0/guides/smithy-cli/index.html), which validates your model:
|
|
113
|
+
|
|
114
|
+
<NxCommands commands={['build my-shapes']} />
|
|
115
|
+
|
|
116
|
+
On macOS and Linux the CLI is resolved by [mise](https://mise.jdx.dev/), which the build fetches on demand, so there is nothing to install — it downloads and caches the pinned version the first time you build. On Windows it is a prerequisite you install yourself — see <Link path="guides/ts-smithy-api#building-on-windows">Building on Windows</Link>.
|
|
117
|
+
|
|
118
|
+
## Depending on a Shape Library
|
|
119
|
+
|
|
120
|
+
Building a shape library writes an assembled model to `dist/<my-shapes>/build/model.json`. This single file contains every shape the library defines, along with any it depends on, so a consumer only ever declares the libraries it references directly.
|
|
121
|
+
|
|
122
|
+
To depend on a shape library from another Smithy project, make two changes to the consuming project:
|
|
123
|
+
|
|
124
|
+
<Steps>
|
|
125
|
+
|
|
126
|
+
1. Add the library's built model to `imports` in the consuming project's `smithy-build.json`. Paths are relative to that file, so the number of `../` segments matches how deeply the consuming project is nested — three for `packages/my-api/model` below:
|
|
127
|
+
|
|
128
|
+
```json ins={4}
|
|
129
|
+
{
|
|
130
|
+
"version": "1.0",
|
|
131
|
+
"sources": ["src/"],
|
|
132
|
+
"imports": ["../../../dist/packages/my-shapes/build/model.json"],
|
|
133
|
+
...
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
2. Add the library's `build` target as a dependency of the consuming project's `compile` target in its `project.json`, so the model exists before the consumer builds:
|
|
138
|
+
|
|
139
|
+
```json ins={4}
|
|
140
|
+
{
|
|
141
|
+
"targets": {
|
|
142
|
+
"compile": {
|
|
143
|
+
"dependsOn": ["@my-scope/my-shapes:build"],
|
|
144
|
+
...
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
</Steps>
|
|
151
|
+
|
|
152
|
+
Your model can now reference the library's shapes with `use`:
|
|
153
|
+
|
|
154
|
+
```smithy
|
|
155
|
+
$version: "2.0"
|
|
156
|
+
|
|
157
|
+
namespace com.example.api
|
|
158
|
+
|
|
159
|
+
use com.example.shared#Customer
|
|
160
|
+
|
|
161
|
+
structure GetCustomerOutput {
|
|
162
|
+
@required
|
|
163
|
+
customer: Customer
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Shape libraries can depend on other shape libraries the same way. Since each library's built model already contains its own dependencies, you only need to repeat these steps for the libraries you reference directly. A library reached by more than one path is resolved once — Smithy ignores duplicate but equivalent shape definitions.
|
|
@@ -9,6 +9,7 @@ import Link from '@components/link.astro';
|
|
|
9
9
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
10
10
|
import NxCommands from '@components/nx-commands.astro';
|
|
11
11
|
import OptionFilter from '@components/option-filter.astro';
|
|
12
|
+
import PackageManagerShortCommand from '@components/package-manager-short-command.astro';
|
|
12
13
|
|
|
13
14
|
[Terraform](https://www.terraform.io/) is an open-source infrastructure as code software tool that enables you to safely and predictably create, change, and improve infrastructure.
|
|
14
15
|
|
|
@@ -48,10 +49,13 @@ For application projects (`--type=application`), the generator creates a complet
|
|
|
48
49
|
- main.tf S3 bucket and policies for state storage
|
|
49
50
|
- providers.tf AWS provider configuration
|
|
50
51
|
- variables.tf Bootstrap variable definitions
|
|
51
|
-
- scripts Node helpers run by the nx `bootstrap` and `init` targets
|
|
52
|
+
- scripts Node helpers run by the nx `bootstrap`, `bootstrap-destroy` and `init` targets
|
|
52
53
|
- aws-config.ts Resolves account + region via the AWS SDK credential chain
|
|
53
54
|
- bootstrap.ts Pulls/pushes the bootstrap tfstate and runs `terraform apply`
|
|
55
|
+
- bootstrap-destroy.ts Empties the state bucket and runs `terraform destroy`
|
|
54
56
|
- init.ts Runs `terraform init` with the S3 backend config
|
|
57
|
+
- env.ts Points `terraform init` at the shared provider cache
|
|
58
|
+
- checkov.yml Checkov configuration, including the checks to skip
|
|
55
59
|
- project.json Project configuration and build targets
|
|
56
60
|
|
|
57
61
|
</FileTree>
|
|
@@ -71,6 +75,7 @@ For library projects (`--type=library`), the generator creates a simpler structu
|
|
|
71
75
|
|
|
72
76
|
- src
|
|
73
77
|
- main.tf Main Terraform module file
|
|
78
|
+
- checkov.yml Checkov configuration, including the checks to skip
|
|
74
79
|
- project.json Project configuration and build targets
|
|
75
80
|
|
|
76
81
|
</FileTree>
|
|
@@ -84,7 +89,7 @@ Application projects include full deployment capabilities with remote state mana
|
|
|
84
89
|
|
|
85
90
|
You can start writing your Terraform infrastructure inside `src/main.tf`, for example:
|
|
86
91
|
|
|
87
|
-
```diff title="src/main.tf" {
|
|
92
|
+
```diff title="src/main.tf" {16-19}
|
|
88
93
|
-locals {
|
|
89
94
|
- account_id = data.aws_caller_identity.current.account_id
|
|
90
95
|
- aws_region = data.aws_region.current.id
|
|
@@ -108,7 +113,7 @@ You can start writing your Terraform infrastructure inside `src/main.tf`, for ex
|
|
|
108
113
|
|
|
109
114
|
### Cross project dependencies
|
|
110
115
|
|
|
111
|
-
If you wanted to execute a module from a
|
|
116
|
+
If you wanted to execute a module from a separate project (lib), you could do so as follows:
|
|
112
117
|
|
|
113
118
|
```
|
|
114
119
|
module "lib_module" {
|
|
@@ -242,20 +247,114 @@ You can validate your Terraform configuration using the `validate` target:
|
|
|
242
247
|
|
|
243
248
|
<NxCommands commands={['validate tf-infra']} />
|
|
244
249
|
|
|
245
|
-
####
|
|
250
|
+
#### Linting
|
|
246
251
|
|
|
247
|
-
|
|
252
|
+
Terraform projects use [`terraform fmt`](https://developer.hashicorp.com/terraform/cli/commands/fmt) to check formatting.
|
|
248
253
|
|
|
249
|
-
|
|
254
|
+
##### Running the Linter
|
|
255
|
+
|
|
256
|
+
To invoke the linter to check your project, you can run the `lint` target.
|
|
257
|
+
|
|
258
|
+
<NxCommands commands={["lint tf-infra"]} />
|
|
259
|
+
|
|
260
|
+
##### Fixing Lint Issues
|
|
261
|
+
|
|
262
|
+
The majority of linting or formatting issues can be fixed automatically by running with the `--configuration=fix` argument.
|
|
263
|
+
|
|
264
|
+
<NxCommands commands={["lint tf-infra --configuration=fix"]} />
|
|
265
|
+
|
|
266
|
+
Similarly if you would like to fix all lint issues in all packages in your workspace, you can run:
|
|
267
|
+
|
|
268
|
+
<NxCommands commands={["run-many --target lint --all --configuration=fix"]} />
|
|
269
|
+
|
|
270
|
+
:::tip[Shorthand Command]
|
|
271
|
+
This has a shorthand command from the root of your workspace:
|
|
272
|
+
|
|
273
|
+
<PackageManagerShortCommand commands={["lint"]} />
|
|
274
|
+
:::
|
|
275
|
+
|
|
276
|
+
##### Skipping Lint Issues
|
|
277
|
+
|
|
278
|
+
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:
|
|
279
|
+
|
|
280
|
+
<NxCommands commands={["run-many --target build --configuration=skip-lint"]} />
|
|
281
|
+
|
|
282
|
+
This skips the format check entirely during build.
|
|
283
|
+
|
|
284
|
+
:::tip[Shorthand Command]
|
|
285
|
+
This has a shorthand command from the root of your workspace:
|
|
286
|
+
|
|
287
|
+
<PackageManagerShortCommand commands={["build:skip-lint"]} />
|
|
288
|
+
:::
|
|
250
289
|
|
|
251
290
|
#### Security Testing
|
|
252
291
|
|
|
253
|
-
Run security checks on your infrastructure using Checkov with the `
|
|
292
|
+
Run security checks on your infrastructure using Checkov with the `checkov` target:
|
|
254
293
|
|
|
255
|
-
<NxCommands commands={['
|
|
294
|
+
<NxCommands commands={['checkov tf-infra']} />
|
|
256
295
|
|
|
257
296
|
You will find your security test results in the root `dist` folder, under `dist/packages/<my-terraform-project>/checkov`.
|
|
258
297
|
|
|
298
|
+
Checkov runs as part of `build`.
|
|
299
|
+
|
|
300
|
+
Checks are configured in the project's `checkov.yml`. Add a check id to `skip-check` to suppress it across the whole project:
|
|
301
|
+
|
|
302
|
+
```yaml title="checkov.yml"
|
|
303
|
+
skip-check:
|
|
304
|
+
- CKV_AWS_115 # Concurrent execution limit
|
|
305
|
+
- CKV_AWS_116 # Dead Letter Queue
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
To suppress a check for a single resource instead, add a `#checkov:skip=<id>:<reason>` comment inside the resource block:
|
|
309
|
+
|
|
310
|
+
```hcl
|
|
311
|
+
resource "aws_s3_bucket" "example" {
|
|
312
|
+
#checkov:skip=CKV_AWS_18:Access logging not required for this bucket
|
|
313
|
+
bucket = "example"
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### Running Terraform Tests
|
|
318
|
+
|
|
319
|
+
The `test` target runs [Terraform's native test framework](https://developer.hashicorp.com/terraform/language/tests) over any `.tftest.hcl` files in your project:
|
|
320
|
+
|
|
321
|
+
<NxCommands commands={['test tf-infra']} />
|
|
322
|
+
|
|
323
|
+
A project with no test files is a no-op success, so you can add tests when you need them. `build` runs this target, so your tests run as part of a normal build.
|
|
324
|
+
|
|
325
|
+
Each `run` block evaluates your configuration. Use `command = plan` to check what Terraform _would_ do (this expands the whole module graph, so it catches plan-time errors that `validate` cannot), or `command = apply` to create real resources and assert on their outputs. Declaring `mock_provider` means no API calls are made and no AWS credentials are needed, which keeps `plan` tests fast and safe to run in CI:
|
|
326
|
+
|
|
327
|
+
```hcl title="src/main.tftest.hcl"
|
|
328
|
+
mock_provider "aws" {
|
|
329
|
+
mock_data "aws_caller_identity" {
|
|
330
|
+
defaults = { account_id = "123456789012" }
|
|
331
|
+
}
|
|
332
|
+
mock_data "aws_region" {
|
|
333
|
+
defaults = { region = "us-east-1" }
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
variables {
|
|
338
|
+
aws_region = "us-east-1"
|
|
339
|
+
environment = "dev"
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
run "plan_is_valid" {
|
|
343
|
+
command = plan
|
|
344
|
+
|
|
345
|
+
assert {
|
|
346
|
+
condition = data.aws_caller_identity.current.account_id == "123456789012"
|
|
347
|
+
error_message = "Unexpected account id"
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Set every variable your configuration requires in the `variables` block, otherwise the run fails with "has a required variable ... with no set value".
|
|
353
|
+
|
|
354
|
+
Every target that runs `terraform init` reuses a provider cache under `.terraform/plugin-cache` in your workspace root, so providers are downloaded once rather than on every run. Each project gets its own directory there: two `terraform init` runs filling one cache at the same time can each compute a different hash for the same provider, which terraform then rejects against your `.terraform.lock.hcl`. See the [Terraform documentation](https://developer.hashicorp.com/terraform/cli/config/config-file#provider-plugin-cache) for more information.
|
|
355
|
+
|
|
356
|
+
Set `TF_PLUGIN_CACHE_DIR` in your environment to point the vended `init` script at a cache you manage yourself — a volume shared between workspaces, say. Note that the `test` target reads its path from `project.json`, so change it there too.
|
|
357
|
+
|
|
259
358
|
<OptionFilter when={{ type: 'application' }} description="Application-only targets: plan / apply / destroy / etc.">
|
|
260
359
|
### Application-Only Targets
|
|
261
360
|
|
|
@@ -269,6 +368,12 @@ Before applying changes, you can see what Terraform will do by running the `plan
|
|
|
269
368
|
|
|
270
369
|
This will create a plan file in `dist/packages/<my-terraform-project>/terraform/dev.tfplan`.
|
|
271
370
|
|
|
371
|
+
`plan` depends on `assemble`, so it produces the artifacts your modules reference, such as the Lambda bundles and generated operations metadata, without running the lint, test and type-check gates.
|
|
372
|
+
|
|
373
|
+
:::caution[Use `build` in your pipeline]
|
|
374
|
+
`assemble` is used for faster iteration during development. Run `build` in your CI pipeline to ensure your project passes quality gates prior to a production deployment.
|
|
375
|
+
:::
|
|
376
|
+
|
|
272
377
|
#### Initializing Terraform
|
|
273
378
|
|
|
274
379
|
Initialize your Terraform working directory with the `init` target:
|
|
@@ -310,6 +415,12 @@ This will permanently delete all resources managed by this Terraform configurati
|
|
|
310
415
|
To clean up the bootstrap resources (S3 bucket for state storage):
|
|
311
416
|
|
|
312
417
|
<NxCommands commands={['bootstrap-destroy tf-infra']} />
|
|
418
|
+
|
|
419
|
+
This empties the state bucket before destroying it, and resolves the region from the AWS SDK credential chain, so it runs unattended in CI.
|
|
420
|
+
|
|
421
|
+
:::caution[Destroy your infrastructure first]
|
|
422
|
+
The state bucket holds the state for every environment, so run `destroy` for each environment before this. Once the bucket is gone, Terraform no longer knows about the resources it created.
|
|
423
|
+
:::
|
|
313
424
|
</OptionFilter>
|
|
314
425
|
|
|
315
426
|
## More Information
|
package/docs/guides/trpc.mdx
CHANGED
|
@@ -6,7 +6,9 @@ when:
|
|
|
6
6
|
framework: [trpc]
|
|
7
7
|
infra: [rest-lambda, http-lambda]
|
|
8
8
|
---
|
|
9
|
-
import { FileTree, Tabs, TabItem } from '@astrojs/starlight/components';
|
|
9
|
+
import { FileTree, Tabs, TabItem, CardGrid } from '@astrojs/starlight/components';
|
|
10
|
+
import Astro from '@astrojs/react';
|
|
11
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
10
12
|
import Link from '@components/link.astro';
|
|
11
13
|
import RunGenerator from '@components/run-generator.astro';
|
|
12
14
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
@@ -64,6 +66,7 @@ The generator will create the following project structure in the `<directory>/<a
|
|
|
64
66
|
- client
|
|
65
67
|
- index.ts Type-safe client for machine-to-machine API calls
|
|
66
68
|
- tsconfig.json TypeScript configuration
|
|
69
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
67
70
|
- project.json Project configuration and build targets
|
|
68
71
|
|
|
69
72
|
</FileTree>
|
|
@@ -138,7 +141,7 @@ The example `echo` procedure is generated for you in `src/procedures/echo.ts`:
|
|
|
138
141
|
export const echo = publicProcedure
|
|
139
142
|
.input(EchoInputSchema)
|
|
140
143
|
.output(EchoOutputSchema)
|
|
141
|
-
.query((opts) => ({
|
|
144
|
+
.query((opts) => ({ message: opts.input.message }));
|
|
142
145
|
```
|
|
143
146
|
|
|
144
147
|
To break down the above:
|
|
@@ -463,7 +466,7 @@ export const createIdentityPlugin = () => {
|
|
|
463
466
|
</OptionFilter>
|
|
464
467
|
|
|
465
468
|
<OptionFilter when={{ auth: 'cognito' }} description="Identity middleware example for Cognito-authenticated APIs">
|
|
466
|
-
When you deploy with `auth: 'cognito'`, the API Gateway Cognito
|
|
469
|
+
When you deploy with `auth: 'cognito'`, the API Gateway Cognito authorizer verifies the JWT that the caller supplies in the `Authorization` header and places the verified claims on the Lambda event. Our middleware just reads those claims — no extra AWS SDK calls, no manual JWT verification.
|
|
467
470
|
|
|
468
471
|
First, we define what we'll add to the context:
|
|
469
472
|
|
|
@@ -478,7 +481,7 @@ export interface IIdentityContext {
|
|
|
478
481
|
|
|
479
482
|
Note that we define an additional _optional_ property on the context. tRPC manages ensuring that this is defined in procedures which have correctly configured this middleware.
|
|
480
483
|
|
|
481
|
-
Next, the middleware itself
|
|
484
|
+
Next, the middleware itself:
|
|
482
485
|
|
|
483
486
|
```ts
|
|
484
487
|
import { initTRPC, TRPCError } from '@trpc/server';
|
|
@@ -503,7 +506,7 @@ export const createIdentityPlugin = () => {
|
|
|
503
506
|
| undefined;
|
|
504
507
|
|
|
505
508
|
const sub = claims?.sub;
|
|
506
|
-
const username = claims?.
|
|
509
|
+
const username = claims?.username;
|
|
507
510
|
|
|
508
511
|
if (!sub || !username) {
|
|
509
512
|
throw new TRPCError({
|
|
@@ -541,14 +544,14 @@ export const me = publicProcedure
|
|
|
541
544
|
}));
|
|
542
545
|
```
|
|
543
546
|
|
|
544
|
-
:::tip[
|
|
545
|
-
You don't need `aws-jwt-verify` or any other JWT-verification library here — the API Gateway Cognito User Pools authorizer has already verified the signature, issuer,
|
|
547
|
+
:::tip[No token verification required]
|
|
548
|
+
You don't need `aws-jwt-verify` or any other JWT-verification library here — the API Gateway Cognito User Pools authorizer has already verified the signature, issuer, scopes, and expiry by the time your Lambda runs. If any of those checks fail, API Gateway returns `401 Unauthorized` and your handler is never invoked.
|
|
546
549
|
:::
|
|
547
550
|
</OptionFilter>
|
|
548
551
|
|
|
549
552
|
## Deploying your tRPC API
|
|
550
553
|
|
|
551
|
-
The tRPC API generator creates CDK or Terraform infrastructure as code based on your selected `
|
|
554
|
+
The tRPC API generator creates CDK or Terraform infrastructure as code based on your selected `iac`. You can use this to deploy your tRPC API.
|
|
552
555
|
|
|
553
556
|
<Infrastructure>
|
|
554
557
|
<Fragment slot="cdk">
|
|
@@ -556,7 +559,7 @@ The CDK construct for deploying your API lives in the `common/constructs` folder
|
|
|
556
559
|
|
|
557
560
|
<OptionFilter when={{ auth: ['iam', 'custom'] }} description="CDK usage for IAM or Custom authentication">
|
|
558
561
|
```ts {6-8}
|
|
559
|
-
import { MyApi } from '
|
|
562
|
+
import { MyApi } from '@my-scope/common-constructs';
|
|
560
563
|
|
|
561
564
|
export class ExampleStack extends Stack {
|
|
562
565
|
constructor(scope: Construct, id: string) {
|
|
@@ -570,12 +573,14 @@ export class ExampleStack extends Stack {
|
|
|
570
573
|
|
|
571
574
|
:::caution[Custom Lambda Authorizer]
|
|
572
575
|
When using `Custom` auth, the construct creates a Lambda Authorizer internally from the generated `src/authorizer.ts` file, which **denies all requests by default**. You must implement your authorization logic in that file before your API will accept any traffic.
|
|
576
|
+
|
|
577
|
+
Authorizer results are cached for 5 minutes, keyed on the `Authorization` header, so a revoked token may be accepted until its cached result expires. Reduce the cache duration in the generated infrastructure if you need faster revocation.
|
|
573
578
|
:::
|
|
574
579
|
</OptionFilter>
|
|
575
580
|
|
|
576
581
|
<OptionFilter when={{ auth: 'cognito' }} description="CDK usage with Cognito authentication — pass the identity construct">
|
|
577
|
-
```ts {6,
|
|
578
|
-
import { MyApi, UserIdentity } from '
|
|
582
|
+
```ts {6,10}
|
|
583
|
+
import { MyApi, UserIdentity } from '@my-scope/common-constructs';
|
|
579
584
|
|
|
580
585
|
export class ExampleStack extends Stack {
|
|
581
586
|
constructor(scope: Construct, id: string) {
|
|
@@ -630,7 +635,7 @@ module "my_api" {
|
|
|
630
635
|
</OptionFilter>
|
|
631
636
|
|
|
632
637
|
<OptionFilter when={{ auth: 'cognito' }} description="Terraform usage with Cognito authentication — supply user pool and client">
|
|
633
|
-
```hcl {1-3, 8-
|
|
638
|
+
```hcl {1-3, 8, 10-11}
|
|
634
639
|
module "asset_bucket" {
|
|
635
640
|
source = "../../common/terraform/src/core/asset-bucket"
|
|
636
641
|
}
|
|
@@ -715,6 +720,8 @@ module "my_api" {
|
|
|
715
720
|
<OptionFilter when={{ auth: 'custom' }} description="Custom Lambda Authorizer usage with Terraform">
|
|
716
721
|
:::caution[Custom Lambda Authorizer]
|
|
717
722
|
When using `Custom` auth, your API is protected by a Lambda Authorizer that **denies all requests by default**. You must implement your authorization logic in the generated `src/authorizer.ts` file before your API will accept any traffic.
|
|
723
|
+
|
|
724
|
+
Authorizer results are cached for 5 minutes, keyed on the `Authorization` header, so a revoked token may be accepted until its cached result expires. Reduce the cache duration in the generated infrastructure if you need faster revocation.
|
|
718
725
|
:::
|
|
719
726
|
</OptionFilter>
|
|
720
727
|
</Fragment>
|
|
@@ -726,12 +733,18 @@ When using `Custom` auth, your API is protected by a Lambda Authorizer that **de
|
|
|
726
733
|
<Snippet name="api/waf-configuration" parentHeading="WAF" />
|
|
727
734
|
</OptionFilter>
|
|
728
735
|
|
|
736
|
+
<OptionFilter when={{ infra: 'rest-lambda' }} description="Access logging — REST APIs log requests to CloudWatch by default">
|
|
737
|
+
### Access logging
|
|
738
|
+
|
|
739
|
+
<Snippet name="api/access-logging" parentHeading="Access logging" />
|
|
740
|
+
</OptionFilter>
|
|
741
|
+
|
|
729
742
|
### Integrations
|
|
730
743
|
|
|
731
744
|
<Snippet name="api/type-safe-api-integrations" parentHeading="Integrations" />
|
|
732
745
|
|
|
733
746
|
:::tip[CDK Type-Safe Integrations]
|
|
734
|
-
If you selected CDK for your `
|
|
747
|
+
If you selected CDK for your `iac`, when you add or remove a procedure in your tRPC API, these changes will be reflected immediately in the CDK construct without the need to rebuild.
|
|
735
748
|
:::
|
|
736
749
|
|
|
737
750
|
<OptionFilter when={{ auth: 'iam' }} description="Granting API invoke access — IAM-authenticated APIs only">
|
|
@@ -805,7 +818,7 @@ This will automatically reload when you make changes to your API.
|
|
|
805
818
|
You can create a tRPC client to invoke your API in a type-safe manner. If you are calling your tRPC API from another backend, you can use the client in `src/client/index.ts`, for example:
|
|
806
819
|
|
|
807
820
|
```ts
|
|
808
|
-
import { createMyApiClient } from '
|
|
821
|
+
import { createMyApiClient } from '@my-scope/my-api';
|
|
809
822
|
|
|
810
823
|
const client = createMyApiClient({ url: 'https://my-api-url.example.com/' });
|
|
811
824
|
|
|
@@ -817,3 +830,31 @@ If you are calling your API from a React website, consider using the <Link path=
|
|
|
817
830
|
## More Information
|
|
818
831
|
|
|
819
832
|
For more information about tRPC, please refer to the [tRPC documentation](https://trpc.io/docs).
|
|
833
|
+
|
|
834
|
+
## Connections
|
|
835
|
+
|
|
836
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
837
|
+
|
|
838
|
+
<CardGrid>
|
|
839
|
+
<ConnectionCard
|
|
840
|
+
title="React to tRPC"
|
|
841
|
+
description="Call a tRPC API from a React website"
|
|
842
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/react-trpc`}
|
|
843
|
+
source="react"
|
|
844
|
+
target="trpc"
|
|
845
|
+
/>
|
|
846
|
+
<ConnectionCard
|
|
847
|
+
title="tRPC API to Relational Database"
|
|
848
|
+
description="Connect a tRPC API to an Aurora relational database"
|
|
849
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-rdb`}
|
|
850
|
+
source="trpc"
|
|
851
|
+
target="aurora"
|
|
852
|
+
/>
|
|
853
|
+
<ConnectionCard
|
|
854
|
+
title="tRPC API to TypeScript DynamoDB"
|
|
855
|
+
description="Connect a tRPC API to a DynamoDB table"
|
|
856
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-dynamodb`}
|
|
857
|
+
source="trpc"
|
|
858
|
+
target="dynamodb"
|
|
859
|
+
/>
|
|
860
|
+
</CardGrid>
|