@aws/nx-plugin-mcp 0.120.0 → 1.0.0-rc.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 (92) hide show
  1. package/bin/aws-nx-mcp.js +74 -41
  2. package/docs/guides/astro-docs.mdx +144 -0
  3. package/docs/guides/connection/py-agent-a2a.mdx +105 -0
  4. package/docs/guides/connection/py-agent-mcp.mdx +147 -0
  5. package/docs/guides/connection/react-agui.mdx +240 -0
  6. package/docs/guides/connection/react-fastapi.mdx +1476 -0
  7. package/docs/guides/connection/react-py-agent.mdx +198 -0
  8. package/docs/guides/connection/react-smithy.mdx +1355 -0
  9. package/docs/guides/connection/react-trpc.mdx +447 -0
  10. package/docs/guides/connection/react-ts-agent.mdx +198 -0
  11. package/docs/guides/connection/smithy-rdb.mdx +161 -0
  12. package/docs/guides/connection/trpc-rdb.mdx +127 -0
  13. package/docs/guides/connection/ts-agent-a2a.mdx +106 -0
  14. package/docs/guides/connection/ts-agent-mcp.mdx +144 -0
  15. package/docs/guides/connection/ts-agent-rdb.mdx +141 -0
  16. package/docs/guides/connection/ts-mcp-server-rdb.mdx +135 -0
  17. package/docs/guides/connection.mdx +126 -0
  18. package/docs/guides/docker-bundling.mdx +403 -0
  19. package/docs/guides/docs.mdx +21 -0
  20. package/docs/guides/fastapi.mdx +511 -0
  21. package/docs/guides/license.mdx +293 -0
  22. package/docs/guides/nx-generator.mdx +588 -0
  23. package/docs/guides/py-agent.mdx +483 -0
  24. package/docs/guides/py-api.mdx +22 -0
  25. package/docs/guides/py-mcp-server.mdx +161 -0
  26. package/docs/guides/python-lambda-function.mdx +207 -0
  27. package/docs/guides/python-project.mdx +228 -0
  28. package/docs/guides/react-website-auth.mdx +216 -0
  29. package/docs/guides/react-website.mdx +424 -0
  30. package/docs/guides/runtime-config.mdx +312 -0
  31. package/docs/guides/terraform-project.mdx +317 -0
  32. package/docs/guides/trpc.mdx +818 -0
  33. package/docs/guides/ts-agent.mdx +436 -0
  34. package/docs/guides/ts-api.mdx +28 -0
  35. package/docs/guides/ts-lambda-function.mdx +218 -0
  36. package/docs/guides/ts-mcp-server.mdx +169 -0
  37. package/docs/guides/ts-nx-plugin.mdx +159 -0
  38. package/docs/guides/ts-rdb.mdx +759 -0
  39. package/docs/guides/ts-smithy-api.mdx +663 -0
  40. package/docs/guides/typescript-infrastructure.mdx +408 -0
  41. package/docs/guides/typescript-project.mdx +312 -0
  42. package/docs/guides/website.mdx +21 -0
  43. package/docs/guides/workspace.mdx +181 -0
  44. package/docs/snippets/agent/architecture.mdx +72 -0
  45. package/docs/snippets/agent/bedrock-deployment.mdx +172 -0
  46. package/docs/snippets/agent/runtime-arn.mdx +64 -0
  47. package/docs/snippets/api/api-architecture.mdx +93 -0
  48. package/docs/snippets/api/api-choice-note.mdx +6 -0
  49. package/docs/snippets/api/cors-configuration-cdk-note.mdx +25 -0
  50. package/docs/snippets/api/cors-configuration-terraform-note.mdx +28 -0
  51. package/docs/snippets/api/shared-constructs.mdx +38 -0
  52. package/docs/snippets/api/type-safe-api-integrations.mdx +643 -0
  53. package/docs/snippets/api/waf-configuration.mdx +37 -0
  54. package/docs/snippets/connection/a2a-infrastructure.mdx +63 -0
  55. package/docs/snippets/connection/lambda-rdb-ssl-requirements.mdx +40 -0
  56. package/docs/snippets/connection/mcp-server-rdb-ssl-requirements.mdx +35 -0
  57. package/docs/snippets/connection/rdb-api-infrastructure.mdx +72 -0
  58. package/docs/snippets/connection/react-agent-infrastructure.mdx +61 -0
  59. package/docs/snippets/connection/strands-agent-rdb-ssl-requirements.mdx +35 -0
  60. package/docs/snippets/lambda-function/architecture.mdx +36 -0
  61. package/docs/snippets/lambda-function/deploying-your-function.mdx +118 -0
  62. package/docs/snippets/mcp/architecture.mdx +58 -0
  63. package/docs/snippets/mcp/assistant-docs.mdx +10 -0
  64. package/docs/snippets/mcp/bedrock-deployment.mdx +167 -0
  65. package/docs/snippets/mcp/config.mdx +13 -0
  66. package/docs/snippets/mcp/configuration-py.mdx +42 -0
  67. package/docs/snippets/mcp/configuration-ts.mdx +53 -0
  68. package/docs/snippets/mcp/observability.mdx +8 -0
  69. package/docs/snippets/mcp/shared-constructs.mdx +32 -0
  70. package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +602 -0
  71. package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +915 -0
  72. package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +161 -0
  73. package/docs/snippets/pdk-migration/example/04-deploy.mdx +229 -0
  74. package/docs/snippets/pdk-migration/faq/aws-arch.mdx +17 -0
  75. package/docs/snippets/pdk-migration/faq/cdk-graph.mdx +29 -0
  76. package/docs/snippets/pdk-migration/faq/infrastructure-python-java.mdx +19 -0
  77. package/docs/snippets/pdk-migration/faq/pdk-nag.mdx +15 -0
  78. package/docs/snippets/pdk-migration/faq/pipeline.mdx +15 -0
  79. package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +310 -0
  80. package/docs/snippets/pdk-migration/faq/use-of-projen.mdx +15 -0
  81. package/docs/snippets/prerequisites.mdx +20 -0
  82. package/docs/snippets/required-prerequisites.mdx +12 -0
  83. package/docs/snippets/shared-constructs.mdx +40 -0
  84. package/docs/snippets/tools/acurl.mdx +73 -0
  85. package/docs/snippets/ts-bundle.mdx +14 -0
  86. package/generators.json +47 -6
  87. package/package.json +1 -1
  88. package/src/py/api/schema.json +100 -0
  89. package/src/ts/api/schema.json +105 -0
  90. package/src/ts/docs/schema.json +70 -0
  91. package/src/ts/website/app/schema.json +97 -0
  92. package/src/ts/website/auth/schema.json +46 -0
@@ -0,0 +1,511 @@
1
+ ---
2
+ title: FastAPI
3
+ description: Reference documentation for FastAPI
4
+ generator: py#fast-api
5
+ when:
6
+ framework: [fastapi]
7
+ ---
8
+
9
+ import { FileTree, Tabs, TabItem } from '@astrojs/starlight/components';
10
+ import Link from '@components/link.astro';
11
+ import RunGenerator from '@components/run-generator.astro';
12
+ import GeneratorParameters from '@components/generator-parameters.astro';
13
+ import NxCommands from '@components/nx-commands.astro';
14
+ import PackageManagerShortCommand from '@components/package-manager-short-command.astro';
15
+ import Infrastructure from '@components/infrastructure.astro';
16
+ import Snippet from '@components/snippet.astro';
17
+ import OptionFilter from '@components/option-filter.astro';
18
+
19
+ [FastAPI](https://fastapi.tiangolo.com/) is a framework for building APIs in Python.
20
+
21
+ The FastAPI generator creates a new FastAPI with AWS CDK or Terraform infrastructure setup. The generated backend uses AWS Lambda for serverless deployment, exposed via an AWS API Gateway API. It sets up [AWS Lambda Powertools](https://docs.powertools.aws.dev/lambda/python/latest/) for observability, including logging, AWS X-Ray tracing and Cloudwatch Metrics.
22
+
23
+ ## Usage
24
+
25
+ ### Generate a FastAPI
26
+
27
+ You can generate a new FastAPI in two ways:
28
+
29
+ <RunGenerator generator="py#fast-api" />
30
+
31
+ ### Options
32
+
33
+ <GeneratorParameters generator="py#fast-api" />
34
+
35
+ <Snippet name="api/api-choice-note" />
36
+
37
+ :::tip[API Type]
38
+ Select `ServerlessApiGatewayRestApi` (default) as your `computeType` if you intend to build any streaming operations.
39
+ :::
40
+
41
+ :::tip[Integration Pattern]
42
+ The `integrationPattern` option defaults to `isolated`, which creates one Lambda per FastAPI operation. Select `shared` if you would prefer a single shared Lambda handler for the whole API, with optional per-operation overrides.
43
+ :::
44
+
45
+ ## Generator Output
46
+
47
+ The generator will create the following project structure in the `<directory>/<api-name>` directory:
48
+
49
+ <FileTree>
50
+
51
+ - project.json Project configuration and build targets
52
+ - pyproject.toml Python project configuration and dependencies
53
+ - run.sh Lambda Web Adapter bootstrap script to start the FastAPI app via uvicorn
54
+ - \<module_name>
55
+ - \_\_init\_\_.py Module initialisation
56
+ - init.py Sets the up FastAPI app and configures powertools middleware
57
+ - main.py API implementation
58
+ - scripts
59
+ - generate_open_api.py Script to generate an OpenAPI schema from the FastAPI app
60
+
61
+ </FileTree>
62
+
63
+ ### Infrastructure
64
+
65
+ <Snippet name="shared-constructs" />
66
+
67
+ <Snippet name="api/shared-constructs" />
68
+
69
+ #### Architecture
70
+
71
+ <Snippet name="api/api-architecture" />
72
+
73
+ ## Implementing your FastAPI
74
+
75
+ The main API implementation is in `main.py`. This is where you define your API routes and their implementations. Here's an example:
76
+
77
+ ```python
78
+ from pydantic import BaseModel
79
+ from .init import app, tracer
80
+
81
+ class Item(BaseModel):
82
+ name: str
83
+
84
+ @app.get("/items/{item_id}")
85
+ @tracer.capture_method
86
+ def get_item(item_id: int) -> Item:
87
+ return Item(name=...)
88
+
89
+ @app.post("/items")
90
+ @tracer.capture_method
91
+ def create_item(item: Item):
92
+ return ...
93
+ ```
94
+
95
+ The generator sets up several features automatically:
96
+
97
+ 1. AWS Lambda Powertools integration for observability
98
+ 2. Error handling middleware
99
+ 3. Request/response correlation
100
+ 4. Metrics collection
101
+ 5. AWS Lambda deployment via [Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter) with uvicorn
102
+ 6. Type-safe streaming (REST API only)
103
+
104
+ ### Observability with AWS Lambda Powertools
105
+
106
+ #### Logging
107
+
108
+ The generator configures structured logging using AWS Lambda Powertools. You can access the logger in your route handlers:
109
+
110
+ ```python
111
+ from .init import app, logger
112
+
113
+ @app.get("/items/{item_id}")
114
+ def read_item(item_id: int):
115
+ logger.info("Fetching item", extra={"item_id": item_id})
116
+ return {"item_id": item_id}
117
+ ```
118
+
119
+ The logger automatically includes:
120
+
121
+ - Correlation IDs for request tracing
122
+ - Request path and method
123
+ - Lambda context information
124
+ - Cold start indicators
125
+
126
+ #### Tracing
127
+
128
+ AWS X-Ray tracing is configured automatically. You can add custom subsegments to your traces:
129
+
130
+ ```python
131
+ from .init import app, tracer
132
+
133
+ @app.get("/items/{item_id}")
134
+ @tracer.capture_method
135
+ def read_item(item_id: int):
136
+ # Creates a new subsegment
137
+ with tracer.provider.in_subsegment("fetch-item-details"):
138
+ # Your logic here
139
+ return {"item_id": item_id}
140
+ ```
141
+
142
+ #### Metrics
143
+
144
+ CloudWatch metrics are collected automatically for each request. You can add custom metrics:
145
+
146
+ ```python
147
+ from .init import app, metrics
148
+ from aws_lambda_powertools.metrics import MetricUnit
149
+
150
+ @app.get("/items/{item_id}")
151
+ def read_item(item_id: int):
152
+ metrics.add_metric(name="ItemViewed", unit=MetricUnit.Count, value=1)
153
+ return {"item_id": item_id}
154
+ ```
155
+
156
+ Default metrics include:
157
+
158
+ - Request counts
159
+ - Success/failure counts
160
+ - Cold start metrics
161
+ - Per-route metrics
162
+
163
+ ### Error Handling
164
+
165
+ The generator includes comprehensive error handling:
166
+
167
+ ```python
168
+ from fastapi import HTTPException
169
+
170
+ @app.get("/items/{item_id}")
171
+ def read_item(item_id: int):
172
+ if item_id < 0:
173
+ raise HTTPException(status_code=400, detail="Item ID must be positive")
174
+ return {"item_id": item_id}
175
+ ```
176
+
177
+ Unhandled exceptions are caught by the middleware and:
178
+
179
+ 1. Log the full exception with stack trace
180
+ 2. Record a failure metric
181
+ 3. Return a safe 500 response to the client
182
+ 4. Preserve the correlation ID
183
+
184
+ :::tip[Response Models]
185
+ It's recommended to specify response models for your API operations for better code generation if using the `connection` generator. <Link path="guides/connection/react-fastapi#errors">See here for more details</Link>.
186
+ :::
187
+
188
+ <OptionFilter when={{ computeType: 'ServerlessApiGatewayRestApi' }} description="Streaming — REST API only">
189
+ ### Streaming
190
+
191
+ The generated FastAPI supports streaming responses out of the box when using a REST API. The infrastructure is configured to use the [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter) to run your FastAPI via uvicorn inside Lambda, with `ResponseTransferMode.STREAM` in API Gateway for all REST API operations, which enables streaming to work alongside non-streaming operations.
192
+
193
+ #### Using `JsonStreamingResponse`
194
+
195
+ The generated `init.py` exports a `JsonStreamingResponse` class that provides type-safe streaming with proper OpenAPI schema generation. This ensures that the <Link path="guides/connection/react-fastapi">`connection` generator</Link> can produce correctly typed streaming client methods.
196
+
197
+ ```python
198
+ from pydantic import BaseModel
199
+ from .init import app, JsonStreamingResponse
200
+
201
+ class Chunk(BaseModel):
202
+ message: str
203
+
204
+ async def generate_chunks():
205
+ for i in range(100):
206
+ yield Chunk(message=f"This is chunk {i}")
207
+
208
+ @app.post(
209
+ "/stream",
210
+ response_class=JsonStreamingResponse,
211
+ responses={200: JsonStreamingResponse.openapi_response(Chunk, "Stream of chunks")},
212
+ )
213
+ async def my_stream() -> JsonStreamingResponse:
214
+ return JsonStreamingResponse(generate_chunks())
215
+ ```
216
+
217
+ The `JsonStreamingResponse` class:
218
+
219
+ 1. Serializes Pydantic models to [JSON Lines](https://jsonlines.org/) format (`application/jsonl`)
220
+ 2. Provides an `openapi_response` helper that generates the correct OpenAPI schema with `itemSchema`, enabling the <Link path="guides/connection/react-fastapi#consuming-a-stream">`connection` generator</Link> to produce type-safe streaming client methods
221
+
222
+ #### Consumption
223
+
224
+ To consume a stream of responses, you can make use of the <Link path="guides/connection/react-fastapi#consuming-a-stream">`connection` generator</Link> which will provide a type-safe method for iterating over your streamed chunks.
225
+ </OptionFilter>
226
+
227
+ ## Deploying your FastAPI
228
+
229
+ The FastAPI generator creates CDK or Terraform infrastructure as code based on your selected `iacProvider`. You can use this to deploy your FastAPI.
230
+
231
+ <Infrastructure>
232
+ <Fragment slot="cdk">
233
+ The CDK construct for deploying your API in the `common/constructs` folder. You can use this in a CDK application:
234
+
235
+ ```ts {6-8}
236
+ import { MyApi } from ':my-scope/common-constructs';
237
+
238
+ export class ExampleStack extends Stack {
239
+ constructor(scope: Construct, id: string) {
240
+ // Add the api to your stack
241
+ const api = new MyApi(this, 'MyApi', {
242
+ integrations: MyApi.defaultIntegrations(this).build(),
243
+ });
244
+ }
245
+ }
246
+ ```
247
+
248
+ This sets up:
249
+
250
+ 1. An AWS Lambda function for each operation in the FastAPI application
251
+ 2. API Gateway HTTP/REST API as the function trigger
252
+ 3. IAM roles and permissions
253
+ 4. CloudWatch log group
254
+ 5. X-Ray tracing configuration
255
+ 6. CloudWatch metrics namespace
256
+
257
+ <Snippet name="api/cors-configuration-cdk-note" />
258
+
259
+ <OptionFilter when={{ auth: 'Cognito' }} description="Cognito identity construct wiring">
260
+ :::note[Cognito Authentication]
261
+ If you selected to use `Cognito` authentication, you will need to supply the `identity` property to the API construct:
262
+
263
+ ```ts {9}
264
+ import { MyApi, UserIdentity } from ':my-scope/common-constructs';
265
+
266
+ export class ExampleStack extends Stack {
267
+ constructor(scope: Construct, id: string) {
268
+ const identity = new UserIdentity(this, 'Identity');
269
+
270
+ const api = new MyApi(this, 'MyApi', {
271
+ integrations: MyApi.defaultIntegrations(this).build(),
272
+ identity,
273
+ });
274
+ }
275
+ }
276
+ ```
277
+
278
+ The `UserIdentity` construct can be generated using the <Link path="/guides/react-website-auth">`ts#website#auth` generator</Link>
279
+ :::
280
+ </OptionFilter>
281
+
282
+ <OptionFilter when={{ auth: 'Custom' }} description="Custom Lambda Authorizer CDK usage">
283
+ :::caution[Custom Lambda Authorizer]
284
+ When using `Custom` auth, the construct creates a Lambda Authorizer internally from the generated `authorizer.py` file, which **denies all requests by default**. You must implement your authorization logic in that file before your API will accept any traffic.
285
+ :::
286
+ </OptionFilter>
287
+ </Fragment>
288
+ <Fragment slot="terraform">
289
+ The Terraform modules for deploying your API are in the `common/terraform` folder. You can use this in a Terraform configuration.
290
+
291
+ The API module stages its Lambda deployment zip in a shared S3 asset bucket — see the <Link path="/guides/terraform-project">Terraform infrastructure guide</Link> for details. Instantiate the `core/asset-bucket` module once per deployment and pass its `bucket_name` output into every API / Lambda module via the `asset_bucket_name` input:
292
+
293
+ ```hcl {1-3, 8}
294
+ module "asset_bucket" {
295
+ source = "../../common/terraform/src/core/asset-bucket"
296
+ }
297
+
298
+ module "my_api" {
299
+ source = "../../common/terraform/src/app/apis/my-api"
300
+
301
+ asset_bucket_name = module.asset_bucket.bucket_name
302
+
303
+ # Environment variables for the Lambda function
304
+ env = {
305
+ ENVIRONMENT = var.environment
306
+ LOG_LEVEL = "INFO"
307
+ }
308
+
309
+ # Additional IAM policies if needed
310
+ additional_iam_policy_statements = [
311
+ # Add any additional permissions your API needs
312
+ ]
313
+
314
+ tags = local.common_tags
315
+ }
316
+ ```
317
+
318
+ This sets up:
319
+
320
+ 1. An AWS Lambda function that serves all FastAPI routes
321
+ 2. API Gateway HTTP/REST API as the function trigger
322
+ 3. IAM roles and permissions
323
+ 4. CloudWatch log group
324
+ 5. X-Ray tracing configuration
325
+ 6. CORS configuration
326
+
327
+ <Snippet name="api/cors-configuration-terraform-note" />
328
+
329
+ <OptionFilter when={{ auth: 'Cognito' }} description="Cognito module wiring">
330
+ :::note[Cognito Authentication]
331
+ If you selected to use `Cognito` authentication, you will need to supply the Cognito configuration:
332
+
333
+ ```hcl {3, 5-6}
334
+ module "my_api" {
335
+ source = "../../common/terraform/src/app/apis/my-api"
336
+
337
+ asset_bucket_name = module.asset_bucket.bucket_name
338
+
339
+ user_pool_id = local.user_pool_id
340
+ user_pool_client_ids = [local.client_id]
341
+
342
+ env = {
343
+ ENVIRONMENT = var.environment
344
+ LOG_LEVEL = "INFO"
345
+ }
346
+
347
+ tags = local.common_tags
348
+ }
349
+ ```
350
+
351
+ You can set up Cognito User Pool and Client using the appropriate Terraform resources or modules.
352
+ :::
353
+ </OptionFilter>
354
+
355
+ The Terraform module provides several outputs you can use:
356
+
357
+ ```hcl
358
+ # Access the API endpoint
359
+ output "api_url" {
360
+ value = module.my_api.stage_invoke_url
361
+ }
362
+
363
+ # Access Lambda function details
364
+ output "lambda_function_name" {
365
+ value = module.my_api.lambda_function_name
366
+ }
367
+
368
+ # Access IAM role for granting additional permissions
369
+ output "lambda_execution_role_arn" {
370
+ value = module.my_api.lambda_execution_role_arn
371
+ }
372
+ ```
373
+
374
+ You can customize CORS settings by passing variables to the module:
375
+
376
+ ```hcl
377
+ module "my_api" {
378
+ source = "../../common/terraform/src/app/apis/my-api"
379
+
380
+ asset_bucket_name = module.asset_bucket.bucket_name
381
+
382
+ # Custom CORS configuration
383
+ cors_allow_origins = ["https://myapp.com", "https://staging.myapp.com"]
384
+ cors_allow_methods = ["GET", "POST", "PUT", "DELETE"]
385
+ cors_allow_headers = [
386
+ "authorization",
387
+ "content-type",
388
+ "x-custom-header"
389
+ ]
390
+
391
+ tags = local.common_tags
392
+ }
393
+ ```
394
+
395
+ <OptionFilter when={{ auth: 'Custom' }} description="Custom Lambda Authorizer usage with Terraform">
396
+ :::caution[Custom Lambda Authorizer]
397
+ 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 `authorizer.py` file before your API will accept any traffic.
398
+ :::
399
+ </OptionFilter>
400
+ </Fragment>
401
+ </Infrastructure>
402
+
403
+ <OptionFilter when={{ computeType: 'ServerlessApiGatewayRestApi' }} description="WAF — REST APIs get a WAF Web ACL by default">
404
+ ### WAF
405
+
406
+ <Snippet name="api/waf-configuration" parentHeading="WAF" />
407
+ </OptionFilter>
408
+
409
+ ### Integrations
410
+
411
+ <Snippet name="api/type-safe-api-integrations" parentHeading="Integrations" />
412
+
413
+ #### Code Generation
414
+
415
+ <Infrastructure>
416
+ <Fragment slot="cdk">
417
+ Since operations in FastAPI are defined in Python and CDK infrastructure in TypeScript, we instrument code-generation to supply metadata to the CDK construct to provide a type-safe interface for integrations.
418
+
419
+ A `generate:<ApiName>-metadata` target is added to the common constructs `project.json` to facilitate this code generation, which emits a file such as `packages/common/constructs/src/generated/my-api/metadata.gen.ts`. Since this is generated at build time, it is ignored in version control.
420
+
421
+ :::note[Build Before Deploy]
422
+ You will need to run a build whenever you change your API to ensure the types consumed by the CDK construct are up to date.
423
+
424
+ <PackageManagerShortCommand commands={["build"]} />
425
+ :::
426
+
427
+ :::tip[Hot Reloading]
428
+ If you are actively working on both your CDK infrastructure and FastAPI together, you can use [`nx watch`](https://nx.dev/nx-api/nx/documents/watch) to regenerate these types every time you make API changes:
429
+
430
+ <NxCommands
431
+ commands={[
432
+ 'watch --projects=<FastAPIProject> -- \\ ',
433
+ 'run <InfraProject>:"generate:<ApiName>-metadata"',
434
+ ]}
435
+ />
436
+ :::
437
+ </Fragment>
438
+ <Fragment slot="terraform">
439
+ :::note[Terraform Limitations]
440
+ We do not support type-safe integrations for Terraform, and therefore no code generation targets are configured if you selected Terraform for your `iacProvider`.
441
+ :::
442
+ </Fragment>
443
+ </Infrastructure>
444
+
445
+ <OptionFilter when={{ auth: 'IAM' }} description="IAM-authenticated APIs only">
446
+ ### Granting Access (IAM Only)
447
+
448
+ If you selected to use `IAM` authentication, you can use the `grantInvokeAccess` method to grant access to your API:
449
+
450
+ <Infrastructure>
451
+ <Fragment slot="cdk">
452
+ ```ts
453
+ api.grantInvokeAccess(myIdentityPool.authenticatedRole);
454
+ ```
455
+ </Fragment>
456
+ <Fragment slot="terraform">
457
+ ```hcl
458
+ # Create an IAM policy to allow invoking the API
459
+ resource "aws_iam_policy" "api_invoke_policy" {
460
+ name = "MyApiInvokePolicy"
461
+ description = "Policy to allow invoking the FastAPI"
462
+
463
+ policy = jsonencode({
464
+ Version = "2012-10-17"
465
+ Statement = [
466
+ {
467
+ Effect = "Allow"
468
+ Action = "execute-api:Invoke"
469
+ Resource = "${module.my_api.api_execution_arn}/*/*"
470
+ }
471
+ ]
472
+ })
473
+ }
474
+
475
+ # Attach the policy to an IAM role (e.g., for authenticated users)
476
+ resource "aws_iam_role_policy_attachment" "api_invoke_access" {
477
+ role = aws_iam_role.authenticated_user_role.name
478
+ policy_arn = aws_iam_policy.api_invoke_policy.arn
479
+ }
480
+
481
+ # Or attach to an existing role by name
482
+ resource "aws_iam_role_policy_attachment" "api_invoke_access_existing" {
483
+ role = "MyExistingRole"
484
+ policy_arn = aws_iam_policy.api_invoke_policy.arn
485
+ }
486
+ ```
487
+
488
+ The key outputs from the API module that you can use for IAM policies are:
489
+
490
+ - `module.my_api.api_execution_arn` - For granting execute-api:Invoke permissions
491
+ - `module.my_api.api_arn` - The API Gateway ARN
492
+ - `module.my_api.lambda_function_arn` - The Lambda function ARN
493
+ </Fragment>
494
+ </Infrastructure>
495
+ </OptionFilter>
496
+
497
+ ## Local Development
498
+
499
+ The generator configures a local development server that you can run with:
500
+
501
+ <NxCommands commands={['serve my-api']} />
502
+
503
+ This starts a local FastAPI development server with:
504
+
505
+ - Auto-reload on code changes
506
+ - Interactive API documentation at `/docs` or `/redoc`
507
+ - OpenAPI schema at `/openapi.json`
508
+
509
+ ## Invoking your FastAPI
510
+
511
+ To invoke your API from a React website, you can use the <Link path="guides/connection/react-fastapi">`connection` generator</Link>.