@aws/nx-plugin 1.0.0-rc.31 → 1.0.0-rc.33
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/LICENSE-THIRD-PARTY +72 -70
- package/package.json +5 -5
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +15 -15
- package/src/infra/app/files/app/src/main.ts.template +1 -1
- package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
- package/src/infra/app/generator.js +3 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +64 -3
- package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +280 -0
- package/src/open-api/ts-client/files/client.gen.ts.template +37 -2
- package/src/open-api/ts-client/generator.js +5 -1
- package/src/open-api/ts-client/generator.js.map +1 -1
- package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
- package/src/open-api/ts-hooks/generator.js +5 -1
- package/src/open-api/ts-hooks/generator.js.map +1 -1
- package/src/open-api/utils/normalise.js +13 -6
- package/src/open-api/utils/normalise.js.map +1 -1
- package/src/open-api/utils/parser.js +12 -1
- package/src/open-api/utils/parser.js.map +1 -1
- package/src/open-api/utils/types.d.ts +4 -1
- package/src/open-api/utils/types.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/preset/generator.d.ts +1 -1
- package/src/preset/generator.js +5 -2
- package/src/preset/generator.js.map +1 -1
- package/src/preset/schema.d.js.map +1 -1
- package/src/preset/schema.d.ts +2 -0
- package/src/preset/schema.json +6 -0
- package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
- package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
- package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +426 -18
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +283 -11
- package/src/smithy/ts/api/files/handler.ts.template +2 -2
- package/src/smithy/ts/api/files/local-server.ts.template +2 -2
- package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
- package/src/smithy/ts/api/files/service.ts.template +3 -3
- package/src/smithy/ts/api/generator.js +3 -1
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +426 -18
- package/src/trpc/backend/files/src/client/index.ts.template +1 -1
- package/src/trpc/backend/files/src/handler.ts.template +1 -1
- package/src/trpc/backend/files/src/index.ts.template +5 -5
- package/src/trpc/backend/files/src/init.ts.template +1 -1
- package/src/trpc/backend/files/src/local-server.ts.template +1 -1
- package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
- package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
- package/src/trpc/backend/files/src/router.ts.template +2 -2
- package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
- package/src/trpc/backend/generator.js +3 -1
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
- package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/a2a-connection/generator.js +3 -1
- package/src/ts/agent/a2a-connection/generator.js.map +1 -1
- package/src/ts/agent/files/a2a/index.ts.template +1 -1
- package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
- package/src/ts/agent/files/http/client.ts.template +2 -2
- package/src/ts/agent/files/http/index.ts.template +2 -2
- package/src/ts/agent/files/http/router.ts.template +3 -3
- package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/gateway-connection/generator.js +3 -1
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.js +5 -2
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
- package/src/ts/agent/mcp-connection/generator.js +3 -1
- package/src/ts/agent/mcp-connection/generator.js.map +1 -1
- package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
- package/src/ts/astro-docs/generator.js +2 -0
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/dynamodb/files/src/client.ts.template +5 -2
- package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
- package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
- package/src/ts/dynamodb/files/src/index.ts.template +2 -2
- package/src/ts/dynamodb/generator.js +3 -1
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/lib/generator.js +7 -1
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +19 -4
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/types.d.ts +6 -0
- package/src/ts/lib/types.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -31
- package/src/ts/mcp-server/generator.js +11 -22
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
- package/src/ts/nx-generator/generator.js +5 -2
- package/src/ts/nx-generator/generator.js.map +1 -1
- package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
- package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
- package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
- package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
- package/src/ts/nx-plugin/generator.js +3 -1
- package/src/ts/nx-plugin/generator.js.map +1 -1
- package/src/ts/nx-plugin/utils.js +7 -4
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
- package/src/ts/rdb/files/src/index.ts.template +1 -1
- package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
- package/src/ts/rdb/files/src/prisma.ts.template +7 -4
- package/src/ts/rdb/generator.js +3 -1
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +35 -35
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
- package/src/utils/agent-chat/agent-chat.js +3 -1
- package/src/utils/agent-chat/agent-chat.js.map +1 -1
- package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
- package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
- package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
- package/src/utils/agent-connection/agent-connection.js +4 -1
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
- package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
- package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
- package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
- package/src/utils/api-constructs/api-constructs.js +8 -2
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
- package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
- package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
- package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
- package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
- package/src/utils/ast.js +16 -0
- package/src/utils/ast.js.map +1 -1
- package/src/utils/commands.d.ts +1 -1
- package/src/utils/commands.js +4 -1
- package/src/utils/commands.js.map +1 -1
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
- package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
- package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
- package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
- package/src/utils/files/common/constructs/src/index.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
- package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
- package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
- package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
- package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
- package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
- package/src/utils/function-constructs/function-constructs.js +3 -1
- package/src/utils/function-constructs/function-constructs.js.map +1 -1
- package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
- package/src/utils/identity-constructs/identity-constructs.js +5 -1
- package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
- package/src/utils/module-format.d.ts +28 -0
- package/src/utils/module-format.js +28 -0
- package/src/utils/module-format.js.map +1 -0
- package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +5 -5
- package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +1 -1
- package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
- package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
- package/src/utils/shared-constructs.js +3 -1
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/shared-infra-config.js +3 -1
- package/src/utils/shared-infra-config.js.map +1 -1
- package/src/utils/shared-infra-scripts.js +3 -1
- package/src/utils/shared-infra-scripts.js.map +1 -1
- package/src/utils/shared-shadcn.js +3 -1
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/test.d.ts +2 -0
- package/src/utils/test.js +7 -1
- package/src/utils/test.js.map +1 -1
- package/src/utils/versions.d.ts +61 -61
- package/src/utils/versions.js +59 -59
- package/src/utils/versions.js.map +1 -1
- package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
- package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
- package/src/utils/website-constructs/website-constructs.js +9 -2
- package/src/utils/website-constructs/website-constructs.js.map +1 -1
|
@@ -70,7 +70,7 @@ exports[`lambda-handler project generator > terraform iac > should generate terr
|
|
|
70
70
|
required_providers {
|
|
71
71
|
aws = {
|
|
72
72
|
source = "hashicorp/aws"
|
|
73
|
-
version = "6.
|
|
73
|
+
version = "6.54.0"
|
|
74
74
|
}
|
|
75
75
|
archive = {
|
|
76
76
|
source = "hashicorp/archive"
|
|
@@ -251,7 +251,7 @@ exports[`lambda-handler project generator > terraform iac > should match snapsho
|
|
|
251
251
|
required_providers {
|
|
252
252
|
aws = {
|
|
253
253
|
source = "hashicorp/aws"
|
|
254
|
-
version = "6.
|
|
254
|
+
version = "6.54.0"
|
|
255
255
|
}
|
|
256
256
|
archive = {
|
|
257
257
|
source = "hashicorp/archive"
|
|
@@ -135,7 +135,7 @@ exports[`py#mcp-server generator > should match snapshot for Terraform generated
|
|
|
135
135
|
required_providers {
|
|
136
136
|
aws = {
|
|
137
137
|
source = "hashicorp/aws"
|
|
138
|
-
version = "6.
|
|
138
|
+
version = "6.54.0"
|
|
139
139
|
}
|
|
140
140
|
null = {
|
|
141
141
|
source = "hashicorp/null"
|
|
@@ -201,6 +201,30 @@ variable "additional_iam_policy_statements" {
|
|
|
201
201
|
default = []
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
# VPC Configuration (optional)
|
|
205
|
+
variable "enable_vpc" {
|
|
206
|
+
description = "Run the agent core runtime inside a VPC. Set alongside vpc_id/subnet_ids."
|
|
207
|
+
type = bool
|
|
208
|
+
default = false
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
variable "vpc_id" {
|
|
212
|
+
description = "VPC ID to run the agent core runtime in. Required when enable_vpc is true."
|
|
213
|
+
type = string
|
|
214
|
+
default = null
|
|
215
|
+
|
|
216
|
+
validation {
|
|
217
|
+
condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
|
|
218
|
+
error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
variable "subnet_ids" {
|
|
223
|
+
description = "Subnet IDs to run the agent core runtime in. Required when enable_vpc is true."
|
|
224
|
+
type = list(string)
|
|
225
|
+
default = null
|
|
226
|
+
}
|
|
227
|
+
|
|
204
228
|
variable "tags" {
|
|
205
229
|
description = "Tags to apply to resources"
|
|
206
230
|
type = map(string)
|
|
@@ -436,6 +460,28 @@ resource "null_resource" "docker_publish" {
|
|
|
436
460
|
depends_on = [aws_ecr_repository_policy.agent_core_ecr_policy]
|
|
437
461
|
}
|
|
438
462
|
|
|
463
|
+
# Security group for the agent core runtime, used when running inside a VPC
|
|
464
|
+
resource "aws_security_group" "agent_core_runtime" {
|
|
465
|
+
count = var.enable_vpc ? 1 : 0
|
|
466
|
+
|
|
467
|
+
#checkov:skip=CKV2_AWS_5:Attached to the runtime via network_configuration; Checkov cannot resolve this reference
|
|
468
|
+
name_prefix = "\${var.agent_runtime_name}-runtime-"
|
|
469
|
+
description = "Security group for the \${var.agent_runtime_name} agent core runtime"
|
|
470
|
+
vpc_id = var.vpc_id
|
|
471
|
+
tags = var.tags
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
resource "aws_vpc_security_group_egress_rule" "agent_core_runtime_https" {
|
|
475
|
+
count = var.enable_vpc ? 1 : 0
|
|
476
|
+
|
|
477
|
+
security_group_id = aws_security_group.agent_core_runtime[0].id
|
|
478
|
+
cidr_ipv4 = "0.0.0.0/0"
|
|
479
|
+
from_port = 443
|
|
480
|
+
to_port = 443
|
|
481
|
+
ip_protocol = "tcp"
|
|
482
|
+
description = "Allow outbound HTTPS to AWS service endpoints"
|
|
483
|
+
}
|
|
484
|
+
|
|
439
485
|
# Bedrock AgentCore Agent Runtime
|
|
440
486
|
resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
|
|
441
487
|
agent_runtime_name = "\${var.agent_runtime_name}_\${random_id.unique_suffix.hex}"
|
|
@@ -462,7 +508,15 @@ resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
|
|
|
462
508
|
}
|
|
463
509
|
|
|
464
510
|
network_configuration {
|
|
465
|
-
network_mode = "PUBLIC"
|
|
511
|
+
network_mode = var.enable_vpc ? "VPC" : "PUBLIC"
|
|
512
|
+
|
|
513
|
+
dynamic "network_mode_config" {
|
|
514
|
+
for_each = var.enable_vpc ? [1] : []
|
|
515
|
+
content {
|
|
516
|
+
security_groups = [aws_security_group.agent_core_runtime[0].id]
|
|
517
|
+
subnets = var.subnet_ids
|
|
518
|
+
}
|
|
519
|
+
}
|
|
466
520
|
}
|
|
467
521
|
|
|
468
522
|
protocol_configuration {
|
|
@@ -489,7 +543,7 @@ resource "null_resource" "runtime_ready" {
|
|
|
489
543
|
|
|
490
544
|
provisioner "local-exec" {
|
|
491
545
|
command = <<-EOT
|
|
492
|
-
uv run --with boto3==1.43.
|
|
546
|
+
uv run --with boto3==1.43.46 python -c "
|
|
493
547
|
import boto3
|
|
494
548
|
import json
|
|
495
549
|
import os
|
|
@@ -564,6 +618,11 @@ output "agent_runtime_version" {
|
|
|
564
618
|
description = "Version of the Bedrock Agent Core runtime"
|
|
565
619
|
value = aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_version
|
|
566
620
|
}
|
|
621
|
+
|
|
622
|
+
output "security_group_id" {
|
|
623
|
+
description = "Security group ID of the agent core runtime, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
624
|
+
value = var.enable_vpc ? aws_security_group.agent_core_runtime[0].id : null
|
|
625
|
+
}
|
|
567
626
|
"
|
|
568
627
|
`;
|
|
569
628
|
|
|
@@ -590,6 +649,25 @@ variable "tags" {
|
|
|
590
649
|
default = {}
|
|
591
650
|
}
|
|
592
651
|
|
|
652
|
+
# VPC Configuration (optional)
|
|
653
|
+
variable "enable_vpc" {
|
|
654
|
+
description = "Run the agent core runtime inside a VPC. Set alongside vpc_id/subnet_ids."
|
|
655
|
+
type = bool
|
|
656
|
+
default = false
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
variable "vpc_id" {
|
|
660
|
+
description = "VPC ID to run the agent core runtime in. Required when enable_vpc is true."
|
|
661
|
+
type = string
|
|
662
|
+
default = null
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
variable "subnet_ids" {
|
|
666
|
+
description = "Subnet IDs to run the agent core runtime in. Required when enable_vpc is true."
|
|
667
|
+
type = list(string)
|
|
668
|
+
default = null
|
|
669
|
+
}
|
|
670
|
+
|
|
593
671
|
variable "appconfig_application_id" {
|
|
594
672
|
description = "ID of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_id\`). The agent reads its runtime configuration from this application."
|
|
595
673
|
type = string
|
|
@@ -605,6 +683,9 @@ module "agent_core_runtime" {
|
|
|
605
683
|
agent_runtime_name = "TerraformSnapshotServer"
|
|
606
684
|
docker_image_tag = "proj-terraform-snapshot-server:latest"
|
|
607
685
|
server_protocol = "MCP"
|
|
686
|
+
enable_vpc = var.enable_vpc
|
|
687
|
+
vpc_id = var.vpc_id
|
|
688
|
+
subnet_ids = var.subnet_ids
|
|
608
689
|
|
|
609
690
|
env = merge({
|
|
610
691
|
RUNTIME_CONFIG_APP_ID = var.appconfig_application_id
|
|
@@ -647,6 +728,11 @@ output "appconfig_application_id" {
|
|
|
647
728
|
description = "AppConfig Application ID for runtime config (passthrough of the shared \`appconfig_application_id\` input)."
|
|
648
729
|
value = var.appconfig_application_id
|
|
649
730
|
}
|
|
731
|
+
|
|
732
|
+
output "security_group_id" {
|
|
733
|
+
description = "Security group ID of the agent core runtime, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
734
|
+
value = module.agent_core_runtime.security_group_id
|
|
735
|
+
}
|
|
650
736
|
"
|
|
651
737
|
`;
|
|
652
738
|
|
|
@@ -718,8 +804,8 @@ version = "0.1.0"
|
|
|
718
804
|
dependencies = [
|
|
719
805
|
"aws-lambda-powertools==3.31.0",
|
|
720
806
|
"mcp==1.28.1",
|
|
721
|
-
"uvicorn==0.
|
|
722
|
-
"boto3==1.43.
|
|
807
|
+
"uvicorn==0.51.0",
|
|
808
|
+
"boto3==1.43.46",
|
|
723
809
|
"aws-opentelemetry-distro==0.18.0"
|
|
724
810
|
]
|
|
725
811
|
|
|
@@ -403,7 +403,7 @@ terraform {
|
|
|
403
403
|
required_providers {
|
|
404
404
|
aws = {
|
|
405
405
|
source = "hashicorp/aws"
|
|
406
|
-
version = "6.
|
|
406
|
+
version = "6.54.0"
|
|
407
407
|
}
|
|
408
408
|
random = {
|
|
409
409
|
source = "hashicorp/random"
|
|
@@ -662,7 +662,7 @@ exports[`tsSmithyApiGenerator > should generate smithy ts api with Terraform pro
|
|
|
662
662
|
required_providers {
|
|
663
663
|
aws = {
|
|
664
664
|
source = "hashicorp/aws"
|
|
665
|
-
version = "6.
|
|
665
|
+
version = "6.54.0"
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
}
|
|
@@ -689,6 +689,30 @@ variable "asset_bucket_name" {
|
|
|
689
689
|
type = string
|
|
690
690
|
}
|
|
691
691
|
|
|
692
|
+
# VPC Configuration (optional)
|
|
693
|
+
variable "enable_vpc" {
|
|
694
|
+
description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
|
|
695
|
+
type = bool
|
|
696
|
+
default = false
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
variable "vpc_id" {
|
|
700
|
+
description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
|
|
701
|
+
type = string
|
|
702
|
+
default = null
|
|
703
|
+
|
|
704
|
+
validation {
|
|
705
|
+
condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
|
|
706
|
+
error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
variable "subnet_ids" {
|
|
711
|
+
description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
|
|
712
|
+
type = list(string)
|
|
713
|
+
default = null
|
|
714
|
+
}
|
|
715
|
+
|
|
692
716
|
# CORS Configuration (passed to core module)
|
|
693
717
|
|
|
694
718
|
variable "cors_allow_headers" {
|
|
@@ -785,9 +809,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
|
|
|
785
809
|
depends_on = [aws_api_gateway_stage.api_stage]
|
|
786
810
|
}
|
|
787
811
|
|
|
812
|
+
# Security group for the API Lambda function, used when deployed into a VPC
|
|
813
|
+
resource "aws_security_group" "api_lambda" {
|
|
814
|
+
count = var.enable_vpc ? 1 : 0
|
|
815
|
+
|
|
816
|
+
#checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
|
|
817
|
+
name_prefix = "test-api-lambda-"
|
|
818
|
+
description = "Security group for the TestApi API Lambda function"
|
|
819
|
+
vpc_id = var.vpc_id
|
|
820
|
+
tags = var.tags
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
|
|
824
|
+
count = var.enable_vpc ? 1 : 0
|
|
825
|
+
|
|
826
|
+
security_group_id = aws_security_group.api_lambda[0].id
|
|
827
|
+
cidr_ipv4 = "0.0.0.0/0"
|
|
828
|
+
from_port = 443
|
|
829
|
+
to_port = 443
|
|
830
|
+
ip_protocol = "tcp"
|
|
831
|
+
description = "Allow outbound HTTPS to AWS service endpoints"
|
|
832
|
+
}
|
|
833
|
+
|
|
788
834
|
# Lambda function
|
|
789
835
|
resource "aws_lambda_function" "api_lambda" {
|
|
790
|
-
#checkov:skip=CKV_AWS_117:Lambda function
|
|
836
|
+
#checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
|
|
791
837
|
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
|
|
792
838
|
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
793
839
|
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
@@ -809,6 +855,14 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
809
855
|
mode = "Active"
|
|
810
856
|
}
|
|
811
857
|
|
|
858
|
+
dynamic "vpc_config" {
|
|
859
|
+
for_each = var.enable_vpc ? [1] : []
|
|
860
|
+
content {
|
|
861
|
+
subnet_ids = var.subnet_ids
|
|
862
|
+
security_group_ids = [aws_security_group.api_lambda[0].id]
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
812
866
|
|
|
813
867
|
environment {
|
|
814
868
|
variables = merge({
|
|
@@ -816,6 +870,8 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
816
870
|
}
|
|
817
871
|
|
|
818
872
|
tags = var.tags
|
|
873
|
+
|
|
874
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
|
|
819
875
|
}
|
|
820
876
|
|
|
821
877
|
# IAM role for Lambda execution
|
|
@@ -850,6 +906,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
|
|
|
850
906
|
role = aws_iam_role.lambda_execution_role.name
|
|
851
907
|
}
|
|
852
908
|
|
|
909
|
+
# Attach VPC access policy to Lambda role when deployed into a VPC
|
|
910
|
+
resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
|
|
911
|
+
count = var.enable_vpc ? 1 : 0
|
|
912
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
|
|
913
|
+
role = aws_iam_role.lambda_execution_role.name
|
|
914
|
+
}
|
|
915
|
+
|
|
853
916
|
# Additional IAM policies for Lambda (if provided)
|
|
854
917
|
resource "aws_iam_role_policy" "lambda_additional_policies" {
|
|
855
918
|
count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
|
|
@@ -1316,6 +1379,11 @@ output "lambda_execution_role_name" {
|
|
|
1316
1379
|
value = aws_iam_role.lambda_execution_role.name
|
|
1317
1380
|
}
|
|
1318
1381
|
|
|
1382
|
+
output "security_group_id" {
|
|
1383
|
+
description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
1384
|
+
value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1319
1387
|
# Integration Outputs
|
|
1320
1388
|
output "integration_id" {
|
|
1321
1389
|
description = "ID of the Lambda integration"
|
|
@@ -1759,7 +1827,7 @@ terraform {
|
|
|
1759
1827
|
required_providers {
|
|
1760
1828
|
aws = {
|
|
1761
1829
|
source = "hashicorp/aws"
|
|
1762
|
-
version = "6.
|
|
1830
|
+
version = "6.54.0"
|
|
1763
1831
|
}
|
|
1764
1832
|
random = {
|
|
1765
1833
|
source = "hashicorp/random"
|
|
@@ -2015,7 +2083,7 @@ output "waf_web_acl_arn" {
|
|
|
2015
2083
|
required_providers {
|
|
2016
2084
|
aws = {
|
|
2017
2085
|
source = "hashicorp/aws"
|
|
2018
|
-
version = "6.
|
|
2086
|
+
version = "6.54.0"
|
|
2019
2087
|
}
|
|
2020
2088
|
}
|
|
2021
2089
|
}
|
|
@@ -2052,6 +2120,30 @@ variable "asset_bucket_name" {
|
|
|
2052
2120
|
type = string
|
|
2053
2121
|
}
|
|
2054
2122
|
|
|
2123
|
+
# VPC Configuration (optional)
|
|
2124
|
+
variable "enable_vpc" {
|
|
2125
|
+
description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
|
|
2126
|
+
type = bool
|
|
2127
|
+
default = false
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
variable "vpc_id" {
|
|
2131
|
+
description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
|
|
2132
|
+
type = string
|
|
2133
|
+
default = null
|
|
2134
|
+
|
|
2135
|
+
validation {
|
|
2136
|
+
condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
|
|
2137
|
+
error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
variable "subnet_ids" {
|
|
2142
|
+
description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
|
|
2143
|
+
type = list(string)
|
|
2144
|
+
default = null
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2055
2147
|
# CORS Configuration (passed to core module)
|
|
2056
2148
|
|
|
2057
2149
|
variable "cors_allow_headers" {
|
|
@@ -2148,9 +2240,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
|
|
|
2148
2240
|
depends_on = [aws_api_gateway_stage.api_stage]
|
|
2149
2241
|
}
|
|
2150
2242
|
|
|
2243
|
+
# Security group for the API Lambda function, used when deployed into a VPC
|
|
2244
|
+
resource "aws_security_group" "api_lambda" {
|
|
2245
|
+
count = var.enable_vpc ? 1 : 0
|
|
2246
|
+
|
|
2247
|
+
#checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
|
|
2248
|
+
name_prefix = "test-api-lambda-"
|
|
2249
|
+
description = "Security group for the TestApi API Lambda function"
|
|
2250
|
+
vpc_id = var.vpc_id
|
|
2251
|
+
tags = var.tags
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
|
|
2255
|
+
count = var.enable_vpc ? 1 : 0
|
|
2256
|
+
|
|
2257
|
+
security_group_id = aws_security_group.api_lambda[0].id
|
|
2258
|
+
cidr_ipv4 = "0.0.0.0/0"
|
|
2259
|
+
from_port = 443
|
|
2260
|
+
to_port = 443
|
|
2261
|
+
ip_protocol = "tcp"
|
|
2262
|
+
description = "Allow outbound HTTPS to AWS service endpoints"
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2151
2265
|
# Lambda function
|
|
2152
2266
|
resource "aws_lambda_function" "api_lambda" {
|
|
2153
|
-
#checkov:skip=CKV_AWS_117:Lambda function
|
|
2267
|
+
#checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
|
|
2154
2268
|
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
|
|
2155
2269
|
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
2156
2270
|
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
@@ -2172,6 +2286,14 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
2172
2286
|
mode = "Active"
|
|
2173
2287
|
}
|
|
2174
2288
|
|
|
2289
|
+
dynamic "vpc_config" {
|
|
2290
|
+
for_each = var.enable_vpc ? [1] : []
|
|
2291
|
+
content {
|
|
2292
|
+
subnet_ids = var.subnet_ids
|
|
2293
|
+
security_group_ids = [aws_security_group.api_lambda[0].id]
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2175
2297
|
|
|
2176
2298
|
environment {
|
|
2177
2299
|
variables = merge({
|
|
@@ -2179,6 +2301,8 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
2179
2301
|
}
|
|
2180
2302
|
|
|
2181
2303
|
tags = var.tags
|
|
2304
|
+
|
|
2305
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
|
|
2182
2306
|
}
|
|
2183
2307
|
|
|
2184
2308
|
# IAM role for Lambda execution
|
|
@@ -2213,6 +2337,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
|
|
|
2213
2337
|
role = aws_iam_role.lambda_execution_role.name
|
|
2214
2338
|
}
|
|
2215
2339
|
|
|
2340
|
+
# Attach VPC access policy to Lambda role when deployed into a VPC
|
|
2341
|
+
resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
|
|
2342
|
+
count = var.enable_vpc ? 1 : 0
|
|
2343
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
|
|
2344
|
+
role = aws_iam_role.lambda_execution_role.name
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2216
2347
|
# Additional IAM policies for Lambda (if provided)
|
|
2217
2348
|
resource "aws_iam_role_policy" "lambda_additional_policies" {
|
|
2218
2349
|
count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
|
|
@@ -2597,6 +2728,11 @@ output "lambda_execution_role_name" {
|
|
|
2597
2728
|
value = aws_iam_role.lambda_execution_role.name
|
|
2598
2729
|
}
|
|
2599
2730
|
|
|
2731
|
+
output "security_group_id" {
|
|
2732
|
+
description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
2733
|
+
value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2600
2736
|
# Integration Outputs
|
|
2601
2737
|
output "integration_id" {
|
|
2602
2738
|
description = "ID of the Lambda integration"
|
|
@@ -2638,7 +2774,7 @@ terraform {
|
|
|
2638
2774
|
required_providers {
|
|
2639
2775
|
aws = {
|
|
2640
2776
|
source = "hashicorp/aws"
|
|
2641
|
-
version = "6.
|
|
2777
|
+
version = "6.54.0"
|
|
2642
2778
|
}
|
|
2643
2779
|
random = {
|
|
2644
2780
|
source = "hashicorp/random"
|
|
@@ -2894,7 +3030,7 @@ output "waf_web_acl_arn" {
|
|
|
2894
3030
|
required_providers {
|
|
2895
3031
|
aws = {
|
|
2896
3032
|
source = "hashicorp/aws"
|
|
2897
|
-
version = "6.
|
|
3033
|
+
version = "6.54.0"
|
|
2898
3034
|
}
|
|
2899
3035
|
}
|
|
2900
3036
|
}
|
|
@@ -2921,6 +3057,30 @@ variable "asset_bucket_name" {
|
|
|
2921
3057
|
type = string
|
|
2922
3058
|
}
|
|
2923
3059
|
|
|
3060
|
+
# VPC Configuration (optional)
|
|
3061
|
+
variable "enable_vpc" {
|
|
3062
|
+
description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
|
|
3063
|
+
type = bool
|
|
3064
|
+
default = false
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
variable "vpc_id" {
|
|
3068
|
+
description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
|
|
3069
|
+
type = string
|
|
3070
|
+
default = null
|
|
3071
|
+
|
|
3072
|
+
validation {
|
|
3073
|
+
condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
|
|
3074
|
+
error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
variable "subnet_ids" {
|
|
3079
|
+
description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
|
|
3080
|
+
type = list(string)
|
|
3081
|
+
default = null
|
|
3082
|
+
}
|
|
3083
|
+
|
|
2924
3084
|
# CORS Configuration (passed to core module)
|
|
2925
3085
|
|
|
2926
3086
|
variable "cors_allow_headers" {
|
|
@@ -3017,9 +3177,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
|
|
|
3017
3177
|
depends_on = [aws_api_gateway_stage.api_stage]
|
|
3018
3178
|
}
|
|
3019
3179
|
|
|
3180
|
+
# Security group for the API Lambda function, used when deployed into a VPC
|
|
3181
|
+
resource "aws_security_group" "api_lambda" {
|
|
3182
|
+
count = var.enable_vpc ? 1 : 0
|
|
3183
|
+
|
|
3184
|
+
#checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
|
|
3185
|
+
name_prefix = "test-api-lambda-"
|
|
3186
|
+
description = "Security group for the TestApi API Lambda function"
|
|
3187
|
+
vpc_id = var.vpc_id
|
|
3188
|
+
tags = var.tags
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
|
+
resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
|
|
3192
|
+
count = var.enable_vpc ? 1 : 0
|
|
3193
|
+
|
|
3194
|
+
security_group_id = aws_security_group.api_lambda[0].id
|
|
3195
|
+
cidr_ipv4 = "0.0.0.0/0"
|
|
3196
|
+
from_port = 443
|
|
3197
|
+
to_port = 443
|
|
3198
|
+
ip_protocol = "tcp"
|
|
3199
|
+
description = "Allow outbound HTTPS to AWS service endpoints"
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3020
3202
|
# Lambda function
|
|
3021
3203
|
resource "aws_lambda_function" "api_lambda" {
|
|
3022
|
-
#checkov:skip=CKV_AWS_117:Lambda function
|
|
3204
|
+
#checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
|
|
3023
3205
|
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
|
|
3024
3206
|
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
3025
3207
|
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
@@ -3041,6 +3223,14 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
3041
3223
|
mode = "Active"
|
|
3042
3224
|
}
|
|
3043
3225
|
|
|
3226
|
+
dynamic "vpc_config" {
|
|
3227
|
+
for_each = var.enable_vpc ? [1] : []
|
|
3228
|
+
content {
|
|
3229
|
+
subnet_ids = var.subnet_ids
|
|
3230
|
+
security_group_ids = [aws_security_group.api_lambda[0].id]
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3044
3234
|
|
|
3045
3235
|
environment {
|
|
3046
3236
|
variables = merge({
|
|
@@ -3048,6 +3238,8 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
3048
3238
|
}
|
|
3049
3239
|
|
|
3050
3240
|
tags = var.tags
|
|
3241
|
+
|
|
3242
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
|
|
3051
3243
|
}
|
|
3052
3244
|
|
|
3053
3245
|
# IAM role for Lambda execution
|
|
@@ -3082,6 +3274,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
|
|
|
3082
3274
|
role = aws_iam_role.lambda_execution_role.name
|
|
3083
3275
|
}
|
|
3084
3276
|
|
|
3277
|
+
# Attach VPC access policy to Lambda role when deployed into a VPC
|
|
3278
|
+
resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
|
|
3279
|
+
count = var.enable_vpc ? 1 : 0
|
|
3280
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
|
|
3281
|
+
role = aws_iam_role.lambda_execution_role.name
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3085
3284
|
# Additional IAM policies for Lambda (if provided)
|
|
3086
3285
|
resource "aws_iam_role_policy" "lambda_additional_policies" {
|
|
3087
3286
|
count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
|
|
@@ -3465,6 +3664,11 @@ output "lambda_execution_role_name" {
|
|
|
3465
3664
|
value = aws_iam_role.lambda_execution_role.name
|
|
3466
3665
|
}
|
|
3467
3666
|
|
|
3667
|
+
output "security_group_id" {
|
|
3668
|
+
description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
3669
|
+
value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3468
3672
|
# Integration Outputs
|
|
3469
3673
|
output "integration_id" {
|
|
3470
3674
|
description = "ID of the Lambda integration"
|
|
@@ -3502,7 +3706,7 @@ exports[`tsSmithyApiGenerator > terraform iac > should generate terraform with c
|
|
|
3502
3706
|
required_providers {
|
|
3503
3707
|
aws = {
|
|
3504
3708
|
source = "hashicorp/aws"
|
|
3505
|
-
version = "6.
|
|
3709
|
+
version = "6.54.0"
|
|
3506
3710
|
}
|
|
3507
3711
|
}
|
|
3508
3712
|
}
|
|
@@ -3529,6 +3733,30 @@ variable "asset_bucket_name" {
|
|
|
3529
3733
|
type = string
|
|
3530
3734
|
}
|
|
3531
3735
|
|
|
3736
|
+
# VPC Configuration (optional)
|
|
3737
|
+
variable "enable_vpc" {
|
|
3738
|
+
description = "Deploy the Lambda function into a VPC. Set alongside vpc_id/subnet_ids."
|
|
3739
|
+
type = bool
|
|
3740
|
+
default = false
|
|
3741
|
+
}
|
|
3742
|
+
|
|
3743
|
+
variable "vpc_id" {
|
|
3744
|
+
description = "VPC ID to deploy the Lambda function into. Required when enable_vpc is true."
|
|
3745
|
+
type = string
|
|
3746
|
+
default = null
|
|
3747
|
+
|
|
3748
|
+
validation {
|
|
3749
|
+
condition = !var.enable_vpc || (var.vpc_id != null && var.subnet_ids != null)
|
|
3750
|
+
error_message = "vpc_id and subnet_ids must be set when enable_vpc is true."
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
|
|
3754
|
+
variable "subnet_ids" {
|
|
3755
|
+
description = "Subnet IDs to deploy the Lambda function into. Required when enable_vpc is true."
|
|
3756
|
+
type = list(string)
|
|
3757
|
+
default = null
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3532
3760
|
# CORS Configuration (passed to core module)
|
|
3533
3761
|
|
|
3534
3762
|
variable "cors_allow_headers" {
|
|
@@ -3625,9 +3853,31 @@ resource "aws_wafv2_web_acl_association" "api_waf_association" {
|
|
|
3625
3853
|
depends_on = [aws_api_gateway_stage.api_stage]
|
|
3626
3854
|
}
|
|
3627
3855
|
|
|
3856
|
+
# Security group for the API Lambda function, used when deployed into a VPC
|
|
3857
|
+
resource "aws_security_group" "api_lambda" {
|
|
3858
|
+
count = var.enable_vpc ? 1 : 0
|
|
3859
|
+
|
|
3860
|
+
#checkov:skip=CKV2_AWS_5:Attached to api_lambda via vpc_config block; Checkov cannot resolve this reference
|
|
3861
|
+
name_prefix = "custom-api-lambda-"
|
|
3862
|
+
description = "Security group for the CustomApi API Lambda function"
|
|
3863
|
+
vpc_id = var.vpc_id
|
|
3864
|
+
tags = var.tags
|
|
3865
|
+
}
|
|
3866
|
+
|
|
3867
|
+
resource "aws_vpc_security_group_egress_rule" "api_lambda_https" {
|
|
3868
|
+
count = var.enable_vpc ? 1 : 0
|
|
3869
|
+
|
|
3870
|
+
security_group_id = aws_security_group.api_lambda[0].id
|
|
3871
|
+
cidr_ipv4 = "0.0.0.0/0"
|
|
3872
|
+
from_port = 443
|
|
3873
|
+
to_port = 443
|
|
3874
|
+
ip_protocol = "tcp"
|
|
3875
|
+
description = "Allow outbound HTTPS to AWS service endpoints"
|
|
3876
|
+
}
|
|
3877
|
+
|
|
3628
3878
|
# Lambda function
|
|
3629
3879
|
resource "aws_lambda_function" "api_lambda" {
|
|
3630
|
-
#checkov:skip=CKV_AWS_117:Lambda function
|
|
3880
|
+
#checkov:skip=CKV_AWS_117:Lambda function is optionally deployed into a VPC via vpc_id/subnet_ids; not required for this use case
|
|
3631
3881
|
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
|
|
3632
3882
|
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
3633
3883
|
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
@@ -3649,6 +3899,14 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
3649
3899
|
mode = "Active"
|
|
3650
3900
|
}
|
|
3651
3901
|
|
|
3902
|
+
dynamic "vpc_config" {
|
|
3903
|
+
for_each = var.enable_vpc ? [1] : []
|
|
3904
|
+
content {
|
|
3905
|
+
subnet_ids = var.subnet_ids
|
|
3906
|
+
security_group_ids = [aws_security_group.api_lambda[0].id]
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
3909
|
+
|
|
3652
3910
|
|
|
3653
3911
|
environment {
|
|
3654
3912
|
variables = merge({
|
|
@@ -3656,6 +3914,8 @@ resource "aws_lambda_function" "api_lambda" {
|
|
|
3656
3914
|
}
|
|
3657
3915
|
|
|
3658
3916
|
tags = var.tags
|
|
3917
|
+
|
|
3918
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_vpc_access]
|
|
3659
3919
|
}
|
|
3660
3920
|
|
|
3661
3921
|
# IAM role for Lambda execution
|
|
@@ -3690,6 +3950,13 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
|
|
|
3690
3950
|
role = aws_iam_role.lambda_execution_role.name
|
|
3691
3951
|
}
|
|
3692
3952
|
|
|
3953
|
+
# Attach VPC access policy to Lambda role when deployed into a VPC
|
|
3954
|
+
resource "aws_iam_role_policy_attachment" "lambda_vpc_access" {
|
|
3955
|
+
count = var.enable_vpc ? 1 : 0
|
|
3956
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
|
|
3957
|
+
role = aws_iam_role.lambda_execution_role.name
|
|
3958
|
+
}
|
|
3959
|
+
|
|
3693
3960
|
# Additional IAM policies for Lambda (if provided)
|
|
3694
3961
|
resource "aws_iam_role_policy" "lambda_additional_policies" {
|
|
3695
3962
|
count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
|
|
@@ -4156,6 +4423,11 @@ output "lambda_execution_role_name" {
|
|
|
4156
4423
|
value = aws_iam_role.lambda_execution_role.name
|
|
4157
4424
|
}
|
|
4158
4425
|
|
|
4426
|
+
output "security_group_id" {
|
|
4427
|
+
description = "Security group ID of the API Lambda function, for use in ingress rules on resources it must reach (e.g. a database). Null unless enable_vpc is true."
|
|
4428
|
+
value = var.enable_vpc ? aws_security_group.api_lambda[0].id : null
|
|
4429
|
+
}
|
|
4430
|
+
|
|
4159
4431
|
# Integration Outputs
|
|
4160
4432
|
output "integration_id" {
|
|
4161
4433
|
description = "ID of the Lambda integration"
|
|
@@ -10,8 +10,8 @@ import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
|
|
|
10
10
|
import { Logger } from '@aws-lambda-powertools/logger';
|
|
11
11
|
import { Metrics } from '@aws-lambda-powertools/metrics';
|
|
12
12
|
import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
|
|
13
|
-
import { Service } from './service
|
|
14
|
-
import { get<%- apiNameClassName %>ServiceHandler } from './generated/ssdk/index
|
|
13
|
+
import { Service } from './service<% if (esm) { %>.js<% } %>';
|
|
14
|
+
import { get<%- apiNameClassName %>ServiceHandler } from './generated/ssdk/index<% if (esm) { %>.js<% } %>';
|
|
15
15
|
|
|
16
16
|
process.env.POWERTOOLS_METRICS_NAMESPACE = '<%- apiNameClassName %>';
|
|
17
17
|
process.env.POWERTOOLS_SERVICE_NAME = '<%- apiNameClassName %>';
|