@aws/nx-plugin 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/package.json +1 -1
  2. package/src/api-connection/generator.js +0 -2
  3. package/src/api-connection/generator.js.map +1 -1
  4. package/src/api-connection/schema.d.ts +0 -1
  5. package/src/api-connection/schema.json +0 -7
  6. package/src/cloudscape-website/app/generator.js +1 -0
  7. package/src/cloudscape-website/app/generator.js.map +1 -1
  8. package/src/infra/app/__snapshots__/generator.spec.ts.snap +9 -0
  9. package/src/infra/app/generator.js +1 -0
  10. package/src/infra/app/generator.js.map +1 -1
  11. package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +31 -30
  12. package/src/py/fast-api/generator.js +3 -0
  13. package/src/py/fast-api/generator.js.map +1 -1
  14. package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +68 -1
  15. package/src/py/fast-api/react/files/website/components/__apiNameClassName__Provider.tsx.template +27 -1
  16. package/src/py/fast-api/react/generator.js +7 -17
  17. package/src/py/fast-api/react/generator.js.map +1 -1
  18. package/src/py/fast-api/react/schema.d.ts +0 -1
  19. package/src/py/fast-api/react/schema.json +0 -7
  20. package/src/py/fast-api/schema.d.ts +1 -0
  21. package/src/py/fast-api/schema.json +9 -1
  22. package/src/py/project/generator.js +1 -0
  23. package/src/py/project/generator.js.map +1 -1
  24. package/src/py/project/schema.json +7 -2
  25. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +680 -84
  26. package/src/trpc/backend/files/backend/src/client/index.ts.template +22 -2
  27. package/src/trpc/backend/files/backend/src/middleware/index.ts.template +2 -3
  28. package/src/trpc/backend/files/backend/src/router.ts.template +2 -3
  29. package/src/trpc/backend/generator.js +21 -5
  30. package/src/trpc/backend/generator.js.map +1 -1
  31. package/src/trpc/backend/schema.d.ts +2 -1
  32. package/src/trpc/backend/schema.json +10 -2
  33. package/src/trpc/react/__snapshots__/generator.spec.ts.snap +186 -73
  34. package/src/trpc/react/files/src/components/__apiNameClassName__ClientProvider.tsx.template +54 -0
  35. package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +2 -2
  36. package/src/trpc/react/generator.js +13 -69
  37. package/src/trpc/react/generator.js.map +1 -1
  38. package/src/trpc/react/schema.d.ts +0 -1
  39. package/src/trpc/react/schema.json +0 -7
  40. package/src/ts/lib/__snapshots__/generator.spec.ts.snap +9 -0
  41. package/src/ts/lib/generator.js +1 -0
  42. package/src/ts/lib/generator.js.map +1 -1
  43. package/src/ts/lib/schema.json +7 -2
  44. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +3 -0
  45. package/src/ts/mcp-server/generator.js +1 -0
  46. package/src/ts/mcp-server/generator.js.map +1 -1
  47. package/src/ts/mcp-server/schema.json +5 -0
  48. package/src/utils/api-constructs/api-constructs.d.ts +1 -0
  49. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  50. package/src/utils/api-constructs/files/app/apis/http/__apiNameKebabCase__.ts.template +53 -2
  51. package/src/utils/api-constructs/files/app/apis/rest/__apiNameKebabCase__.ts.template +57 -2
  52. package/src/utils/api-constructs/files/core/api/http/http-api.ts.template +1 -15
  53. package/src/utils/api-constructs/files/core/api/rest/rest-api.ts.template +0 -14
  54. package/src/utils/nx.d.ts +4 -0
  55. package/src/utils/nx.js +9 -1
  56. package/src/utils/nx.js.map +1 -1
  57. package/src/api-connection/README.md +0 -0
  58. package/src/cloudscape-website/app/README.md +0 -289
  59. package/src/cloudscape-website/cognito-auth/README.md +0 -193
  60. package/src/infra/app/README.md +0 -200
  61. package/src/license/README.md +0 -290
  62. package/src/trpc/backend/README.md +0 -571
  63. package/src/trpc/backend/files/backend/src/client/sigv4.ts.template +0 -9
  64. package/src/trpc/react/README.md +0 -330
  65. package/src/trpc/react/files/src/components/TrpcClients/TrpcApis.tsx.template +0 -1
  66. package/src/trpc/react/files/src/components/TrpcClients/TrpcClientProviders.tsx.template +0 -10
  67. package/src/trpc/react/files/src/components/TrpcClients/TrpcProvider.tsx.template +0 -55
  68. package/src/trpc/react/files/src/components/TrpcClients/index.tsx.template +0 -5
@@ -1,571 +0,0 @@
1
- # tRPC Backend Generator
2
-
3
- ## Overview
4
-
5
- This generator creates a new tRPC backend application with AWS CDK infrastructure setup. The generated backend uses AWS Lambda for serverless deployment and includes schema validation using Zod. The codebase is structured using ES Modules (ESM) for modern JavaScript module system compatibility. It sets up a complete type-safe API using tRPC with AWS Lambda integration, AWS X-Ray tracing, and AWS Lambda Powertools for observability.
6
-
7
- ## Usage
8
-
9
- You can generate a new tRPC backend in two ways:
10
-
11
- ### 1. Using VSCode IDE
12
-
13
- First, install the NX Console extension for VSCode:
14
-
15
- 1. Open VSCode
16
- 2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
17
- 3. Search for "Nx Console"
18
- 4. Install [Nx Console](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
19
-
20
- Then generate your API:
21
-
22
- 1. Open the NX Console in VSCode
23
- 2. Click on "Generate"
24
- 3. Search for "trpc#backend"
25
- 4. Fill in the required parameters in the form
26
- 5. Click "Run"
27
-
28
- ### 2. Using CLI
29
-
30
- Generate the API:
31
-
32
- ```bash
33
- nx g @aws/nx-plugin:trpc#backend my-api --directory=apps/api
34
- ```
35
-
36
- You can also perform a dry-run to see what files would be generated without actually creating them:
37
-
38
- ```bash
39
- nx g @aws/nx-plugin:trpc#backend my-api --directory=apps/api --dry-run
40
- ```
41
-
42
- Both methods will create a new tRPC backend API in the specified directory with all the necessary configuration and infrastructure code.
43
-
44
- ## Input Parameters
45
-
46
- | Parameter | Type | Default | Description |
47
- | -------------- | ------ | ---------- | ---------------------------------------------------------------------------- |
48
- | apiName\* | string | - | The name of the API (required). Used to generate class names and file paths. |
49
- | directory | string | "packages" | The directory to store the application in. |
50
- | unitTestRunner | string | "vitest" | Test runner for unit tests. Options: jest, vitest, none |
51
-
52
- \*Required parameter
53
-
54
- ## Expected Output
55
-
56
- The generator creates three main components:
57
-
58
- ### 1. Backend API Code
59
-
60
- ```
61
- <directory>/<api-name>/backend/
62
- ├── src/
63
- │ ├── index.ts # Backend entry point with tRPC setup
64
- │ └── lambdas/ # Lambda function handlers
65
- │ ├── index.ts # Lambda exports
66
- │ ├── router.ts # tRPC router definition
67
- │ └── middleware.ts # Middleware plugins
68
- ├── tsconfig.json # TypeScript configuration
69
- └── project.json # Project configuration and build targets
70
- ```
71
-
72
- ### 2. Schema Code
73
-
74
- ```
75
- <directory>/<api-name>/schema/
76
- ├── src/
77
- │ └── index.ts # Shared schema definitions using Zod
78
- ├── tsconfig.json # TypeScript configuration
79
- └── project.json # Project configuration and build targets
80
- ```
81
-
82
- ### 3. Infrastructure Code
83
-
84
- ```
85
- common/
86
- | └── constructs/
87
- | | └── src/
88
- | │ ├── app/ # Infrastructure specific to this API
89
- | │ │ └── index.ts
90
- | │ │ └── trpc-apis
91
- | │ │ └── index.ts
92
- | │ │ └── <name>.ts # Application specific cdk construct i.e: MyApi
93
- | │ ├── core/ # Infrastructure specific to this API
94
- | │ │ └── index.ts
95
- | │ │ └── trpc-api.ts # Generic Trpc API construct
96
- | │ └── index.ts # Exports for all constructs
97
- | └── types/
98
- | └── src/
99
- | └── runtime-config.ts # Updates IRuntimeConfig to add trpcApis
100
- ├── tsconfig.json # TypeScript configuration
101
- └── project.json # Project configuration and build targets
102
- ```
103
-
104
- Additionally, it:
105
-
106
- 1. Configures build settings for production deployment
107
- 2. Installs required dependencies:
108
- - @trpc/server
109
- - zod
110
- - aws-xray-sdk-core
111
- - aws-cdk-lib
112
- - constructs
113
- - @aws-lambda-powertools/logger
114
- - @aws-lambda-powertools/metrics
115
- - @aws-lambda-powertools/tracer
116
-
117
- ## Router and Middleware Setup
118
-
119
- The generator creates a powerful tRPC router setup with integrated middleware for observability and error handling.
120
-
121
- ### Router Configuration
122
-
123
- The router is configured in `router.ts` with AWS Lambda integration:
124
-
125
- ```typescript
126
- import { initTRPC } from '@trpc/server';
127
- import { awsLambdaRequestHandler } from '@trpc/server/adapters/aws-lambda';
128
- import { createErrorPlugin, createLoggerPlugin, createMetricsPlugin, createTracerPlugin, IMiddlewareContext } from './middleware.js';
129
-
130
- // Initialize tRPC with context type
131
- export type Context = IMiddlewareContext;
132
- const t = initTRPC.context<Context>().create();
133
-
134
- // Create base router and procedure which automatically instruments all middleware
135
- export const router = t.router;
136
- export const publicProcedure = t.procedure.unstable_concat(createLoggerPlugin().loggerPlugin).unstable_concat(createTracerPlugin().tracerPlugin).unstable_concat(createMetricsPlugin().metricsPlugin).unstable_concat(createErrorPlugin().errorPlugin);
137
-
138
- // Define your procedures here
139
- const appRouter = router({
140
- echo: publicProcedure
141
- .input(z.string())
142
- .output(EchoSchema)
143
- .query((opts) => ({ result: opts.input })),
144
- });
145
-
146
- // Create Lambda handler
147
- export const handler = awsLambdaRequestHandler({
148
- router: appRouter,
149
- });
150
-
151
- // Import this type in the frontend when setting up your integration
152
- export type AppRouter = typeof appRouter;
153
- ```
154
-
155
- ### Middleware and Context
156
-
157
- The generator includes four powerful middleware plugins whcih are automatically instrumented:
158
-
159
- 1. **Logger Plugin**
160
-
161
- - Automatically logs procedure execution
162
- - Captures errors with detailed context
163
- - Uses structured logging format
164
-
165
- 2. **Metrics Plugin**
166
-
167
- - Captures cold start metrics
168
- - Tracks request counts
169
- - Records success/error metrics
170
- - Automatically publishes metrics to CloudWatch
171
-
172
- 3. **Tracer Plugin**
173
-
174
- - Integrates with AWS X-Ray
175
- - Creates subsegments for each procedure
176
- - Annotates cold starts
177
- - Adds error metadata automatically
178
-
179
- 4. **Error Plugin**
180
- - Standardizes error handling
181
- - Converts internal errors to tRPC errors
182
- - Maintains error context for debugging
183
-
184
- ### Using Context in Procedures
185
-
186
- You can access the context in your procedures to utilize the observability tools:
187
-
188
- ```typescript
189
- const appRouter = router({
190
- getData: publicProcedure.input(z.string()).query(async (opts) => {
191
- // Access logger
192
- opts.ctx.logger.info('Processing getData request', {
193
- input: opts.input,
194
- });
195
-
196
- // Add custom metrics
197
- opts.ctx.metrics.addMetric('getData.calls', MetricUnit.Count, 1);
198
-
199
- // Use tracer for subsegments
200
- return opts.ctx.tracer.captureMethod('getData.process', async () => {
201
- // Your business logic here
202
- return { data: 'result' };
203
- });
204
- }),
205
- });
206
- ```
207
-
208
- ## Infrastructure Architecture
209
-
210
- ```mermaid
211
- graph TD
212
- subgraph AWS Cloud
213
- APIGW[API Gateway] --> Lambda[Lambda Function]
214
- Lambda --> XRay[X-Ray Tracing]
215
- Lambda --> CW[CloudWatch Logs]
216
- Lambda --> Metrics[CloudWatch Metrics]
217
- end
218
- ```
219
-
220
- The infrastructure stack deploys:
221
-
222
- 1. **API Gateway**
223
-
224
- - HTTP API endpoint
225
- - Request validation
226
- - CORS configuration
227
-
228
- 2. **Lambda Functions**
229
-
230
- - Serverless compute
231
- - Auto-scaling
232
- - Pay-per-use pricing
233
-
234
- 3. **Observability**
235
- - X-Ray distributed tracing
236
- - CloudWatch Logs integration
237
- - CloudWatch Metrics via Lambda Powertools
238
- - Structured logging with Lambda Powertools
239
-
240
- ## Using the Generated CDK Constructs
241
-
242
- After generating your tRPC backend, you'll find a CDK construct in the `common/constructs` directory. Here's how to use it in your infrastructure:
243
-
244
- ### Basic Usage
245
-
246
- ```typescript
247
- import { Stack } from 'aws-cdk-lib';
248
- import { MyApi } from ':my-org/common-constructs';
249
- import { HttpNoneAuthorizer } from '@aws-cdk-lib/aws-apigatewayv2-authorizers';
250
-
251
- export class MyStack extends Stack {
252
- constructor(scope: App, id: string) {
253
- super(scope, id);
254
-
255
- // Create the API with no authentication
256
- const api = new MyApi(this, 'MyApi');
257
- }
258
- }
259
- ```
260
-
261
- ### With Cognito Authentication
262
-
263
- ```typescript
264
- import * as cdk from 'aws-cdk-lib';
265
- import { Construct } from 'constructs';
266
- import { UserIdentity, MyApi } from ':my-org/common-constructs';
267
- import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
268
-
269
- export class ApplicationStack extends cdk.Stack {
270
- constructor(scope: Construct, id: string, props?: cdk.StackProps) {
271
- super(scope, id, props);
272
-
273
- const identity = new UserIdentity(this, 'UserIdentity');
274
- const myapi = new MyApi(this, 'MyApi');
275
- myapi.grantInvokeAccess(identity.identityPool.authenticatedRole);
276
- }
277
- }
278
- ```
279
-
280
- ### Granting Access to Other Services
281
-
282
- ```typescript
283
- import { Stack } from 'aws-cdk-lib';
284
- import { MyApi } from ':my-org/common-constructs';
285
- import { Role } from '@aws-cdk-lib/aws-iam';
286
-
287
- export class MyStack extends Stack {
288
- constructor(scope: App, id: string) {
289
- super(scope, id);
290
-
291
- const api = new MyApi(this, 'MyApi');
292
-
293
- // Grant access to other roles if needed
294
- const consumerRole = new Role(this, 'ConsumerRole', {
295
- // ... role configuration
296
- });
297
-
298
- api.grantInvokeAccess(consumerRole);
299
- }
300
- }
301
- ```
302
-
303
- The API URL will be automatically registered in the RuntimeConfig system and can be accessed in your frontend application.
304
-
305
- ### Updating CORS configuration
306
-
307
- To update the CORS configuration, you can do this directly by modifying the generated APi construct located in `common/constructs/src/app/trpc-apis`.
308
-
309
- For example:
310
-
311
- ```typescript
312
- import { Construct } from 'constructs';
313
- import * as url from 'url';
314
- import { TrpcApi } from '../../core/trpc-api.js';
315
- import { HttpIamAuthorizer } from 'aws-cdk-lib/aws-apigatewayv2-authorizers';
316
-
317
- export class MyApi extends TrpcApi {
318
- constructor(scope: Construct, id: string) {
319
- super(scope, id, {
320
- defaultAuthorizer: new HttpIamAuthorizer(),
321
- handlerFilePath: url.fileURLToPath(new URL('../../../../../../packages/my-api/backend/src/lambdas/router.ts', import.meta.url)),
322
- allowedOrigins: ['http://localhost:4200/'], // Allow CORS from local vite dev server
323
- });
324
- }
325
- }
326
- ```
327
-
328
- ## Schema Code and Zod
329
-
330
- The generator creates a separate schema package that uses [Zod](https://zod.dev), a TypeScript-first schema declaration and validation library. This package can be shared between your backend and frontend code to ensure type safety across your entire application.
331
-
332
- ### Introduction to Zod
333
-
334
- Zod is a schema declaration and validation library designed specifically for TypeScript. It allows you to:
335
-
336
- - Define schemas with a fluent API
337
- - Automatically infer TypeScript types from schemas
338
- - Validate data at runtime
339
- - Create complex nested schemas
340
- - Transform data during validation
341
-
342
- For complete documentation, visit the [Zod documentation](https://zod.dev).
343
-
344
- ### Defining Schemas
345
-
346
- The generator creates a basic schema structure that you can extend:
347
-
348
- ```typescript
349
- import { z } from 'zod';
350
-
351
- // Basic object schema
352
- export const UserSchema = z.object({
353
- id: z.string().uuid(),
354
- email: z.string().email(),
355
- name: z.string().min(2),
356
- age: z.number().min(0).optional(),
357
- });
358
-
359
- // Infer the TypeScript type
360
- export type User = z.infer<typeof UserSchema>;
361
-
362
- // Input schema for creating a user
363
- export const CreateUserSchema = UserSchema.omit({ id: true });
364
-
365
- // Input schema for updating a user
366
- export const UpdateUserSchema = CreateUserSchema.partial();
367
-
368
- // Response schema for a list of users
369
- export const UserListSchema = z.array(UserSchema);
370
- ```
371
-
372
- ### Common Schema Patterns
373
-
374
- #### Nested Objects
375
-
376
- ```typescript
377
- import { z } from 'zod';
378
-
379
- export const AddressSchema = z.object({
380
- street: z.string(),
381
- city: z.string(),
382
- country: z.string(),
383
- postalCode: z.string(),
384
- });
385
-
386
- export const CustomerSchema = z.object({
387
- id: z.string().uuid(),
388
- name: z.string(),
389
- address: AddressSchema,
390
- shippingAddresses: z.array(AddressSchema),
391
- });
392
- ```
393
-
394
- #### Enums and Unions
395
-
396
- ```typescript
397
- import { z } from 'zod';
398
-
399
- export const OrderStatusSchema = z.enum(['pending', 'processing', 'shipped', 'delivered']);
400
-
401
- export const PaymentMethodSchema = z.union([z.object({ type: z.literal('credit_card'), cardNumber: z.string() }), z.object({ type: z.literal('paypal'), email: z.string().email() })]);
402
-
403
- export const OrderSchema = z.object({
404
- id: z.string().uuid(),
405
- status: OrderStatusSchema,
406
- payment: PaymentMethodSchema,
407
- });
408
- ```
409
-
410
- #### Request/Response Schemas
411
-
412
- ```typescript
413
- import { z } from 'zod';
414
-
415
- // Pagination parameters
416
- export const PaginationSchema = z.object({
417
- page: z.number().min(1),
418
- limit: z.number().min(1).max(100),
419
- });
420
-
421
- // Query parameters
422
- export const SearchParamsSchema = z.object({
423
- query: z.string().min(1),
424
- filters: z.record(z.string()).optional(),
425
- });
426
-
427
- // API Response wrapper
428
- export const ApiResponseSchema = <T extends z.ZodType>(dataSchema: T) =>
429
- z.object({
430
- success: z.boolean(),
431
- data: dataSchema,
432
- error: z.string().optional(),
433
- metadata: z.record(z.unknown()).optional(),
434
- });
435
-
436
- // Usage example
437
- export const GetUsersResponseSchema = ApiResponseSchema(
438
- z.object({
439
- users: z.array(UserSchema),
440
- total: z.number(),
441
- })
442
- );
443
- ```
444
-
445
- ### Using Schemas with tRPC
446
-
447
- Your schemas can be used directly in your tRPC procedures for input validation and type safety:
448
-
449
- ```typescript
450
- import { router, publicProcedure } from './router';
451
- import { UserSchema, CreateUserSchema, UpdateUserSchema, SearchParamsSchema } from ':my-org/schema';
452
-
453
- export const userRouter = router({
454
- // Create user with input validation
455
- create: publicProcedure
456
- .input(CreateUserSchema)
457
- .output(UserSchema)
458
- .mutation(async (opts) => {
459
- // Input is fully typed and validated
460
- const userData = opts.input;
461
- // ... create user logic
462
- }),
463
-
464
- // Search users with pagination
465
- search: publicProcedure
466
- .input(SearchParamsSchema.merge(PaginationSchema))
467
- .output(GetUsersResponseSchema)
468
- .query(async (opts) => {
469
- const { query, filters, page, limit } = opts.input;
470
- // ... search logic
471
- }),
472
-
473
- // Update user with partial data
474
- update: publicProcedure
475
- .input(
476
- z.object({
477
- id: z.string().uuid(),
478
- data: UpdateUserSchema,
479
- })
480
- )
481
- .output(UserSchema)
482
- .mutation(async (opts) => {
483
- const { id, data } = opts.input;
484
- // ... update logic
485
- }),
486
- });
487
- ```
488
-
489
- ### Schema Best Practices
490
-
491
- 1. **Keep Schemas Centralized**: Store all schemas in the schema package to ensure they're easily shared between frontend and backend.
492
-
493
- 2. **Use Type Inference**: Let TypeScript infer types from your schemas instead of maintaining separate type definitions:
494
-
495
- ```typescript
496
- // Do this:
497
- export const UserSchema = z.object({ ... });
498
- export type User = z.infer<typeof UserSchema>;
499
-
500
- // Don't do this:
501
- export interface User { ... }
502
- export const UserSchema: z.ZodType<User> = z.object({ ... });
503
- ```
504
-
505
- 3. **Compose Schemas**: Build complex schemas by composing simpler ones:
506
-
507
- ```typescript
508
- const BaseUserSchema = z.object({
509
- email: z.string().email(),
510
- name: z.string(),
511
- });
512
-
513
- const AdminSchema = BaseUserSchema.extend({
514
- permissions: z.array(z.string()),
515
- });
516
- ```
517
-
518
- 4. **Version Your Schemas**: When making breaking changes, consider versioning your schemas:
519
-
520
- ```typescript
521
- export const UserSchemaV1 = z.object({ ... });
522
- export const UserSchemaV2 = UserSchemaV1.extend({ ... });
523
- ```
524
-
525
- 5. **Document Your Schemas**: Add JSDoc comments to explain complex validation rules:
526
- ```typescript
527
- export const ConfigSchema = z.object({
528
- /**
529
- * API key must be in format: prefix_<32 chars>
530
- * Example: myapp_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
531
- */
532
- apiKey: z.string().regex(/^[a-z]+_[a-f0-9]{32}$/),
533
- });
534
- ```
535
-
536
- ## Building the Application
537
-
538
- To create a production build:
539
-
540
- ```bash
541
- nx build @my-org/my-api
542
- ```
543
-
544
- All built code is located in the `dist` folder at the root of your workspace. For example:
545
-
546
- - Backend code: `dist/apps/api/my-api/backend`
547
- - Schema code: `dist/apps/api/my-api/schema`
548
-
549
- The production build:
550
-
551
- - Bundles Lambda functions for optimal cold start performance
552
- - Generates TypeScript declaration files
553
- - Creates source maps for debugging
554
- - Optimizes dependencies for AWS Lambda environment
555
-
556
- ## Troubleshooting
557
-
558
- ### `SyntaxError: Named export 'ListInferenceProfilesCommand' not found` or `TypeError: import_client_bedrock2.ListInferenceProfilesCommand is not a constructor`
559
-
560
- If you see this error in a Lambda function related to `@aws-sdk`, it usually means that you are trying to use an operation which does not exist at runtime. This usually occurs when you are using the `@aws-sdk` provided by the Node Runtime. To bundle the required `@aws-sdk`, you can simply specify it in your `NodeJsFunction` as follows:
561
-
562
- ```typescript
563
- new NodejsFunction(this, 'MyApiHandler', {
564
- ...,
565
- bundling: {
566
- bundleAwsSDK: true
567
- },
568
- });
569
- ```
570
-
571
- This will ensure that whichever `@aws-sdk` version you have installed locally will be the one that is used in the Lambda.
@@ -1,9 +0,0 @@
1
- import { AwsClient } from 'aws4fetch';
2
- import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
3
-
4
- const credentialProvider = fromNodeProviderChain();
5
-
6
- export const sigv4Fetch = (async (...args) => {
7
- const client = new AwsClient(await credentialProvider());
8
- return client.fetch(...args);
9
- }) satisfies AwsClient['fetch'];