@aws/nx-plugin-mcp 1.0.0-rc.57 → 1.0.0-rc.59
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 +149 -156
- package/docs/get_started/graph-builder.mdx +37 -0
- package/docs/get_started/tutorials/contribute-generator.mdx +2 -2
- package/docs/get_started/tutorials/dungeon-game/1.mdx +2 -2
- package/docs/guides/agentcore-gateway.mdx +37 -10
- package/docs/guides/connection/agentcore-gateway-agent.mdx +282 -0
- package/docs/guides/connection/agentcore-gateway-gateway.mdx +2 -2
- package/docs/guides/connection/agentcore-gateway-mcp.mdx +2 -2
- package/docs/guides/connection/py-agent-a2a.mdx +1 -1
- package/docs/guides/connection/py-agent-gateway.mdx +2 -2
- package/docs/guides/connection/py-agent-mcp.mdx +3 -3
- package/docs/guides/connection/react-agentcore-gateway.mdx +112 -0
- package/docs/guides/connection/smithy-rdb.mdx +1 -1
- package/docs/guides/connection/trpc-rdb.mdx +1 -1
- package/docs/guides/connection/ts-agent-a2a.mdx +1 -1
- package/docs/guides/connection/ts-agent-gateway.mdx +1 -1
- package/docs/guides/connection/ts-agent-mcp.mdx +1 -1
- package/docs/guides/connection.mdx +18 -0
- package/docs/guides/fastapi.mdx +1 -1
- package/docs/guides/py-agent.mdx +7 -0
- package/docs/guides/react-website.mdx +9 -2
- package/docs/guides/terraform-project.mdx +1 -1
- package/docs/guides/trpc.mdx +2 -2
- package/docs/guides/ts-agent.mdx +7 -0
- package/docs/guides/ts-smithy-api.mdx +8 -8
- package/docs/snippets/agent/bedrock-deployment.mdx +1 -1
- package/docs/snippets/agent/runtime-arn.mdx +1 -1
- package/docs/snippets/api/cors-configuration-terraform-note.mdx +1 -1
- package/docs/snippets/api/type-safe-api-integrations.mdx +2 -2
- package/docs/snippets/api/waf-configuration.mdx +2 -2
- package/docs/snippets/connection/a2a-infrastructure.mdx +1 -1
- package/docs/snippets/mcp/bedrock-deployment.mdx +1 -1
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +1 -1
- package/generators.json +17 -1
- package/package.json +1 -1
- package/src/agentcore-gateway/agent-connection/schema.json +31 -0
- package/src/agentcore-gateway/react-connection/schema.json +31 -0
- package/src/agentcore-gateway/schema.json +3 -2
- package/src/py/agent/schema.json +1 -0
- package/src/py/dynamodb/schema.json +1 -0
- package/src/py/fast-api/schema.json +1 -0
- package/src/py/mcp-server/schema.json +1 -0
- package/src/py/rdb/schema.json +1 -0
- package/src/smithy/ts/api/schema.json +1 -0
- package/src/trpc/backend/schema.json +1 -0
- package/src/ts/agent/schema.json +1 -0
- package/src/ts/dynamodb/schema.json +1 -0
- package/src/ts/mcp-server/schema.json +1 -0
- package/src/ts/rdb/schema.json +1 -0
- package/src/ts/react-website/app/schema.json +1 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: React Website to AgentCore Gateway
|
|
3
|
+
description: Connect a React website to agents through an AgentCore Gateway
|
|
4
|
+
when:
|
|
5
|
+
sourceType: ts#react-website
|
|
6
|
+
targetType: agentcore-gateway
|
|
7
|
+
---
|
|
8
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
9
|
+
import Link from '@components/link.astro';
|
|
10
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
11
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
12
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
13
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
14
|
+
|
|
15
|
+
The `connection` generator can connect a <Link path="guides/react-website">React website</Link> to the agents fronted by an <Link path="guides/agentcore-gateway">AgentCore Gateway</Link> generated with `protocol: http`.
|
|
16
|
+
|
|
17
|
+
The browser talks only to the Gateway — requests to `<gatewayUrl>/<targetName>/invocations` are proxied to the agent runtime behind it. Because the website never needs to reach the runtimes directly, the agents can be deployed inside a VPC, with the Gateway as the single governed entry point providing authentication and observability.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
Before using this generator, ensure you have:
|
|
22
|
+
|
|
23
|
+
1. A <Link path="guides/react-website">React website</Link> project
|
|
24
|
+
2. An <Link path="guides/agentcore-gateway">`agentcore-gateway`</Link> project generated with `protocol: http`
|
|
25
|
+
3. At least one AG-UI or HTTP agent attached to the Gateway via the <Link path="guides/connection/agentcore-gateway-agent">Gateway to agent connection generator</Link>
|
|
26
|
+
|
|
27
|
+
The generator creates a website client for **each** AG-UI or HTTP agent attached to the Gateway (A2A targets are skipped — they speak agent-to-agent JSON-RPC, not a browser protocol). It generates the same clients as connecting the website to each agent directly (<Link path="guides/connection/react-agui">AG-UI/CopilotKit</Link> for AG-UI agents, an <Link path="guides/connection/react-py-agent">OpenAPI client</Link> for Python HTTP agents), routed through the Gateway rather than at the runtime.
|
|
28
|
+
|
|
29
|
+
:::note[Authentication]
|
|
30
|
+
The browser authenticates with the **Gateway**, not the agents: SigV4 for an IAM Gateway (via the website's Cognito identity pool), or a JWT bearer token for a Cognito Gateway.
|
|
31
|
+
:::
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Run the Generator
|
|
36
|
+
|
|
37
|
+
<RunGenerator generator="connection" />
|
|
38
|
+
|
|
39
|
+
Select the website project as the source and the Gateway project as the target.
|
|
40
|
+
|
|
41
|
+
### Options
|
|
42
|
+
|
|
43
|
+
<GeneratorParameters generator="connection" />
|
|
44
|
+
|
|
45
|
+
## Generator Output
|
|
46
|
+
|
|
47
|
+
For each fronted AG-UI agent, the same files as the <Link path="guides/connection/react-agui">React to AG-UI agent connection</Link> are generated (an `AguiProvider`, a `useAgui<Agent>` hook and a themed CopilotKit component module), with the hook reading the Gateway's URL from runtime configuration:
|
|
48
|
+
|
|
49
|
+
<FileTree>
|
|
50
|
+
|
|
51
|
+
- packages/\<website>/src
|
|
52
|
+
- components
|
|
53
|
+
- AguiProvider.tsx CopilotKit provider registering each agent
|
|
54
|
+
- copilot/ Themed chat components
|
|
55
|
+
- hooks
|
|
56
|
+
- useAgui\<Agent>.tsx Connects to the agent via the Gateway's `/<targetName>/invocations` route
|
|
57
|
+
|
|
58
|
+
</FileTree>
|
|
59
|
+
|
|
60
|
+
For each fronted Python HTTP agent, the same files as the <Link path="guides/connection/react-py-agent">React to Python agent connection</Link> are generated (a type-safe OpenAPI client, hooks, and a provider), with the client's base URL routed through the Gateway.
|
|
61
|
+
|
|
62
|
+
The Gateway's URL is registered in the `connection.gateways.<GatewayClassName>` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link>, so it is published to the website's `runtime-config.json`.
|
|
63
|
+
|
|
64
|
+
## Granting website users access
|
|
65
|
+
|
|
66
|
+
For an **IAM** Gateway, grant the website's authenticated users permission to invoke it (a **Cognito** Gateway needs no grant — the browser authenticates with its JWT bearer token instead):
|
|
67
|
+
|
|
68
|
+
<Infrastructure>
|
|
69
|
+
<Fragment slot="cdk">
|
|
70
|
+
```ts title="packages/infra/src/stacks/application-stack.ts" {6}
|
|
71
|
+
const identity = new UserIdentity(this, 'UserIdentity');
|
|
72
|
+
new Website(this, 'Website');
|
|
73
|
+
|
|
74
|
+
const myGateway = new MyGateway(this, 'MyGateway');
|
|
75
|
+
myGateway.addAgent(myAgent);
|
|
76
|
+
myGateway.grantInvokeAccess(identity.identityPool.authenticatedRole);
|
|
77
|
+
```
|
|
78
|
+
</Fragment>
|
|
79
|
+
<Fragment slot="terraform">
|
|
80
|
+
```hcl title="packages/infra/src/main.tf"
|
|
81
|
+
resource "aws_iam_policy" "gateway_invoke_policy" {
|
|
82
|
+
name = "GatewayInvokePolicy"
|
|
83
|
+
|
|
84
|
+
policy = jsonencode({
|
|
85
|
+
Version = "2012-10-17"
|
|
86
|
+
Statement = [
|
|
87
|
+
{
|
|
88
|
+
Effect = "Allow"
|
|
89
|
+
Action = ["bedrock-agentcore:InvokeGateway"]
|
|
90
|
+
Resource = [module.my_gateway.gateway_arn]
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
resource "aws_iam_role_policy_attachment" "authenticated_gateway_access" {
|
|
97
|
+
role = module.user_identity.authenticated_role_name
|
|
98
|
+
policy_arn = aws_iam_policy.gateway_invoke_policy.arn
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
</Fragment>
|
|
102
|
+
</Infrastructure>
|
|
103
|
+
|
|
104
|
+
## Local Development
|
|
105
|
+
|
|
106
|
+
The website's `dev` target gains a dependency on the Gateway project's `dev` target, which starts the local gateway plus every attached agent. The website's runtime configuration is overridden in `local-dev` mode to point the Gateway's URL at the local gateway, so the browser exercises the same `/<targetName>/invocations` routes locally:
|
|
107
|
+
|
|
108
|
+
<NxCommands commands={["dev <website-name>"]} />
|
|
109
|
+
|
|
110
|
+
## Connecting new agents
|
|
111
|
+
|
|
112
|
+
The generator connects the website to the agents attached to the Gateway **at the time it runs**. After attaching another agent to the Gateway, re-run the connection generator to generate its website client — existing clients are left untouched.
|
|
@@ -69,7 +69,7 @@ export interface ServiceContext {
|
|
|
69
69
|
|
|
70
70
|
The Prisma client is instantiated inside `lambdaHandler` and passed through the service context:
|
|
71
71
|
|
|
72
|
-
```ts title="packages/api/src/handler.ts" {1,10}
|
|
72
|
+
```ts title="packages/api/src/handler.ts" {1,5,10}
|
|
73
73
|
import { getPrisma as getMyDb } from '@my-scope/my-db';
|
|
74
74
|
|
|
75
75
|
export const lambdaHandler = async (event: APIGatewayProxyEvent) => {
|
|
@@ -65,7 +65,7 @@ export const authenticatedProcedure = t.procedure
|
|
|
65
65
|
|
|
66
66
|
The plugin merges `IMyDbContext` into your procedure context, making `myDb` available as an optional property:
|
|
67
67
|
|
|
68
|
-
```ts title="packages/api/src/procedures/users.ts" {8
|
|
68
|
+
```ts title="packages/api/src/procedures/users.ts" {7-8}
|
|
69
69
|
import { z } from 'zod';
|
|
70
70
|
import { authenticatedProcedure } from '../router.js';
|
|
71
71
|
|
|
@@ -68,7 +68,7 @@ Additionally, it:
|
|
|
68
68
|
|
|
69
69
|
The generator transforms your agent's `agent.ts` to wrap the remote A2A agent as a tool:
|
|
70
70
|
|
|
71
|
-
```ts title="packages/example/src/my-agent/agent.ts" {2,5-
|
|
71
|
+
```ts title="packages/example/src/my-agent/agent.ts" {2,5-12,15}
|
|
72
72
|
import { Agent, tool } from '@strands-agents/sdk';
|
|
73
73
|
import { RemoteAgentClientStrands } from '@my-scope/agent-connection';
|
|
74
74
|
import { z } from 'zod';
|
|
@@ -99,7 +99,7 @@ gateway.grantInvokeAccess(myAgent);
|
|
|
99
99
|
The Gateway URL is automatically registered in the `agentcore.gateways.<ClassName>` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link> by the generated CDK construct, so the agent can discover it at runtime.
|
|
100
100
|
</Fragment>
|
|
101
101
|
<Fragment slot="terraform">
|
|
102
|
-
```hcl title="packages/infra/src/main.tf" {
|
|
102
|
+
```hcl title="packages/infra/src/main.tf" {8-13}
|
|
103
103
|
module "my_gateway" {
|
|
104
104
|
source = "../../common/terraform/src/app/gateways/my-gateway"
|
|
105
105
|
}
|
|
@@ -102,7 +102,7 @@ The MCP server's AgentCore runtime ARN is automatically registered in the `agent
|
|
|
102
102
|
<Fragment slot="terraform">
|
|
103
103
|
After running the connection generator, you need to grant the agent permission to invoke the MCP server in your Terraform configuration:
|
|
104
104
|
|
|
105
|
-
```hcl title="packages/infra/src/main.tf" {
|
|
105
|
+
```hcl title="packages/infra/src/main.tf" {9-25}
|
|
106
106
|
module "inventory_mcp_server" {
|
|
107
107
|
source = "../../common/terraform/src/app/mcp-servers/inventory-mcp"
|
|
108
108
|
}
|
|
@@ -11,6 +11,10 @@ import GeneratorParameters from '@components/generator-parameters.astro';
|
|
|
11
11
|
|
|
12
12
|
This generator is used to connect projects together, such as websites calling APIs. Simply select the source project (for example the project that will call your API) and target project (for example your API project), and this generator will handle integrating the two.
|
|
13
13
|
|
|
14
|
+
:::tip[Sketch it visually]
|
|
15
|
+
Prefer to design your workspace first? The <Link path="get_started/graph-builder">Graph Builder</Link> lets you drag out projects and draw the connections between them, then gives you the commands to scaffold the lot.
|
|
16
|
+
:::
|
|
17
|
+
|
|
14
18
|
## Usage
|
|
15
19
|
|
|
16
20
|
### Run the Generator
|
|
@@ -243,6 +247,20 @@ The Connection generator supports the following connections:
|
|
|
243
247
|
sourceBadge="python"
|
|
244
248
|
target="agentcore"
|
|
245
249
|
/>
|
|
250
|
+
<ConnectionCard
|
|
251
|
+
title="AgentCore Gateway to Agent"
|
|
252
|
+
description="Front an agent with an AgentCore Gateway as a runtime target"
|
|
253
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-agent`}
|
|
254
|
+
source="agentcore"
|
|
255
|
+
target="strands"
|
|
256
|
+
/>
|
|
257
|
+
<ConnectionCard
|
|
258
|
+
title="React Website to AgentCore Gateway"
|
|
259
|
+
description="Connect a React website to agents through an AgentCore Gateway"
|
|
260
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/react-agentcore-gateway`}
|
|
261
|
+
source="react"
|
|
262
|
+
target="agentcore"
|
|
263
|
+
/>
|
|
246
264
|
</CardGrid>
|
|
247
265
|
|
|
248
266
|
:::note[Runtime Configuration]
|
package/docs/guides/fastapi.mdx
CHANGED
|
@@ -542,7 +542,7 @@ This sets up:
|
|
|
542
542
|
:::note[Cognito Authentication]
|
|
543
543
|
If you selected to use `Cognito` authentication, you will need to supply the Cognito configuration:
|
|
544
544
|
|
|
545
|
-
```hcl {
|
|
545
|
+
```hcl {6-7}
|
|
546
546
|
module "my_api" {
|
|
547
547
|
source = "../../common/terraform/src/app/apis/my-api"
|
|
548
548
|
|
package/docs/guides/py-agent.mdx
CHANGED
|
@@ -688,4 +688,11 @@ Use the <Link path="guides/connection">`connection`</Link> generator to integrat
|
|
|
688
688
|
sourceBadge="python"
|
|
689
689
|
target="agentcore"
|
|
690
690
|
/>
|
|
691
|
+
<ConnectionCard
|
|
692
|
+
title="AgentCore Gateway to Agent"
|
|
693
|
+
description="Front an agent with an AgentCore Gateway as a runtime target"
|
|
694
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-agent`}
|
|
695
|
+
source="agentcore"
|
|
696
|
+
target="strands"
|
|
697
|
+
/>
|
|
691
698
|
</CardGrid>
|
|
@@ -145,7 +145,7 @@ By default the distribution uses the default CloudFront domain name (`*.cloudfro
|
|
|
145
145
|
<Fragment slot="cdk">
|
|
146
146
|
Pass the `certificate` and `domainNames` props through in your generated website construct in `packages/common/constructs/src/app/static-websites`:
|
|
147
147
|
|
|
148
|
-
```ts {6-
|
|
148
|
+
```ts {6-8}
|
|
149
149
|
export class MyWebsite extends StaticWebsite {
|
|
150
150
|
constructor(scope: Construct, id: string) {
|
|
151
151
|
super(scope, id, {
|
|
@@ -272,7 +272,7 @@ With Terraform, runtime configuration is managed through the runtime-config modu
|
|
|
272
272
|
|
|
273
273
|
Your website Terraform module will deploy the `connection` namespace of the runtime configuration as a `runtime-config.json` file to the root of your S3 bucket.
|
|
274
274
|
|
|
275
|
-
```hcl title="packages/infra/src/main.tf" {
|
|
275
|
+
```hcl title="packages/infra/src/main.tf" {20-21}
|
|
276
276
|
module "asset_bucket" {
|
|
277
277
|
source = "../../common/terraform/src/core/asset-bucket"
|
|
278
278
|
}
|
|
@@ -533,4 +533,11 @@ Use the <Link path="guides/connection">`connection`</Link> generator to integrat
|
|
|
533
533
|
source="react"
|
|
534
534
|
target="copilotkit"
|
|
535
535
|
/>
|
|
536
|
+
<ConnectionCard
|
|
537
|
+
title="React Website to AgentCore Gateway"
|
|
538
|
+
description="Connect a React website to agents through an AgentCore Gateway"
|
|
539
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/react-agentcore-gateway`}
|
|
540
|
+
source="react"
|
|
541
|
+
target="agentcore"
|
|
542
|
+
/>
|
|
536
543
|
</CardGrid>
|
|
@@ -84,7 +84,7 @@ Application projects include full deployment capabilities with remote state mana
|
|
|
84
84
|
|
|
85
85
|
You can start writing your Terraform infrastructure inside `src/main.tf`, for example:
|
|
86
86
|
|
|
87
|
-
```diff title="src/main.tf" {
|
|
87
|
+
```diff title="src/main.tf" {16-19}
|
|
88
88
|
-locals {
|
|
89
89
|
- account_id = data.aws_caller_identity.current.account_id
|
|
90
90
|
- aws_region = data.aws_region.current.id
|
package/docs/guides/trpc.mdx
CHANGED
|
@@ -577,7 +577,7 @@ When using `Custom` auth, the construct creates a Lambda Authorizer internally f
|
|
|
577
577
|
</OptionFilter>
|
|
578
578
|
|
|
579
579
|
<OptionFilter when={{ auth: 'cognito' }} description="CDK usage with Cognito authentication — pass the identity construct">
|
|
580
|
-
```ts {6,
|
|
580
|
+
```ts {6,10}
|
|
581
581
|
import { MyApi, UserIdentity } from '@my-scope/common-constructs';
|
|
582
582
|
|
|
583
583
|
export class ExampleStack extends Stack {
|
|
@@ -633,7 +633,7 @@ module "my_api" {
|
|
|
633
633
|
</OptionFilter>
|
|
634
634
|
|
|
635
635
|
<OptionFilter when={{ auth: 'cognito' }} description="Terraform usage with Cognito authentication — supply user pool and client">
|
|
636
|
-
```hcl {1-3, 8-
|
|
636
|
+
```hcl {1-3, 8, 10-11}
|
|
637
637
|
module "asset_bucket" {
|
|
638
638
|
source = "../../common/terraform/src/core/asset-bucket"
|
|
639
639
|
}
|
package/docs/guides/ts-agent.mdx
CHANGED
|
@@ -599,4 +599,11 @@ Use the <Link path="guides/connection">`connection`</Link> generator to integrat
|
|
|
599
599
|
sourceBadge="typescript"
|
|
600
600
|
target="agentcore"
|
|
601
601
|
/>
|
|
602
|
+
<ConnectionCard
|
|
603
|
+
title="AgentCore Gateway to Agent"
|
|
604
|
+
description="Front an agent with an AgentCore Gateway as a runtime target"
|
|
605
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-agent`}
|
|
606
|
+
source="agentcore"
|
|
607
|
+
target="strands"
|
|
608
|
+
/>
|
|
602
609
|
</CardGrid>
|
|
@@ -308,7 +308,7 @@ You must construct the context yourself in both `handler.ts` (the Lambda functio
|
|
|
308
308
|
|
|
309
309
|
The generator configures structured logging using AWS Lambda Powertools with automatic context injection via Middy middleware.
|
|
310
310
|
|
|
311
|
-
```typescript {
|
|
311
|
+
```typescript {3}
|
|
312
312
|
// handler.ts
|
|
313
313
|
export const handler = middy<APIGatewayProxyEvent, APIGatewayProxyResult>()
|
|
314
314
|
.use(captureLambdaHandler(tracer))
|
|
@@ -319,7 +319,7 @@ export const handler = middy<APIGatewayProxyEvent, APIGatewayProxyResult>()
|
|
|
319
319
|
|
|
320
320
|
You can reference the logger from your operation implementations via the context:
|
|
321
321
|
|
|
322
|
-
```typescript {
|
|
322
|
+
```typescript {5}
|
|
323
323
|
// operations/echo.ts
|
|
324
324
|
import { ServiceContext } from '../context.js';
|
|
325
325
|
import { Echo as EchoOperation } from '../generated/ssdk/index.js';
|
|
@@ -334,7 +334,7 @@ export const Echo: EchoOperation<ServiceContext> = async (input, ctx) => {
|
|
|
334
334
|
|
|
335
335
|
AWS X-Ray tracing is configured automatically via the `captureLambdaHandler` middleware.
|
|
336
336
|
|
|
337
|
-
```typescript {
|
|
337
|
+
```typescript {2}
|
|
338
338
|
// handler.ts
|
|
339
339
|
export const handler = middy<APIGatewayProxyEvent, APIGatewayProxyResult>()
|
|
340
340
|
.use(captureLambdaHandler(tracer))
|
|
@@ -345,7 +345,7 @@ export const handler = middy<APIGatewayProxyEvent, APIGatewayProxyResult>()
|
|
|
345
345
|
|
|
346
346
|
You can add custom subsegments to your traces in your operations:
|
|
347
347
|
|
|
348
|
-
```typescript {
|
|
348
|
+
```typescript {6, 10, 13}
|
|
349
349
|
// operations/echo.ts
|
|
350
350
|
import { ServiceContext } from '../context.js';
|
|
351
351
|
import { Echo as EchoOperation } from '../generated/ssdk/index.js';
|
|
@@ -368,7 +368,7 @@ export const Echo: EchoOperation<ServiceContext> = async (input, ctx) => {
|
|
|
368
368
|
|
|
369
369
|
CloudWatch metrics are collected automatically for each request via the `logMetrics` middleware.
|
|
370
370
|
|
|
371
|
-
```typescript {
|
|
371
|
+
```typescript {4}
|
|
372
372
|
// handler.ts
|
|
373
373
|
export const handler = middy<APIGatewayProxyEvent, APIGatewayProxyResult>()
|
|
374
374
|
.use(captureLambdaHandler(tracer))
|
|
@@ -379,7 +379,7 @@ export const handler = middy<APIGatewayProxyEvent, APIGatewayProxyResult>()
|
|
|
379
379
|
|
|
380
380
|
You can add custom metrics in your operations:
|
|
381
381
|
|
|
382
|
-
```typescript {
|
|
382
|
+
```typescript {6}
|
|
383
383
|
// operations/echo.ts
|
|
384
384
|
import { MetricUnit } from '@aws-lambda-powertools/metrics';
|
|
385
385
|
import { ServiceContext } from '../context.js';
|
|
@@ -451,7 +451,7 @@ structure UnauthorizedError {
|
|
|
451
451
|
|
|
452
452
|
First, expose the resolved identity on the service context in `src/context.ts`. We provide it as a function so that the `UnauthorizedError` is thrown from within an operation (where the Server SDK serializes it to a `403`), rather than from the handler:
|
|
453
453
|
|
|
454
|
-
```ts {
|
|
454
|
+
```ts {5-8,17} ins={5-8,17}
|
|
455
455
|
import { Logger } from '@aws-lambda-powertools/logger';
|
|
456
456
|
import { Metrics } from '@aws-lambda-powertools/metrics';
|
|
457
457
|
import { Tracer } from '@aws-lambda-powertools/tracer';
|
|
@@ -710,7 +710,7 @@ This sets up:
|
|
|
710
710
|
:::note[Cognito Authentication]
|
|
711
711
|
If you selected `Cognito` authentication, you will need to supply the Cognito configuration:
|
|
712
712
|
|
|
713
|
-
```hcl {
|
|
713
|
+
```hcl {6-7}
|
|
714
714
|
module "my_api" {
|
|
715
715
|
source = "../../common/terraform/src/app/apis/my-api"
|
|
716
716
|
|
|
@@ -149,7 +149,7 @@ The `UserIdentity` construct can be generated using the <Link path="/guides/reac
|
|
|
149
149
|
<Fragment slot="terraform">
|
|
150
150
|
The generated module accepts `user_pool_id` and `user_pool_client_ids` variables for Cognito authentication:
|
|
151
151
|
|
|
152
|
-
```terraform {
|
|
152
|
+
```terraform {11-12}
|
|
153
153
|
module "user_identity" {
|
|
154
154
|
source = "../../common/terraform/src/core/user-identity"
|
|
155
155
|
}
|
|
@@ -26,7 +26,7 @@ export class ExampleStack extends Stack {
|
|
|
26
26
|
```
|
|
27
27
|
</Fragment>
|
|
28
28
|
<Fragment slot="terraform">
|
|
29
|
-
```terraform {
|
|
29
|
+
```terraform {9-10}
|
|
30
30
|
# Agent
|
|
31
31
|
module "my_project_agent" {
|
|
32
32
|
# Relative path to the generated module in the common/terraform project
|
|
@@ -9,7 +9,7 @@ Given a CloudFront domain name `<domain_name>`, within the Terraform module for
|
|
|
9
9
|
- a `cors_allow_origins` property, set to `["http://localhost:4200", "http://localhost:4300", "https://<domain name>"]`, for HTTP APIs. This restricts the API gateway CORS to this distribution and local host.
|
|
10
10
|
- an `ALLOWED_ORIGINS` environment variable, set to `"https://<domain_name>"`, for REST APIs. This sets the CloudFront distribution as the only permitted CORS origin (other than local host) in AWS Lambda integrations. Note that this restriction is not applied to preflight OPTIONS - please +1 [this GitHub issue](https://github.com/awslabs/nx-plugin-for-aws/issues/377) to help prioritise addressing this.
|
|
11
11
|
|
|
12
|
-
```hcl {
|
|
12
|
+
```hcl {6,9}
|
|
13
13
|
module "my_api" {
|
|
14
14
|
source = "../../common/terraform/src/app/apis/my-api"
|
|
15
15
|
|
|
@@ -69,7 +69,7 @@ api.integrations.sayHello.handler.addToRolePolicy(new PolicyStatement({
|
|
|
69
69
|
|
|
70
70
|
If your API uses the `shared` pattern, the shared router Lambda is exposed as `api.integrations.$router`:
|
|
71
71
|
|
|
72
|
-
```ts {
|
|
72
|
+
```ts {5}
|
|
73
73
|
const api = new MyApi(this, 'MyApi', {
|
|
74
74
|
integrations: MyApi.defaultIntegrations(this).build(),
|
|
75
75
|
});
|
|
@@ -640,7 +640,7 @@ Generated CDK API constructs support two integration patterns:
|
|
|
640
640
|
|
|
641
641
|
For example, setting `pattern` to `'shared'` creates a single function instead of one per integration:
|
|
642
642
|
|
|
643
|
-
```ts {
|
|
643
|
+
```ts {6}
|
|
644
644
|
// packages/common/constructs/src/app/apis/my-api.ts
|
|
645
645
|
export class MyApi<...> extends ... {
|
|
646
646
|
|
|
@@ -15,7 +15,7 @@ You can edit the generated rest-api construct to add, remove, or adjust rules (f
|
|
|
15
15
|
<Fragment slot="cdk">
|
|
16
16
|
To opt out (for example, to attach your own Web ACL), set `enableWaf` to `false`:
|
|
17
17
|
|
|
18
|
-
```ts {
|
|
18
|
+
```ts {3}
|
|
19
19
|
const api = new MyApi(this, 'MyApi', {
|
|
20
20
|
integrations: MyApi.defaultIntegrations(this).build(),
|
|
21
21
|
enableWaf: false,
|
|
@@ -25,7 +25,7 @@ const api = new MyApi(this, 'MyApi', {
|
|
|
25
25
|
<Fragment slot="terraform">
|
|
26
26
|
To opt out (for example, to attach your own Web ACL), set `enable_waf` to `false`:
|
|
27
27
|
|
|
28
|
-
```hcl {
|
|
28
|
+
```hcl {5}
|
|
29
29
|
module "my_api" {
|
|
30
30
|
source = "../../common/terraform/src/app/apis/my-api"
|
|
31
31
|
|
|
@@ -21,7 +21,7 @@ remoteAgent.grantInvokeAccess(myAgent);
|
|
|
21
21
|
The remote agent's AgentCore runtime ARN is automatically registered in the `agentcore` namespace of <Link path="guides/runtime-config">Runtime Configuration</Link> by the generated CDK construct, so the host agent can discover it at runtime.
|
|
22
22
|
</Fragment>
|
|
23
23
|
<Fragment slot="terraform">
|
|
24
|
-
```hcl title="packages/infra/src/main.tf" {
|
|
24
|
+
```hcl title="packages/infra/src/main.tf" {15-34}
|
|
25
25
|
module "remote_agent" {
|
|
26
26
|
source = "../../common/terraform/src/app/agents/remote-agent"
|
|
27
27
|
|
|
@@ -144,7 +144,7 @@ The `UserIdentity` construct can be generated using the <Link path="/guides/reac
|
|
|
144
144
|
<Fragment slot="terraform">
|
|
145
145
|
The generated module accepts `user_pool_id` and `user_pool_client_ids` variables for Cognito authentication:
|
|
146
146
|
|
|
147
|
-
```terraform {
|
|
147
|
+
```terraform {11-12}
|
|
148
148
|
module "user_identity" {
|
|
149
149
|
source = "../../common/terraform/src/core/user-identity"
|
|
150
150
|
}
|
|
@@ -167,7 +167,7 @@ new MyApi(this, 'MyApi', {
|
|
|
167
167
|
|
|
168
168
|
You will need to "stub" your service/router for your service to compile if using the `ts#smithy-api` and the TypeScript Server SDK, eg:
|
|
169
169
|
|
|
170
|
-
```ts {
|
|
170
|
+
```ts {3}
|
|
171
171
|
// service.ts
|
|
172
172
|
export const Service: ApiService<ServiceContext> = {
|
|
173
173
|
...
|
package/generators.json
CHANGED
|
@@ -30,6 +30,20 @@
|
|
|
30
30
|
"metric": "g65",
|
|
31
31
|
"hidden": true
|
|
32
32
|
},
|
|
33
|
+
"agentcore-gateway#agent-connection": {
|
|
34
|
+
"factory": "./src/agentcore-gateway/agent-connection/generator",
|
|
35
|
+
"schema": "./src/agentcore-gateway/agent-connection/schema.json",
|
|
36
|
+
"description": "Connect an AgentCore Gateway to an agent, adding the agent as a gateway target",
|
|
37
|
+
"metric": "g69",
|
|
38
|
+
"hidden": true
|
|
39
|
+
},
|
|
40
|
+
"agentcore-gateway#react-connection": {
|
|
41
|
+
"factory": "./src/agentcore-gateway/react-connection/generator",
|
|
42
|
+
"schema": "./src/agentcore-gateway/react-connection/schema.json",
|
|
43
|
+
"description": "Connect a React website to an AgentCore Gateway fronting agents",
|
|
44
|
+
"metric": "g70",
|
|
45
|
+
"hidden": true
|
|
46
|
+
},
|
|
33
47
|
"connection": {
|
|
34
48
|
"factory": "./src/connection/generator",
|
|
35
49
|
"schema": "./src/connection/schema.json",
|
|
@@ -54,7 +68,9 @@
|
|
|
54
68
|
"connection/ts-agent-gateway",
|
|
55
69
|
"connection/py-agent-gateway",
|
|
56
70
|
"connection/agentcore-gateway-mcp",
|
|
57
|
-
"connection/agentcore-gateway-gateway"
|
|
71
|
+
"connection/agentcore-gateway-gateway",
|
|
72
|
+
"connection/agentcore-gateway-agent",
|
|
73
|
+
"connection/react-agentcore-gateway"
|
|
58
74
|
]
|
|
59
75
|
},
|
|
60
76
|
"license": {
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "agentcore-gateway#agent-connection",
|
|
4
|
+
"title": "agentcore-gateway#agent-connection",
|
|
5
|
+
"description": "Connect an AgentCore Gateway to an agent, adding the agent as a gateway target",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The gateway project"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The agent project"
|
|
15
|
+
},
|
|
16
|
+
"sourceComponent": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The gateway component in the source project"
|
|
19
|
+
},
|
|
20
|
+
"targetComponent": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "The agent component in the target project"
|
|
23
|
+
},
|
|
24
|
+
"preferInstallDependencies": {
|
|
25
|
+
"type": "boolean",
|
|
26
|
+
"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.",
|
|
27
|
+
"default": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"required": ["sourceProject", "targetProject"]
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "agentcore-gateway#react-connection",
|
|
4
|
+
"title": "agentcore-gateway#react-connection",
|
|
5
|
+
"description": "Connect a React website to an AgentCore Gateway fronting agents",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"sourceProject": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The React website project"
|
|
11
|
+
},
|
|
12
|
+
"targetProject": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The gateway project"
|
|
15
|
+
},
|
|
16
|
+
"sourceComponent": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The website component in the source project"
|
|
19
|
+
},
|
|
20
|
+
"targetComponent": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "The gateway component in the target project"
|
|
23
|
+
},
|
|
24
|
+
"preferInstallDependencies": {
|
|
25
|
+
"type": "boolean",
|
|
26
|
+
"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.",
|
|
27
|
+
"default": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"required": ["sourceProject", "targetProject"]
|
|
31
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"$id": "agentcore-gateway",
|
|
4
4
|
"title": "agentcore-gateway",
|
|
5
|
+
"x-label": "AgentCore Gateway",
|
|
5
6
|
"description": "Generate an AgentCore Gateway project",
|
|
6
7
|
"type": "object",
|
|
7
8
|
"properties": {
|
|
@@ -26,8 +27,8 @@
|
|
|
26
27
|
},
|
|
27
28
|
"protocol": {
|
|
28
29
|
"type": "string",
|
|
29
|
-
"description": "The inbound protocol exposed by your gateway.
|
|
30
|
-
"enum": ["mcp"],
|
|
30
|
+
"description": "The inbound protocol exposed by your gateway. An mcp gateway aggregates MCP server targets into a single MCP endpoint. An http gateway proxies requests to agent runtime targets via path-based routing, so callers (e.g. a website) can reach agents through the gateway.",
|
|
31
|
+
"enum": ["mcp", "http"],
|
|
31
32
|
"default": "mcp",
|
|
32
33
|
"x-priority": "important"
|
|
33
34
|
},
|
package/src/py/agent/schema.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"$id": "py#mcp-server",
|
|
4
4
|
"title": "py#mcp-server",
|
|
5
|
+
"x-label": "MCP Server",
|
|
5
6
|
"description": "Generate a Python Model Context Protocol (MCP) server for providing context to Large Language Models",
|
|
6
7
|
"type": "object",
|
|
7
8
|
"properties": {
|
package/src/py/rdb/schema.json
CHANGED