@aws/nx-plugin-mcp 1.0.0-rc.20 → 1.0.0-rc.22
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/docs/guides/agentcore-gateway.mdx +39 -7
- package/docs/guides/connection/py-agent-a2a.mdx +39 -10
- package/docs/guides/connection/py-agent-gateway.mdx +33 -7
- package/docs/guides/connection/py-agent-mcp.mdx +34 -8
- package/docs/guides/fastapi.mdx +235 -1
- package/docs/guides/py-agent.mdx +155 -38
- package/docs/guides/py-dynamodb.mdx +36 -9
- package/docs/guides/py-mcp-server.mdx +42 -1
- package/docs/guides/react-website.mdx +53 -1
- package/docs/guides/trpc.mdx +35 -5
- package/docs/guides/ts-agent.mdx +73 -1
- package/docs/guides/ts-dynamodb.mdx +39 -10
- package/docs/guides/ts-mcp-server.mdx +47 -1
- package/docs/guides/ts-rdb.mdx +39 -10
- package/docs/guides/ts-smithy-api.mdx +176 -1
- package/package.json +1 -1
- package/src/py/agent/schema.json +1 -1
package/docs/guides/ts-agent.mdx
CHANGED
|
@@ -4,7 +4,9 @@ description: Generate a TypeScript Agent for building AI agents with tools and d
|
|
|
4
4
|
generator: ts#agent
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import { FileTree, Tabs, TabItem } from '@astrojs/starlight/components';
|
|
7
|
+
import { FileTree, Tabs, TabItem, CardGrid } from '@astrojs/starlight/components';
|
|
8
|
+
import Astro from '@astrojs/react';
|
|
9
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
8
10
|
import RunGenerator from '@components/run-generator.astro';
|
|
9
11
|
import NxCommands from '@components/nx-commands.astro';
|
|
10
12
|
import Link from '@components/link.astro';
|
|
@@ -472,3 +474,73 @@ To invoke your AG-UI agent from a React website, use the <Link path="/guides/con
|
|
|
472
474
|
|
|
473
475
|
Refer to the <Link path="/guides/connection/react-agui">`connection` generator guide</Link> for details about how the connection is set up.
|
|
474
476
|
</OptionFilter>
|
|
477
|
+
|
|
478
|
+
## Connections
|
|
479
|
+
|
|
480
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
481
|
+
|
|
482
|
+
<CardGrid>
|
|
483
|
+
<ConnectionCard
|
|
484
|
+
title="React to TypeScript Agent"
|
|
485
|
+
description="Call a TypeScript Agent from a React website"
|
|
486
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/react-ts-agent`}
|
|
487
|
+
source="react"
|
|
488
|
+
target="strands"
|
|
489
|
+
targetBadge="typescript"
|
|
490
|
+
/>
|
|
491
|
+
<ConnectionCard
|
|
492
|
+
title="React to AG-UI Agent"
|
|
493
|
+
description="Call an Agent exposing the AG-UI protocol from a React website via CopilotKit"
|
|
494
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/react-agui`}
|
|
495
|
+
source="react"
|
|
496
|
+
target="copilotkit"
|
|
497
|
+
/>
|
|
498
|
+
<ConnectionCard
|
|
499
|
+
title="TypeScript Agent to MCP"
|
|
500
|
+
description="Connect a TypeScript Agent to an MCP server"
|
|
501
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-mcp`}
|
|
502
|
+
source="strands"
|
|
503
|
+
sourceBadge="typescript"
|
|
504
|
+
target="mcp"
|
|
505
|
+
/>
|
|
506
|
+
<ConnectionCard
|
|
507
|
+
title="TypeScript Agent to A2A Agent"
|
|
508
|
+
description="Connect a TypeScript Agent to a remote A2A agent"
|
|
509
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-a2a`}
|
|
510
|
+
source="strands"
|
|
511
|
+
sourceBadge="typescript"
|
|
512
|
+
target="a2a"
|
|
513
|
+
/>
|
|
514
|
+
<ConnectionCard
|
|
515
|
+
title="Python Agent to A2A Agent"
|
|
516
|
+
description="Connect a Python Agent to a remote A2A agent"
|
|
517
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-agent-a2a`}
|
|
518
|
+
source="strands"
|
|
519
|
+
sourceBadge="python"
|
|
520
|
+
target="a2a"
|
|
521
|
+
/>
|
|
522
|
+
<ConnectionCard
|
|
523
|
+
title="TypeScript Agent to Relational Database"
|
|
524
|
+
description="Connect a TypeScript Agent to an Aurora relational database"
|
|
525
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-rdb`}
|
|
526
|
+
source="strands"
|
|
527
|
+
sourceBadge="typescript"
|
|
528
|
+
target="aurora"
|
|
529
|
+
/>
|
|
530
|
+
<ConnectionCard
|
|
531
|
+
title="TypeScript Agent to TypeScript DynamoDB"
|
|
532
|
+
description="Connect a TypeScript Agent to a DynamoDB table"
|
|
533
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-dynamodb`}
|
|
534
|
+
source="strands"
|
|
535
|
+
sourceBadge="typescript"
|
|
536
|
+
target="dynamodb"
|
|
537
|
+
/>
|
|
538
|
+
<ConnectionCard
|
|
539
|
+
title="TypeScript Agent to AgentCore Gateway"
|
|
540
|
+
description="Connect a TypeScript Agent to an AgentCore Gateway"
|
|
541
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-gateway`}
|
|
542
|
+
source="strands"
|
|
543
|
+
sourceBadge="typescript"
|
|
544
|
+
target="agentcore"
|
|
545
|
+
/>
|
|
546
|
+
</CardGrid>
|
|
@@ -4,7 +4,9 @@ description: Create a TypeScript DynamoDB project
|
|
|
4
4
|
generator: ts#dynamodb
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import { FileTree, CardGrid } from '@astrojs/starlight/components';
|
|
8
|
+
import Astro from '@astrojs/react';
|
|
9
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
8
10
|
import Link from '@components/link.astro';
|
|
9
11
|
import RunGenerator from '@components/run-generator.astro';
|
|
10
12
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
@@ -144,15 +146,42 @@ const result = await entity.query.primary({ id: '123' }).go();
|
|
|
144
146
|
When running in AWS, `resolveTableName()` fetches the table name from AWS AppConfig using the `RUNTIME_CONFIG_APP_ID` environment variable. Projects built with this plugin (tRPC APIs, Smithy APIs, agents, MCP servers) already have this variable configured automatically. For other TypeScript projects, ensure `RUNTIME_CONFIG_APP_ID` is set in the runtime environment with the AppConfig application ID provisioned by your infrastructure. For more information, see the <Link path="guides/runtime-config">Runtime Configuration guide</Link>.
|
|
145
147
|
:::
|
|
146
148
|
|
|
147
|
-
### Connection Generators
|
|
148
|
-
|
|
149
|
-
For specific project types, use the `connection` generator to automatically wire up local development dependencies so DynamoDB Local starts automatically alongside your project:
|
|
150
|
-
|
|
151
|
-
- <Link path="guides/connection/trpc-dynamodb">tRPC API → DynamoDB</Link>
|
|
152
|
-
- <Link path="guides/connection/smithy-dynamodb">Smithy API → DynamoDB</Link>
|
|
153
|
-
- <Link path="guides/connection/ts-agent-dynamodb">TypeScript Agent → DynamoDB</Link>
|
|
154
|
-
- <Link path="guides/connection/ts-mcp-server-dynamodb">MCP Server → DynamoDB</Link>
|
|
155
|
-
|
|
156
149
|
## Deploying your Table
|
|
157
150
|
|
|
158
151
|
<Snippet name="dynamodb/deploying-table" parentHeading="Deploying your Table" />
|
|
152
|
+
|
|
153
|
+
## Connections
|
|
154
|
+
|
|
155
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
156
|
+
|
|
157
|
+
<CardGrid>
|
|
158
|
+
<ConnectionCard
|
|
159
|
+
title="tRPC API to TypeScript DynamoDB"
|
|
160
|
+
description="Connect a tRPC API to a DynamoDB table"
|
|
161
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-dynamodb`}
|
|
162
|
+
source="trpc"
|
|
163
|
+
target="dynamodb"
|
|
164
|
+
/>
|
|
165
|
+
<ConnectionCard
|
|
166
|
+
title="Smithy API to TypeScript DynamoDB"
|
|
167
|
+
description="Connect a Smithy API to a DynamoDB table"
|
|
168
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-dynamodb`}
|
|
169
|
+
source="smithy"
|
|
170
|
+
target="dynamodb"
|
|
171
|
+
/>
|
|
172
|
+
<ConnectionCard
|
|
173
|
+
title="TypeScript Agent to TypeScript DynamoDB"
|
|
174
|
+
description="Connect a TypeScript Agent to a DynamoDB table"
|
|
175
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-dynamodb`}
|
|
176
|
+
source="strands"
|
|
177
|
+
sourceBadge="typescript"
|
|
178
|
+
target="dynamodb"
|
|
179
|
+
/>
|
|
180
|
+
<ConnectionCard
|
|
181
|
+
title="MCP Server to TypeScript DynamoDB"
|
|
182
|
+
description="Connect a TypeScript MCP Server to a DynamoDB table"
|
|
183
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-dynamodb`}
|
|
184
|
+
source="mcp"
|
|
185
|
+
target="dynamodb"
|
|
186
|
+
/>
|
|
187
|
+
</CardGrid>
|
|
@@ -4,7 +4,9 @@ description: Generate a TypeScript Model Context Protocol (MCP) server for provi
|
|
|
4
4
|
generator: ts#mcp-server
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import { FileTree, CardGrid } from '@astrojs/starlight/components';
|
|
8
|
+
import Astro from '@astrojs/react';
|
|
9
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
8
10
|
import RunGenerator from '@components/run-generator.astro';
|
|
9
11
|
import NxCommands from '@components/nx-commands.astro';
|
|
10
12
|
import Link from '@components/link.astro';
|
|
@@ -171,3 +173,47 @@ A `docker` target is also generated which prepares the docker context for all MC
|
|
|
171
173
|
|
|
172
174
|
<Snippet name="mcp/observability" parentHeading="Observability" />
|
|
173
175
|
</OptionFilter>
|
|
176
|
+
|
|
177
|
+
## Connections
|
|
178
|
+
|
|
179
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
180
|
+
|
|
181
|
+
<CardGrid>
|
|
182
|
+
<ConnectionCard
|
|
183
|
+
title="TypeScript Agent to MCP"
|
|
184
|
+
description="Connect a TypeScript Agent to an MCP server"
|
|
185
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-mcp`}
|
|
186
|
+
source="strands"
|
|
187
|
+
sourceBadge="typescript"
|
|
188
|
+
target="mcp"
|
|
189
|
+
/>
|
|
190
|
+
<ConnectionCard
|
|
191
|
+
title="Python Agent to MCP"
|
|
192
|
+
description="Connect a Python Agent to an MCP server"
|
|
193
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/py-agent-mcp`}
|
|
194
|
+
source="strands"
|
|
195
|
+
sourceBadge="python"
|
|
196
|
+
target="mcp"
|
|
197
|
+
/>
|
|
198
|
+
<ConnectionCard
|
|
199
|
+
title="MCP Server to Relational Database"
|
|
200
|
+
description="Connect a TypeScript MCP Server to an Aurora relational database"
|
|
201
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-rdb`}
|
|
202
|
+
source="mcp"
|
|
203
|
+
target="aurora"
|
|
204
|
+
/>
|
|
205
|
+
<ConnectionCard
|
|
206
|
+
title="MCP Server to TypeScript DynamoDB"
|
|
207
|
+
description="Connect a TypeScript MCP Server to a DynamoDB table"
|
|
208
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-dynamodb`}
|
|
209
|
+
source="mcp"
|
|
210
|
+
target="dynamodb"
|
|
211
|
+
/>
|
|
212
|
+
<ConnectionCard
|
|
213
|
+
title="AgentCore Gateway to MCP Server"
|
|
214
|
+
description="Aggregate an MCP server behind an AgentCore Gateway"
|
|
215
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/agentcore-gateway-mcp`}
|
|
216
|
+
source="agentcore"
|
|
217
|
+
target="mcp"
|
|
218
|
+
/>
|
|
219
|
+
</CardGrid>
|
package/docs/guides/ts-rdb.mdx
CHANGED
|
@@ -4,7 +4,9 @@ description: Create a relational database project
|
|
|
4
4
|
generator: ts#rdb
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import { FileTree, CardGrid } from '@astrojs/starlight/components';
|
|
8
|
+
import Astro from '@astrojs/react';
|
|
9
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
8
10
|
import Link from '@components/link.astro';
|
|
9
11
|
import RunGenerator from '@components/run-generator.astro';
|
|
10
12
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
@@ -243,15 +245,6 @@ const users = await prisma.user.findMany({ orderBy: { id: 'asc' } });
|
|
|
243
245
|
|
|
244
246
|
The Prisma client exposes fully typed models derived from your `prisma/models/` schema, giving you end-to-end type safety from the database all the way through to your API response.
|
|
245
247
|
|
|
246
|
-
### Connection Generators
|
|
247
|
-
|
|
248
|
-
For specific project types, use the `connection` generator to automatically wire up the database — it handles imports, context injection, and local development dependencies:
|
|
249
|
-
|
|
250
|
-
- <Link path="guides/connection/trpc-rdb">tRPC API → Relational Database</Link>
|
|
251
|
-
- <Link path="guides/connection/smithy-rdb">Smithy API → Relational Database</Link>
|
|
252
|
-
- <Link path="guides/connection/ts-agent-rdb">TypeScript Agent → Relational Database</Link>
|
|
253
|
-
- <Link path="guides/connection/ts-mcp-server-rdb">MCP Server → Relational Database</Link>
|
|
254
|
-
|
|
255
248
|
## Deploying your Database
|
|
256
249
|
|
|
257
250
|
The relational database generator creates CDK or Terraform infrastructure based on your selected `iacProvider`.
|
|
@@ -805,3 +798,39 @@ Be cautious with tasks running longer than 15 minutes. If the MySQL client needs
|
|
|
805
798
|
For long-running tasks such as batch jobs or data migrations, call `getPrisma()` at the start of each unit of work rather than once for the entire operation. Because `getPrisma()` always creates a fresh client and fetches a new IAM token for MySQL, this ensures each connection authenticates with a valid token.
|
|
806
799
|
|
|
807
800
|
</OptionFilter>
|
|
801
|
+
|
|
802
|
+
## Connections
|
|
803
|
+
|
|
804
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
805
|
+
|
|
806
|
+
<CardGrid>
|
|
807
|
+
<ConnectionCard
|
|
808
|
+
title="tRPC API to Relational Database"
|
|
809
|
+
description="Connect a tRPC API to an Aurora relational database"
|
|
810
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/trpc-rdb`}
|
|
811
|
+
source="trpc"
|
|
812
|
+
target="aurora"
|
|
813
|
+
/>
|
|
814
|
+
<ConnectionCard
|
|
815
|
+
title="Smithy API to Relational Database"
|
|
816
|
+
description="Connect a Smithy API to an Aurora relational database"
|
|
817
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-rdb`}
|
|
818
|
+
source="smithy"
|
|
819
|
+
target="aurora"
|
|
820
|
+
/>
|
|
821
|
+
<ConnectionCard
|
|
822
|
+
title="TypeScript Agent to Relational Database"
|
|
823
|
+
description="Connect a TypeScript Agent to an Aurora relational database"
|
|
824
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-agent-rdb`}
|
|
825
|
+
source="strands"
|
|
826
|
+
sourceBadge="typescript"
|
|
827
|
+
target="aurora"
|
|
828
|
+
/>
|
|
829
|
+
<ConnectionCard
|
|
830
|
+
title="MCP Server to Relational Database"
|
|
831
|
+
description="Connect a TypeScript MCP Server to an Aurora relational database"
|
|
832
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/ts-mcp-server-rdb`}
|
|
833
|
+
source="mcp"
|
|
834
|
+
target="aurora"
|
|
835
|
+
/>
|
|
836
|
+
</CardGrid>
|
|
@@ -7,7 +7,9 @@ when:
|
|
|
7
7
|
infra: [rest-lambda]
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
10
|
+
import { FileTree, CardGrid } from '@astrojs/starlight/components';
|
|
11
|
+
import Astro from '@astrojs/react';
|
|
12
|
+
import ConnectionCard from '@components/connection-card.astro';
|
|
11
13
|
import Link from '@components/link.astro';
|
|
12
14
|
import RunGenerator from '@components/run-generator.astro';
|
|
13
15
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
@@ -401,6 +403,151 @@ export const MyOperation: MyOperationHandler<ServiceContext> = async (input) =>
|
|
|
401
403
|
};
|
|
402
404
|
```
|
|
403
405
|
|
|
406
|
+
### Accessing the Calling User
|
|
407
|
+
|
|
408
|
+
When your API is protected by authentication, your operations often need to know who is calling. The recommended approach is to resolve the caller's identity once in the handler and pass it through the [service context](#service-context) for consumption by specific operations.
|
|
409
|
+
|
|
410
|
+
We'll model the unauthorized case as a Smithy error so it serializes to a proper `403` response. Add it to your model, for example in `model/src/operations/errors.smithy`, and reference it on any operation that requires identity:
|
|
411
|
+
|
|
412
|
+
```smithy
|
|
413
|
+
$version: "2.0"
|
|
414
|
+
|
|
415
|
+
namespace your.namespace
|
|
416
|
+
|
|
417
|
+
/// Thrown when the calling user cannot be determined
|
|
418
|
+
@error("client")
|
|
419
|
+
@httpError(403)
|
|
420
|
+
structure UnauthorizedError {
|
|
421
|
+
@required
|
|
422
|
+
message: String
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
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:
|
|
427
|
+
|
|
428
|
+
```ts {4-7,15} ins={4-7,15}
|
|
429
|
+
import { Logger } from '@aws-lambda-powertools/logger';
|
|
430
|
+
import { Metrics } from '@aws-lambda-powertools/metrics';
|
|
431
|
+
import { Tracer } from '@aws-lambda-powertools/tracer';
|
|
432
|
+
|
|
433
|
+
export interface Identity {
|
|
434
|
+
sub: string;
|
|
435
|
+
username: string;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Context provided to all operations.
|
|
440
|
+
*/
|
|
441
|
+
export interface ServiceContext {
|
|
442
|
+
tracer: Tracer;
|
|
443
|
+
logger: Logger;
|
|
444
|
+
metrics: Metrics;
|
|
445
|
+
getIdentity: () => Promise<Identity>;
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
Next, write the resolver in `src/identity.ts`. It throws `UnauthorizedError` when the caller cannot be determined. The implementation depends on your selected `auth` method:
|
|
450
|
+
|
|
451
|
+
<OptionFilter when={{ auth: 'iam' }} description="Identity resolution for IAM-authenticated APIs">
|
|
452
|
+
For `IAM` authentication, we look up the caller in Cognito using the sub extracted from the API Gateway event:
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
import { CognitoIdentityProvider } from '@aws-sdk/client-cognito-identity-provider';
|
|
456
|
+
import type { APIGatewayProxyEvent } from 'aws-lambda';
|
|
457
|
+
import { Identity } from './context.js';
|
|
458
|
+
import { UnauthorizedError } from './generated/ssdk/index.js';
|
|
459
|
+
|
|
460
|
+
const cognito = new CognitoIdentityProvider();
|
|
461
|
+
|
|
462
|
+
export const getIdentity = async (
|
|
463
|
+
event: APIGatewayProxyEvent,
|
|
464
|
+
): Promise<Identity> => {
|
|
465
|
+
const cognitoAuthenticationProvider =
|
|
466
|
+
event.requestContext?.identity?.cognitoAuthenticationProvider;
|
|
467
|
+
|
|
468
|
+
let sub: string | undefined = undefined;
|
|
469
|
+
if (cognitoAuthenticationProvider) {
|
|
470
|
+
const providerParts = cognitoAuthenticationProvider.split(':');
|
|
471
|
+
sub = providerParts[providerParts.length - 1];
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (!sub) {
|
|
475
|
+
throw new UnauthorizedError({ message: 'Unable to determine calling user' });
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const { Users } = await cognito.listUsers({
|
|
479
|
+
// Assumes user pool id is configured in lambda environment
|
|
480
|
+
UserPoolId: process.env.USER_POOL_ID!,
|
|
481
|
+
Limit: 1,
|
|
482
|
+
Filter: `sub="${sub}"`,
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
if (!Users || Users.length !== 1) {
|
|
486
|
+
throw new UnauthorizedError({ message: `No user found with subjectId ${sub}` });
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return { sub, username: Users[0].Username! };
|
|
490
|
+
};
|
|
491
|
+
```
|
|
492
|
+
</OptionFilter>
|
|
493
|
+
|
|
494
|
+
<OptionFilter when={{ auth: 'cognito' }} description="Identity resolution for Cognito-authenticated APIs">
|
|
495
|
+
With `auth: 'cognito'`, the API Gateway Cognito User Pools authorizer verifies the JWT that the caller supplies in the `Authorization` header and places the verified claims on the event at `event.requestContext.authorizer.claims`:
|
|
496
|
+
|
|
497
|
+
```ts
|
|
498
|
+
import type { APIGatewayProxyEvent } from 'aws-lambda';
|
|
499
|
+
import { Identity } from './context.js';
|
|
500
|
+
import { UnauthorizedError } from './generated/ssdk/index.js';
|
|
501
|
+
|
|
502
|
+
export const getIdentity = async (
|
|
503
|
+
event: APIGatewayProxyEvent,
|
|
504
|
+
): Promise<Identity> => {
|
|
505
|
+
const claims = event.requestContext?.authorizer?.claims as
|
|
506
|
+
| Record<string, string>
|
|
507
|
+
| undefined;
|
|
508
|
+
|
|
509
|
+
const sub = claims?.sub;
|
|
510
|
+
const username = claims?.username;
|
|
511
|
+
|
|
512
|
+
if (!sub || !username) {
|
|
513
|
+
throw new UnauthorizedError({ message: 'Unable to determine calling user' });
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return { sub, username };
|
|
517
|
+
};
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
:::tip[No token verification required]
|
|
521
|
+
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.
|
|
522
|
+
:::
|
|
523
|
+
</OptionFilter>
|
|
524
|
+
|
|
525
|
+
Then wire the resolver into the context in `src/handler.ts`:
|
|
526
|
+
|
|
527
|
+
```ts {2,8} ins={2,8}
|
|
528
|
+
import { Service } from './service.js';
|
|
529
|
+
import { getIdentity } from './identity.js';
|
|
530
|
+
// ...
|
|
531
|
+
const httpResponse = await serviceHandler.handle(httpRequest, {
|
|
532
|
+
tracer,
|
|
533
|
+
logger,
|
|
534
|
+
metrics,
|
|
535
|
+
getIdentity: () => getIdentity(event),
|
|
536
|
+
});
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
We can now use the resolved identity in an operation, for example in `src/operations/echo.ts`:
|
|
540
|
+
|
|
541
|
+
```ts
|
|
542
|
+
import { ServiceContext } from '../context.js';
|
|
543
|
+
import { Echo as EchoOperation } from '../generated/ssdk/index.js';
|
|
544
|
+
|
|
545
|
+
export const Echo: EchoOperation<ServiceContext> = async (input, ctx) => {
|
|
546
|
+
const identity = await ctx.getIdentity();
|
|
547
|
+
return { message: `${identity.username} says ${input.message}` };
|
|
548
|
+
};
|
|
549
|
+
```
|
|
550
|
+
|
|
404
551
|
## Building and Code Generation
|
|
405
552
|
|
|
406
553
|
The Smithy model project uses [Docker](https://www.docker.com/) to build the Smithy artifacts and generate the TypeScript Server SDK:
|
|
@@ -662,3 +809,31 @@ resource "aws_iam_role_policy_attachment" "api_invoke_access" {
|
|
|
662
809
|
## Invoking your Smithy API
|
|
663
810
|
|
|
664
811
|
To invoke your API from a React website, you can use the <Link path="guides/connection/react-smithy">`connection`</Link> generator, which provides type-safe client generation from your Smithy model.
|
|
812
|
+
|
|
813
|
+
## Connections
|
|
814
|
+
|
|
815
|
+
Use the <Link path="guides/connection">`connection`</Link> generator to integrate this project with others in your workspace. The following connections involve this project:
|
|
816
|
+
|
|
817
|
+
<CardGrid>
|
|
818
|
+
<ConnectionCard
|
|
819
|
+
title="React to Smithy API"
|
|
820
|
+
description="Call a Smithy API from a React website"
|
|
821
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/react-smithy`}
|
|
822
|
+
source="react"
|
|
823
|
+
target="smithy"
|
|
824
|
+
/>
|
|
825
|
+
<ConnectionCard
|
|
826
|
+
title="Smithy API to Relational Database"
|
|
827
|
+
description="Connect a Smithy API to an Aurora relational database"
|
|
828
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-rdb`}
|
|
829
|
+
source="smithy"
|
|
830
|
+
target="aurora"
|
|
831
|
+
/>
|
|
832
|
+
<ConnectionCard
|
|
833
|
+
title="Smithy API to TypeScript DynamoDB"
|
|
834
|
+
description="Connect a Smithy API to a DynamoDB table"
|
|
835
|
+
href={`/nx-plugin-for-aws/${Astro.currentLocale || 'en'}/guides/connection/smithy-dynamodb`}
|
|
836
|
+
source="smithy"
|
|
837
|
+
target="dynamodb"
|
|
838
|
+
/>
|
|
839
|
+
</CardGrid>
|
package/package.json
CHANGED
package/src/py/agent/schema.json
CHANGED