@aws/nx-plugin 0.109.0 → 0.109.1

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 (32) hide show
  1. package/package.json +1 -1
  2. package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +167 -89
  3. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +72 -16
  4. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +11 -9
  5. package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +11 -9
  6. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +113 -61
  7. package/src/terraform/project/files/application/scripts/aws-config.ts.template +41 -0
  8. package/src/terraform/project/files/application/scripts/bootstrap.ts.template +91 -0
  9. package/src/terraform/project/files/application/scripts/init.ts.template +44 -0
  10. package/src/terraform/project/generator.js +16 -11
  11. package/src/terraform/project/generator.js.map +1 -1
  12. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +167 -89
  13. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +72 -16
  14. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +11 -9
  15. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +7 -0
  16. package/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap +11 -9
  17. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +14 -12
  18. package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +28 -15
  19. package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +29 -16
  20. package/src/utils/files/terraform/scripts/reset-runtime-config.ts.template +25 -0
  21. package/src/utils/files/terraform/src/core/asset-bucket/asset-bucket.tf.template +203 -0
  22. package/src/utils/files/terraform/src/core/runtime-config/appconfig/appconfig.tf.template +42 -39
  23. package/src/utils/files/terraform/src/core/runtime-config/appconfig-deployment/appconfig-deployment.tf.template +138 -0
  24. package/src/utils/files/terraform/src/core/runtime-config/entry/entry.tf.template +26 -90
  25. package/src/utils/files/terraform/src/core/runtime-config/read/read.tf.template +61 -5
  26. package/src/utils/function-constructs/files/terraform/app/lambda-functions/__functionNameKebabCase__/__functionNameKebabCase__.tf.template +35 -7
  27. package/src/utils/shared-constructs.js +4 -2
  28. package/src/utils/shared-constructs.js.map +1 -1
  29. package/src/utils/versions.d.ts +4 -1
  30. package/src/utils/versions.js +3 -0
  31. package/src/utils/versions.js.map +1 -1
  32. package/src/utils/website-constructs/files/terraform/core/static-website/static-website.tf.template +7 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "0.109.0",
3
+ "version": "0.109.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",
@@ -2205,6 +2205,11 @@ variable "additional_iam_policy_statements" {
2205
2205
  default = []
2206
2206
  }
2207
2207
 
2208
+ variable "asset_bucket_name" {
2209
+ description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
2210
+ type = string
2211
+ }
2212
+
2208
2213
  # CORS Configuration (passed to core module)
2209
2214
  variable "cors_allow_credentials" {
2210
2215
  description = "Whether to allow credentials in CORS requests"
@@ -2253,6 +2258,12 @@ variable "tags" {
2253
2258
  data "aws_region" "current" {}
2254
2259
  data "aws_caller_identity" "current" {}
2255
2260
 
2261
+ resource "random_string" "suffix" {
2262
+ length = 8
2263
+ special = false
2264
+ upper = false
2265
+ }
2266
+
2256
2267
  # Resources
2257
2268
 
2258
2269
  # Create Lambda ZIP file from the bundle directory
@@ -2262,12 +2273,20 @@ data "archive_file" "lambda_zip" {
2262
2273
  output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/lambda.zip"
2263
2274
  }
2264
2275
 
2276
+ resource "aws_s3_object" "lambda_zip" {
2277
+ bucket = var.asset_bucket_name
2278
+ key = "apis/test-api/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
2279
+ source = data.archive_file.lambda_zip.output_path
2280
+ source_hash = data.archive_file.lambda_zip.output_base64sha256
2281
+ etag = data.archive_file.lambda_zip.output_md5
2282
+ }
2283
+
2265
2284
 
2266
2285
  # Use the core HTTP API module
2267
2286
  module "http_api" {
2268
2287
  source = "../../../core/api/http-api"
2269
2288
 
2270
- api_name = "TestApi"
2289
+ api_name = "TestApi-\${random_string.suffix.result}"
2271
2290
  api_description = "TestApi HTTP API"
2272
2291
  stage_name = "$default"
2273
2292
  stage_auto_deploy = true
@@ -2292,8 +2311,10 @@ resource "aws_lambda_function" "api_lambda" {
2292
2311
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
2293
2312
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
2294
2313
  #checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
2295
- filename = data.archive_file.lambda_zip.output_path
2296
- function_name = "TestApiHandler"
2314
+ s3_bucket = aws_s3_object.lambda_zip.bucket
2315
+ s3_key = aws_s3_object.lambda_zip.key
2316
+ s3_object_version = aws_s3_object.lambda_zip.version_id
2317
+ function_name = "TestApiHandler-\${random_string.suffix.result}"
2297
2318
  role = aws_iam_role.lambda_execution_role.arn
2298
2319
  handler = "run.sh"
2299
2320
  runtime = "python3.14"
@@ -2327,7 +2348,7 @@ resource "aws_lambda_function" "api_lambda" {
2327
2348
 
2328
2349
  # IAM role for Lambda execution
2329
2350
  resource "aws_iam_role" "lambda_execution_role" {
2330
- name = "TestApiHandler-execution-role"
2351
+ name = "TestApiHandler-execution-role-\${random_string.suffix.result}"
2331
2352
 
2332
2353
  assume_role_policy = jsonencode({
2333
2354
  Version = "2012-10-17"
@@ -2360,7 +2381,7 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
2360
2381
  # Additional IAM policies for Lambda (if provided)
2361
2382
  resource "aws_iam_role_policy" "lambda_additional_policies" {
2362
2383
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
2363
- name = "TestApiHandler-additional-policies"
2384
+ name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
2364
2385
  role = aws_iam_role.lambda_execution_role.id
2365
2386
 
2366
2387
  policy = jsonencode({
@@ -2374,7 +2395,7 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
2374
2395
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
2375
2396
  #checkov:skip=CKV_AWS_338:Log retention set to forever
2376
2397
  #checkov:skip=CKV_AWS_66:Log retention set to forever
2377
- name = "/aws/lambda/TestApiHandler"
2398
+ name = "/aws/lambda/TestApiHandler-\${random_string.suffix.result}"
2378
2399
  tags = var.tags
2379
2400
  }
2380
2401
 
@@ -2392,7 +2413,7 @@ resource "aws_apigatewayv2_authorizer" "cognito_authorizer" {
2392
2413
  api_id = module.http_api.api_id
2393
2414
  authorizer_type = "JWT"
2394
2415
  identity_sources = ["$request.header.Authorization"]
2395
- name = "TestApiAuthorizer"
2416
+ name = "TestApiAuthorizer-\${random_string.suffix.result}"
2396
2417
 
2397
2418
  jwt_configuration {
2398
2419
  audience = var.user_pool_client_ids
@@ -2439,14 +2460,6 @@ module "add_url_to_runtime_config" {
2439
2460
  depends_on = [module.http_api]
2440
2461
  }
2441
2462
 
2442
- module "appconfig" {
2443
- source = "../../../core/runtime-config/appconfig"
2444
-
2445
- application_name = "TestApi-runtime-config"
2446
-
2447
- depends_on = [module.add_url_to_runtime_config]
2448
- }
2449
-
2450
2463
  # Lambda permission for API Gateway to invoke the function via alias
2451
2464
  resource "aws_lambda_permission" "api_gateway_invoke" {
2452
2465
  statement_id = "AllowExecutionFromAPIGateway"
@@ -2853,6 +2866,11 @@ variable "additional_iam_policy_statements" {
2853
2866
  default = []
2854
2867
  }
2855
2868
 
2869
+ variable "asset_bucket_name" {
2870
+ description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
2871
+ type = string
2872
+ }
2873
+
2856
2874
  # CORS Configuration (passed to core module)
2857
2875
  variable "cors_allow_credentials" {
2858
2876
  description = "Whether to allow credentials in CORS requests"
@@ -2901,6 +2919,12 @@ variable "tags" {
2901
2919
  data "aws_region" "current" {}
2902
2920
  data "aws_caller_identity" "current" {}
2903
2921
 
2922
+ resource "random_string" "suffix" {
2923
+ length = 8
2924
+ special = false
2925
+ upper = false
2926
+ }
2927
+
2904
2928
  # Resources
2905
2929
 
2906
2930
  # Create Lambda ZIP file from the bundle directory
@@ -2910,12 +2934,20 @@ data "archive_file" "lambda_zip" {
2910
2934
  output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/lambda.zip"
2911
2935
  }
2912
2936
 
2937
+ resource "aws_s3_object" "lambda_zip" {
2938
+ bucket = var.asset_bucket_name
2939
+ key = "apis/test-api/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
2940
+ source = data.archive_file.lambda_zip.output_path
2941
+ source_hash = data.archive_file.lambda_zip.output_base64sha256
2942
+ etag = data.archive_file.lambda_zip.output_md5
2943
+ }
2944
+
2913
2945
 
2914
2946
  # Use the core HTTP API module
2915
2947
  module "http_api" {
2916
2948
  source = "../../../core/api/http-api"
2917
2949
 
2918
- api_name = "TestApi"
2950
+ api_name = "TestApi-\${random_string.suffix.result}"
2919
2951
  api_description = "TestApi HTTP API"
2920
2952
  stage_name = "$default"
2921
2953
  stage_auto_deploy = true
@@ -2940,8 +2972,10 @@ resource "aws_lambda_function" "api_lambda" {
2940
2972
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
2941
2973
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
2942
2974
  #checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
2943
- filename = data.archive_file.lambda_zip.output_path
2944
- function_name = "TestApiHandler"
2975
+ s3_bucket = aws_s3_object.lambda_zip.bucket
2976
+ s3_key = aws_s3_object.lambda_zip.key
2977
+ s3_object_version = aws_s3_object.lambda_zip.version_id
2978
+ function_name = "TestApiHandler-\${random_string.suffix.result}"
2945
2979
  role = aws_iam_role.lambda_execution_role.arn
2946
2980
  handler = "run.sh"
2947
2981
  runtime = "python3.14"
@@ -2975,7 +3009,7 @@ resource "aws_lambda_function" "api_lambda" {
2975
3009
 
2976
3010
  # IAM role for Lambda execution
2977
3011
  resource "aws_iam_role" "lambda_execution_role" {
2978
- name = "TestApiHandler-execution-role"
3012
+ name = "TestApiHandler-execution-role-\${random_string.suffix.result}"
2979
3013
 
2980
3014
  assume_role_policy = jsonencode({
2981
3015
  Version = "2012-10-17"
@@ -3008,7 +3042,7 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
3008
3042
  # Additional IAM policies for Lambda (if provided)
3009
3043
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3010
3044
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
3011
- name = "TestApiHandler-additional-policies"
3045
+ name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
3012
3046
  role = aws_iam_role.lambda_execution_role.id
3013
3047
 
3014
3048
  policy = jsonencode({
@@ -3022,7 +3056,7 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
3022
3056
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
3023
3057
  #checkov:skip=CKV_AWS_338:Log retention set to forever
3024
3058
  #checkov:skip=CKV_AWS_66:Log retention set to forever
3025
- name = "/aws/lambda/TestApiHandler"
3059
+ name = "/aws/lambda/TestApiHandler-\${random_string.suffix.result}"
3026
3060
  tags = var.tags
3027
3061
  }
3028
3062
 
@@ -3074,14 +3108,6 @@ module "add_url_to_runtime_config" {
3074
3108
  depends_on = [module.http_api]
3075
3109
  }
3076
3110
 
3077
- module "appconfig" {
3078
- source = "../../../core/runtime-config/appconfig"
3079
-
3080
- application_name = "TestApi-runtime-config"
3081
-
3082
- depends_on = [module.add_url_to_runtime_config]
3083
- }
3084
-
3085
3111
  # Lambda permission for API Gateway to invoke the function via alias
3086
3112
  resource "aws_lambda_permission" "api_gateway_invoke" {
3087
3113
  statement_id = "AllowExecutionFromAPIGateway"
@@ -3488,6 +3514,11 @@ variable "additional_iam_policy_statements" {
3488
3514
  default = []
3489
3515
  }
3490
3516
 
3517
+ variable "asset_bucket_name" {
3518
+ description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
3519
+ type = string
3520
+ }
3521
+
3491
3522
  # CORS Configuration (passed to core module)
3492
3523
  variable "cors_allow_credentials" {
3493
3524
  description = "Whether to allow credentials in CORS requests"
@@ -3536,6 +3567,12 @@ variable "tags" {
3536
3567
  data "aws_region" "current" {}
3537
3568
  data "aws_caller_identity" "current" {}
3538
3569
 
3570
+ resource "random_string" "suffix" {
3571
+ length = 8
3572
+ special = false
3573
+ upper = false
3574
+ }
3575
+
3539
3576
  # Resources
3540
3577
 
3541
3578
  # Create Lambda ZIP file from the bundle directory
@@ -3545,12 +3582,20 @@ data "archive_file" "lambda_zip" {
3545
3582
  output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/lambda.zip"
3546
3583
  }
3547
3584
 
3585
+ resource "aws_s3_object" "lambda_zip" {
3586
+ bucket = var.asset_bucket_name
3587
+ key = "apis/test-api/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
3588
+ source = data.archive_file.lambda_zip.output_path
3589
+ source_hash = data.archive_file.lambda_zip.output_base64sha256
3590
+ etag = data.archive_file.lambda_zip.output_md5
3591
+ }
3592
+
3548
3593
 
3549
3594
  # Use the core HTTP API module
3550
3595
  module "http_api" {
3551
3596
  source = "../../../core/api/http-api"
3552
3597
 
3553
- api_name = "TestApi"
3598
+ api_name = "TestApi-\${random_string.suffix.result}"
3554
3599
  api_description = "TestApi HTTP API"
3555
3600
  stage_name = "$default"
3556
3601
  stage_auto_deploy = true
@@ -3575,8 +3620,10 @@ resource "aws_lambda_function" "api_lambda" {
3575
3620
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
3576
3621
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
3577
3622
  #checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
3578
- filename = data.archive_file.lambda_zip.output_path
3579
- function_name = "TestApiHandler"
3623
+ s3_bucket = aws_s3_object.lambda_zip.bucket
3624
+ s3_key = aws_s3_object.lambda_zip.key
3625
+ s3_object_version = aws_s3_object.lambda_zip.version_id
3626
+ function_name = "TestApiHandler-\${random_string.suffix.result}"
3580
3627
  role = aws_iam_role.lambda_execution_role.arn
3581
3628
  handler = "run.sh"
3582
3629
  runtime = "python3.14"
@@ -3610,7 +3657,7 @@ resource "aws_lambda_function" "api_lambda" {
3610
3657
 
3611
3658
  # IAM role for Lambda execution
3612
3659
  resource "aws_iam_role" "lambda_execution_role" {
3613
- name = "TestApiHandler-execution-role"
3660
+ name = "TestApiHandler-execution-role-\${random_string.suffix.result}"
3614
3661
 
3615
3662
  assume_role_policy = jsonencode({
3616
3663
  Version = "2012-10-17"
@@ -3643,7 +3690,7 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
3643
3690
  # Additional IAM policies for Lambda (if provided)
3644
3691
  resource "aws_iam_role_policy" "lambda_additional_policies" {
3645
3692
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
3646
- name = "TestApiHandler-additional-policies"
3693
+ name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
3647
3694
  role = aws_iam_role.lambda_execution_role.id
3648
3695
 
3649
3696
  policy = jsonencode({
@@ -3657,7 +3704,7 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
3657
3704
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
3658
3705
  #checkov:skip=CKV_AWS_338:Log retention set to forever
3659
3706
  #checkov:skip=CKV_AWS_66:Log retention set to forever
3660
- name = "/aws/lambda/TestApiHandler"
3707
+ name = "/aws/lambda/TestApiHandler-\${random_string.suffix.result}"
3661
3708
  tags = var.tags
3662
3709
  }
3663
3710
 
@@ -3711,14 +3758,6 @@ module "add_url_to_runtime_config" {
3711
3758
  depends_on = [module.http_api]
3712
3759
  }
3713
3760
 
3714
- module "appconfig" {
3715
- source = "../../../core/runtime-config/appconfig"
3716
-
3717
- application_name = "TestApi-runtime-config"
3718
-
3719
- depends_on = [module.add_url_to_runtime_config]
3720
- }
3721
-
3722
3761
  # Lambda permission for API Gateway to invoke the function via alias
3723
3762
  resource "aws_lambda_permission" "api_gateway_invoke" {
3724
3763
  statement_id = "AllowExecutionFromAPIGateway"
@@ -4150,6 +4189,11 @@ variable "additional_iam_policy_statements" {
4150
4189
  default = []
4151
4190
  }
4152
4191
 
4192
+ variable "asset_bucket_name" {
4193
+ description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
4194
+ type = string
4195
+ }
4196
+
4153
4197
  # CORS Configuration (passed to core module)
4154
4198
 
4155
4199
  variable "cors_allow_headers" {
@@ -4188,20 +4232,34 @@ variable "tags" {
4188
4232
  data "aws_region" "current" {}
4189
4233
  data "aws_caller_identity" "current" {}
4190
4234
 
4235
+ resource "random_string" "suffix" {
4236
+ length = 8
4237
+ special = false
4238
+ upper = false
4239
+ }
4240
+
4191
4241
  # Resources
4192
4242
 
4193
- # Create Lambda ZIP file from the FastAPI bundle directory
4243
+ # Create Lambda ZIP file from the bundle directory
4194
4244
  data "archive_file" "lambda_zip" {
4195
4245
  type = "zip"
4196
4246
  source_dir = "\${path.module}/../../../../../../../dist/apps/test_api/bundle-x86"
4197
4247
  output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/lambda.zip"
4198
4248
  }
4199
4249
 
4250
+ resource "aws_s3_object" "lambda_zip" {
4251
+ bucket = var.asset_bucket_name
4252
+ key = "apis/test-api/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
4253
+ source = data.archive_file.lambda_zip.output_path
4254
+ source_hash = data.archive_file.lambda_zip.output_base64sha256
4255
+ etag = data.archive_file.lambda_zip.output_md5
4256
+ }
4257
+
4200
4258
  # Use the core REST API module
4201
4259
  module "rest_api" {
4202
4260
  source = "../../../core/api/rest-api"
4203
4261
 
4204
- api_name = "TestApi"
4262
+ api_name = "TestApi-\${random_string.suffix.result}"
4205
4263
  api_description = "TestApi REST API"
4206
4264
  stage_name = "prod"
4207
4265
  stage_auto_deploy = true
@@ -4234,8 +4292,10 @@ resource "aws_lambda_function" "api_lambda" {
4234
4292
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
4235
4293
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
4236
4294
  #checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
4237
- filename = data.archive_file.lambda_zip.output_path
4238
- function_name = "TestApiHandler"
4295
+ s3_bucket = aws_s3_object.lambda_zip.bucket
4296
+ s3_key = aws_s3_object.lambda_zip.key
4297
+ s3_object_version = aws_s3_object.lambda_zip.version_id
4298
+ function_name = "TestApiHandler-\${random_string.suffix.result}"
4239
4299
  role = aws_iam_role.lambda_execution_role.arn
4240
4300
  handler = "run.sh"
4241
4301
  runtime = "python3.14"
@@ -4269,7 +4329,7 @@ resource "aws_lambda_function" "api_lambda" {
4269
4329
 
4270
4330
  # IAM role for Lambda execution
4271
4331
  resource "aws_iam_role" "lambda_execution_role" {
4272
- name = "TestApiHandler-execution-role"
4332
+ name = "TestApiHandler-execution-role-\${random_string.suffix.result}"
4273
4333
 
4274
4334
  assume_role_policy = jsonencode({
4275
4335
  Version = "2012-10-17"
@@ -4302,7 +4362,7 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
4302
4362
  # Additional IAM policies for Lambda (if provided)
4303
4363
  resource "aws_iam_role_policy" "lambda_additional_policies" {
4304
4364
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
4305
- name = "TestApiHandler-additional-policies"
4365
+ name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
4306
4366
  role = aws_iam_role.lambda_execution_role.id
4307
4367
 
4308
4368
  policy = jsonencode({
@@ -4316,7 +4376,7 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
4316
4376
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
4317
4377
  #checkov:skip=CKV_AWS_338:Log retention set to forever
4318
4378
  #checkov:skip=CKV_AWS_66:Log retention set to forever
4319
- name = "/aws/lambda/TestApiHandler"
4379
+ name = "/aws/lambda/TestApiHandler-\${random_string.suffix.result}"
4320
4380
  tags = var.tags
4321
4381
  }
4322
4382
 
@@ -4331,7 +4391,7 @@ resource "aws_lambda_alias" "live" {
4331
4391
 
4332
4392
  # Cognito User Pool Authorizer
4333
4393
  resource "aws_api_gateway_authorizer" "cognito_authorizer" {
4334
- name = "TestApiAuthorizer"
4394
+ name = "TestApiAuthorizer-\${random_string.suffix.result}"
4335
4395
  rest_api_id = module.rest_api.api_id
4336
4396
  type = "COGNITO_USER_POOLS"
4337
4397
  provider_arns = ["arn:aws:cognito-idp:\${data.aws_region.current.name}:\${data.aws_caller_identity.current.account_id}:userpool/\${var.user_pool_id}"]
@@ -4525,14 +4585,6 @@ module "add_url_to_runtime_config" {
4525
4585
  depends_on = [aws_api_gateway_stage.api_stage]
4526
4586
  }
4527
4587
 
4528
- module "appconfig" {
4529
- source = "../../../core/runtime-config/appconfig"
4530
-
4531
- application_name = "TestApi-runtime-config"
4532
-
4533
- depends_on = [module.add_url_to_runtime_config]
4534
- }
4535
-
4536
4588
  # Outputs
4537
4589
 
4538
4590
  # API Gateway Outputs (from core module)
@@ -4953,6 +5005,11 @@ variable "additional_iam_policy_statements" {
4953
5005
  default = []
4954
5006
  }
4955
5007
 
5008
+ variable "asset_bucket_name" {
5009
+ description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
5010
+ type = string
5011
+ }
5012
+
4956
5013
  # CORS Configuration (passed to core module)
4957
5014
 
4958
5015
  variable "cors_allow_headers" {
@@ -4991,20 +5048,34 @@ variable "tags" {
4991
5048
  data "aws_region" "current" {}
4992
5049
  data "aws_caller_identity" "current" {}
4993
5050
 
5051
+ resource "random_string" "suffix" {
5052
+ length = 8
5053
+ special = false
5054
+ upper = false
5055
+ }
5056
+
4994
5057
  # Resources
4995
5058
 
4996
- # Create Lambda ZIP file from the FastAPI bundle directory
5059
+ # Create Lambda ZIP file from the bundle directory
4997
5060
  data "archive_file" "lambda_zip" {
4998
5061
  type = "zip"
4999
5062
  source_dir = "\${path.module}/../../../../../../../dist/apps/test_api/bundle-x86"
5000
5063
  output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/lambda.zip"
5001
5064
  }
5002
5065
 
5066
+ resource "aws_s3_object" "lambda_zip" {
5067
+ bucket = var.asset_bucket_name
5068
+ key = "apis/test-api/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
5069
+ source = data.archive_file.lambda_zip.output_path
5070
+ source_hash = data.archive_file.lambda_zip.output_base64sha256
5071
+ etag = data.archive_file.lambda_zip.output_md5
5072
+ }
5073
+
5003
5074
  # Use the core REST API module
5004
5075
  module "rest_api" {
5005
5076
  source = "../../../core/api/rest-api"
5006
5077
 
5007
- api_name = "TestApi"
5078
+ api_name = "TestApi-\${random_string.suffix.result}"
5008
5079
  api_description = "TestApi REST API"
5009
5080
  stage_name = "prod"
5010
5081
  stage_auto_deploy = true
@@ -5037,8 +5108,10 @@ resource "aws_lambda_function" "api_lambda" {
5037
5108
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
5038
5109
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
5039
5110
  #checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
5040
- filename = data.archive_file.lambda_zip.output_path
5041
- function_name = "TestApiHandler"
5111
+ s3_bucket = aws_s3_object.lambda_zip.bucket
5112
+ s3_key = aws_s3_object.lambda_zip.key
5113
+ s3_object_version = aws_s3_object.lambda_zip.version_id
5114
+ function_name = "TestApiHandler-\${random_string.suffix.result}"
5042
5115
  role = aws_iam_role.lambda_execution_role.arn
5043
5116
  handler = "run.sh"
5044
5117
  runtime = "python3.14"
@@ -5072,7 +5145,7 @@ resource "aws_lambda_function" "api_lambda" {
5072
5145
 
5073
5146
  # IAM role for Lambda execution
5074
5147
  resource "aws_iam_role" "lambda_execution_role" {
5075
- name = "TestApiHandler-execution-role"
5148
+ name = "TestApiHandler-execution-role-\${random_string.suffix.result}"
5076
5149
 
5077
5150
  assume_role_policy = jsonencode({
5078
5151
  Version = "2012-10-17"
@@ -5105,7 +5178,7 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
5105
5178
  # Additional IAM policies for Lambda (if provided)
5106
5179
  resource "aws_iam_role_policy" "lambda_additional_policies" {
5107
5180
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
5108
- name = "TestApiHandler-additional-policies"
5181
+ name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
5109
5182
  role = aws_iam_role.lambda_execution_role.id
5110
5183
 
5111
5184
  policy = jsonencode({
@@ -5119,7 +5192,7 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
5119
5192
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
5120
5193
  #checkov:skip=CKV_AWS_338:Log retention set to forever
5121
5194
  #checkov:skip=CKV_AWS_66:Log retention set to forever
5122
- name = "/aws/lambda/TestApiHandler"
5195
+ name = "/aws/lambda/TestApiHandler-\${random_string.suffix.result}"
5123
5196
  tags = var.tags
5124
5197
  }
5125
5198
 
@@ -5330,14 +5403,6 @@ module "add_url_to_runtime_config" {
5330
5403
  depends_on = [aws_api_gateway_stage.api_stage]
5331
5404
  }
5332
5405
 
5333
- module "appconfig" {
5334
- source = "../../../core/runtime-config/appconfig"
5335
-
5336
- application_name = "TestApi-runtime-config"
5337
-
5338
- depends_on = [module.add_url_to_runtime_config]
5339
- }
5340
-
5341
5406
  # Outputs
5342
5407
 
5343
5408
  # API Gateway Outputs (from core module)
@@ -5758,6 +5823,11 @@ variable "additional_iam_policy_statements" {
5758
5823
  default = []
5759
5824
  }
5760
5825
 
5826
+ variable "asset_bucket_name" {
5827
+ description = "Name of the shared asset S3 bucket used to stage the Lambda deployment zip. Instantiate the \`core/asset-bucket\` module once per deployment and pass its \`bucket_name\` output here."
5828
+ type = string
5829
+ }
5830
+
5761
5831
  # CORS Configuration (passed to core module)
5762
5832
 
5763
5833
  variable "cors_allow_headers" {
@@ -5796,20 +5866,34 @@ variable "tags" {
5796
5866
  data "aws_region" "current" {}
5797
5867
  data "aws_caller_identity" "current" {}
5798
5868
 
5869
+ resource "random_string" "suffix" {
5870
+ length = 8
5871
+ special = false
5872
+ upper = false
5873
+ }
5874
+
5799
5875
  # Resources
5800
5876
 
5801
- # Create Lambda ZIP file from the FastAPI bundle directory
5877
+ # Create Lambda ZIP file from the bundle directory
5802
5878
  data "archive_file" "lambda_zip" {
5803
5879
  type = "zip"
5804
5880
  source_dir = "\${path.module}/../../../../../../../dist/apps/test_api/bundle-x86"
5805
5881
  output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/apis/test-api/lambda.zip"
5806
5882
  }
5807
5883
 
5884
+ resource "aws_s3_object" "lambda_zip" {
5885
+ bucket = var.asset_bucket_name
5886
+ key = "apis/test-api/\${data.archive_file.lambda_zip.output_base64sha256}.zip"
5887
+ source = data.archive_file.lambda_zip.output_path
5888
+ source_hash = data.archive_file.lambda_zip.output_base64sha256
5889
+ etag = data.archive_file.lambda_zip.output_md5
5890
+ }
5891
+
5808
5892
  # Use the core REST API module
5809
5893
  module "rest_api" {
5810
5894
  source = "../../../core/api/rest-api"
5811
5895
 
5812
- api_name = "TestApi"
5896
+ api_name = "TestApi-\${random_string.suffix.result}"
5813
5897
  api_description = "TestApi REST API"
5814
5898
  stage_name = "prod"
5815
5899
  stage_auto_deploy = true
@@ -5842,8 +5926,10 @@ resource "aws_lambda_function" "api_lambda" {
5842
5926
  #checkov:skip=CKV_AWS_272:Code signing not required for this use case
5843
5927
  #checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
5844
5928
  #checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
5845
- filename = data.archive_file.lambda_zip.output_path
5846
- function_name = "TestApiHandler"
5929
+ s3_bucket = aws_s3_object.lambda_zip.bucket
5930
+ s3_key = aws_s3_object.lambda_zip.key
5931
+ s3_object_version = aws_s3_object.lambda_zip.version_id
5932
+ function_name = "TestApiHandler-\${random_string.suffix.result}"
5847
5933
  role = aws_iam_role.lambda_execution_role.arn
5848
5934
  handler = "run.sh"
5849
5935
  runtime = "python3.14"
@@ -5877,7 +5963,7 @@ resource "aws_lambda_function" "api_lambda" {
5877
5963
 
5878
5964
  # IAM role for Lambda execution
5879
5965
  resource "aws_iam_role" "lambda_execution_role" {
5880
- name = "TestApiHandler-execution-role"
5966
+ name = "TestApiHandler-execution-role-\${random_string.suffix.result}"
5881
5967
 
5882
5968
  assume_role_policy = jsonencode({
5883
5969
  Version = "2012-10-17"
@@ -5910,7 +5996,7 @@ resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
5910
5996
  # Additional IAM policies for Lambda (if provided)
5911
5997
  resource "aws_iam_role_policy" "lambda_additional_policies" {
5912
5998
  count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
5913
- name = "TestApiHandler-additional-policies"
5999
+ name = "TestApiHandler-additional-policies-\${random_string.suffix.result}"
5914
6000
  role = aws_iam_role.lambda_execution_role.id
5915
6001
 
5916
6002
  policy = jsonencode({
@@ -5924,7 +6010,7 @@ resource "aws_cloudwatch_log_group" "lambda_logs" {
5924
6010
  #checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
5925
6011
  #checkov:skip=CKV_AWS_338:Log retention set to forever
5926
6012
  #checkov:skip=CKV_AWS_66:Log retention set to forever
5927
- name = "/aws/lambda/TestApiHandler"
6013
+ name = "/aws/lambda/TestApiHandler-\${random_string.suffix.result}"
5928
6014
  tags = var.tags
5929
6015
  }
5930
6016
 
@@ -6126,14 +6212,6 @@ module "add_url_to_runtime_config" {
6126
6212
  depends_on = [aws_api_gateway_stage.api_stage]
6127
6213
  }
6128
6214
 
6129
- module "appconfig" {
6130
- source = "../../../core/runtime-config/appconfig"
6131
-
6132
- application_name = "TestApi-runtime-config"
6133
-
6134
- depends_on = [module.add_url_to_runtime_config]
6135
- }
6136
-
6137
6215
  # Outputs
6138
6216
 
6139
6217
  # API Gateway Outputs (from core module)