@aws/nx-plugin 0.46.0 → 0.47.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.
- package/package.json +1 -1
- package/src/infra/app/generator.js +4 -1
- package/src/infra/app/generator.js.map +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +60 -0
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +310 -0
- package/src/py/lambda-function/generator.js +15 -25
- package/src/py/lambda-function/generator.js.map +1 -1
- package/src/py/lambda-function/schema.d.ts +1 -0
- package/src/py/lambda-function/schema.json +8 -0
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +60 -0
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +310 -0
- package/src/ts/lambda-function/generator.js +15 -27
- package/src/ts/lambda-function/generator.js.map +1 -1
- package/src/ts/lambda-function/schema.d.ts +1 -0
- package/src/ts/lambda-function/schema.json +8 -0
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +756 -0
- package/src/ts/react-website/app/generator.js +42 -43
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/ts/react-website/app/schema.d.ts +1 -0
- package/src/ts/react-website/app/schema.json +8 -0
- package/src/ts/react-website/cognito-auth/__snapshots__/generator.spec.ts.snap +259 -0
- package/src/ts/react-website/cognito-auth/generator.js +10 -13
- package/src/ts/react-website/cognito-auth/generator.js.map +1 -1
- package/src/ts/react-website/cognito-auth/schema.d.ts +1 -0
- package/src/ts/react-website/cognito-auth/schema.json +8 -0
- package/src/ts/react-website/runtime-config/__snapshots__/generator.spec.ts.snap +0 -40
- package/src/ts/react-website/runtime-config/generator.js +0 -2
- package/src/ts/react-website/runtime-config/generator.js.map +1 -1
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +10 -0
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +10 -0
- package/src/utils/files/terraform/src/core/runtime-config/entry/entry.tf.template +119 -0
- package/src/utils/files/terraform/src/core/runtime-config/read/read.tf.template +28 -0
- package/src/{py/lambda-function/files/common/constructs/src/app/lambda-functions/__constructFunctionKebabCase__.ts.template → utils/function-constructs/files/cdk/app/lambda-functions/__functionNameKebabCase__.ts.template} +5 -5
- package/src/utils/function-constructs/files/terraform/app/lambda-functions/__functionNameKebabCase__/__functionNameKebabCase__.tf.template +150 -0
- package/src/utils/function-constructs/function-constructs.d.ts +19 -0
- package/src/utils/function-constructs/function-constructs.js +57 -0
- package/src/utils/function-constructs/function-constructs.js.map +1 -0
- package/src/utils/identity-constructs/files/terraform/core/user-identity/add-callback-url/add-callback-url.tf.template +123 -0
- package/src/utils/identity-constructs/files/terraform/core/user-identity/identity/identity.tf.template +421 -0
- package/src/utils/identity-constructs/files/terraform/core/user-identity/main.tf.template +47 -0
- package/src/utils/identity-constructs/identity-constructs.d.ts +15 -0
- package/src/utils/identity-constructs/identity-constructs.js +84 -0
- package/src/utils/identity-constructs/identity-constructs.js.map +1 -0
- package/src/utils/metrics.js +1 -1
- package/src/utils/metrics.js.map +1 -1
- package/src/utils/shared-constructs.js +24 -0
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/website-constructs/files/terraform/app/static-websites/__websiteNameKebabCase__/__websiteNameKebabCase__.tf.template +42 -0
- package/src/utils/website-constructs/files/terraform/core/static-website/static-website.tf.template +709 -0
- package/src/utils/website-constructs/website-constructs.d.ts +18 -0
- package/src/utils/website-constructs/website-constructs.js +61 -0
- package/src/utils/website-constructs/website-constructs.js.map +1 -0
- package/src/ts/lambda-function/files/common/constructs/src/app/lambda-functions/__constructFunctionNameKebabCase__.ts.template +0 -24
- /package/src/{ts/react-website/cognito-auth/files/common/constructs/src → utils/identity-constructs/files/cdk}/core/user-identity.ts.template +0 -0
- /package/src/{ts/react-website/app/files/common/constructs/src → utils/website-constructs/files/cdk}/app/static-websites/__websiteNameKebabCase__.ts.template +0 -0
- /package/src/{ts/react-website/app/files/common/constructs/src → utils/website-constructs/files/cdk}/core/static-website.ts.template +0 -0
|
@@ -2511,6 +2511,16 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
2511
2511
|
depends_on = [aws_apigatewayv2_integration.lambda_integration, aws_apigatewayv2_authorizer.cognito_authorizer]
|
|
2512
2512
|
}
|
|
2513
2513
|
|
|
2514
|
+
# Add API url to runtime config
|
|
2515
|
+
module "add_url_to_runtime_config" {
|
|
2516
|
+
source = "../../../core/runtime-config/entry"
|
|
2517
|
+
|
|
2518
|
+
key_path = "apis.TestApi"
|
|
2519
|
+
value = module.http_api.stage_invoke_url
|
|
2520
|
+
|
|
2521
|
+
depends_on = [module.http_api]
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2514
2524
|
# Lambda permission for API Gateway to invoke the function
|
|
2515
2525
|
resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
2516
2526
|
statement_id = "AllowExecutionFromAPIGateway"
|
|
@@ -3108,6 +3118,16 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
3108
3118
|
depends_on = [aws_apigatewayv2_integration.lambda_integration]
|
|
3109
3119
|
}
|
|
3110
3120
|
|
|
3121
|
+
# Add API url to runtime config
|
|
3122
|
+
module "add_url_to_runtime_config" {
|
|
3123
|
+
source = "../../../core/runtime-config/entry"
|
|
3124
|
+
|
|
3125
|
+
key_path = "apis.TestApi"
|
|
3126
|
+
value = module.http_api.stage_invoke_url
|
|
3127
|
+
|
|
3128
|
+
depends_on = [module.http_api]
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3111
3131
|
# Lambda permission for API Gateway to invoke the function
|
|
3112
3132
|
resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
3113
3133
|
statement_id = "AllowExecutionFromAPIGateway"
|
|
@@ -3707,6 +3727,16 @@ resource "aws_apigatewayv2_route" "proxy_routes" {
|
|
|
3707
3727
|
depends_on = [aws_apigatewayv2_integration.lambda_integration]
|
|
3708
3728
|
}
|
|
3709
3729
|
|
|
3730
|
+
# Add API url to runtime config
|
|
3731
|
+
module "add_url_to_runtime_config" {
|
|
3732
|
+
source = "../../../core/runtime-config/entry"
|
|
3733
|
+
|
|
3734
|
+
key_path = "apis.TestApi"
|
|
3735
|
+
value = module.http_api.stage_invoke_url
|
|
3736
|
+
|
|
3737
|
+
depends_on = [module.http_api]
|
|
3738
|
+
}
|
|
3739
|
+
|
|
3710
3740
|
# Lambda permission for API Gateway to invoke the function
|
|
3711
3741
|
resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
3712
3742
|
statement_id = "AllowExecutionFromAPIGateway"
|
|
@@ -4333,6 +4363,16 @@ resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
|
4333
4363
|
depends_on = [module.rest_api, aws_lambda_function.api_lambda]
|
|
4334
4364
|
}
|
|
4335
4365
|
|
|
4366
|
+
# Add API url to runtime config
|
|
4367
|
+
module "add_url_to_runtime_config" {
|
|
4368
|
+
source = "../../../core/runtime-config/entry"
|
|
4369
|
+
|
|
4370
|
+
key_path = "apis.TestApi"
|
|
4371
|
+
value = aws_api_gateway_stage.api_stage.invoke_url
|
|
4372
|
+
|
|
4373
|
+
depends_on = [aws_api_gateway_stage.api_stage]
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4336
4376
|
# Outputs
|
|
4337
4377
|
|
|
4338
4378
|
# API Gateway Outputs (from core module)
|
|
@@ -4951,6 +4991,16 @@ resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
|
4951
4991
|
depends_on = [module.rest_api, aws_lambda_function.api_lambda]
|
|
4952
4992
|
}
|
|
4953
4993
|
|
|
4994
|
+
# Add API url to runtime config
|
|
4995
|
+
module "add_url_to_runtime_config" {
|
|
4996
|
+
source = "../../../core/runtime-config/entry"
|
|
4997
|
+
|
|
4998
|
+
key_path = "apis.TestApi"
|
|
4999
|
+
value = aws_api_gateway_stage.api_stage.invoke_url
|
|
5000
|
+
|
|
5001
|
+
depends_on = [aws_api_gateway_stage.api_stage]
|
|
5002
|
+
}
|
|
5003
|
+
|
|
4954
5004
|
# Outputs
|
|
4955
5005
|
|
|
4956
5006
|
# API Gateway Outputs (from core module)
|
|
@@ -5560,6 +5610,16 @@ resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
|
5560
5610
|
depends_on = [module.rest_api, aws_lambda_function.api_lambda]
|
|
5561
5611
|
}
|
|
5562
5612
|
|
|
5613
|
+
# Add API url to runtime config
|
|
5614
|
+
module "add_url_to_runtime_config" {
|
|
5615
|
+
source = "../../../core/runtime-config/entry"
|
|
5616
|
+
|
|
5617
|
+
key_path = "apis.TestApi"
|
|
5618
|
+
value = aws_api_gateway_stage.api_stage.invoke_url
|
|
5619
|
+
|
|
5620
|
+
depends_on = [aws_api_gateway_stage.api_stage]
|
|
5621
|
+
}
|
|
5622
|
+
|
|
5563
5623
|
# Outputs
|
|
5564
5624
|
|
|
5565
5625
|
# API Gateway Outputs (from core module)
|
|
@@ -221,6 +221,7 @@ exports[`trpc react generator > should modify main.tsx correctly > main.tsx 1`]
|
|
|
221
221
|
"import TestApiClientProvider from './components/TestApiClientProvider';
|
|
222
222
|
import QueryClientProvider from './components/QueryClientProvider';
|
|
223
223
|
import RuntimeConfigProvider from './components/RuntimeConfig';
|
|
224
|
+
|
|
224
225
|
import { RouterProvider } from '@tanstack/react-router';
|
|
225
226
|
|
|
226
227
|
const App = () => <RouterProvider router={router} />;
|
|
@@ -132,3 +132,313 @@ export const handler = middy()
|
|
|
132
132
|
.handler(testFunction);
|
|
133
133
|
"
|
|
134
134
|
`;
|
|
135
|
+
|
|
136
|
+
exports[`ts-lambda-function generator > terraform iacProvider > should generate terraform files for lambda function and snapshot them > terraform-lambda-files 1`] = `
|
|
137
|
+
{
|
|
138
|
+
"test-project-test-function.tf": "variable "tags" {
|
|
139
|
+
description = "Tags to apply to resources"
|
|
140
|
+
type = map(string)
|
|
141
|
+
default = {}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
variable "env" {
|
|
145
|
+
description = "Additional environment variables for the Lambda function"
|
|
146
|
+
type = map(string)
|
|
147
|
+
default = {}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
variable "additional_iam_policy_statements" {
|
|
151
|
+
description = "Additional IAM policy statements to attach to the Lambda role"
|
|
152
|
+
type = list(object({
|
|
153
|
+
Effect = string
|
|
154
|
+
Action = list(string)
|
|
155
|
+
Resource = list(string)
|
|
156
|
+
}))
|
|
157
|
+
default = []
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
data "aws_caller_identity" "current" {}
|
|
161
|
+
data "aws_region" "current" {}
|
|
162
|
+
|
|
163
|
+
locals {
|
|
164
|
+
aws_account_id = data.aws_caller_identity.current.account_id
|
|
165
|
+
aws_region = data.aws_region.current.name
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
resource "random_string" "suffix" {
|
|
169
|
+
length = 8
|
|
170
|
+
special = false
|
|
171
|
+
upper = false
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
resource "aws_iam_role" "lambda_role" {
|
|
175
|
+
name = "test-project-test-function-role-\${random_string.suffix.result}"
|
|
176
|
+
|
|
177
|
+
assume_role_policy = jsonencode({
|
|
178
|
+
Version = "2012-10-17"
|
|
179
|
+
Statement = [
|
|
180
|
+
{
|
|
181
|
+
Sid = "LambdaAssumeRolePolicy"
|
|
182
|
+
Effect = "Allow"
|
|
183
|
+
Principal = {
|
|
184
|
+
Service = "lambda.amazonaws.com"
|
|
185
|
+
}
|
|
186
|
+
Action = "sts:AssumeRole"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
tags = var.tags
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
resource "aws_iam_policy" "lambda_policy" {
|
|
195
|
+
name = "test-project-test-function-policy-\${random_string.suffix.result}"
|
|
196
|
+
description = "Policy for test-project-test-function Lambda function"
|
|
197
|
+
|
|
198
|
+
policy = jsonencode({
|
|
199
|
+
Version = "2012-10-17"
|
|
200
|
+
Statement = concat([
|
|
201
|
+
{
|
|
202
|
+
Sid = "CloudWatchLogsAccess"
|
|
203
|
+
Effect = "Allow"
|
|
204
|
+
Action = [
|
|
205
|
+
"logs:CreateLogGroup",
|
|
206
|
+
"logs:CreateLogStream",
|
|
207
|
+
"logs:PutLogEvents"
|
|
208
|
+
]
|
|
209
|
+
Resource = [
|
|
210
|
+
"arn:aws:logs:\${local.aws_region}:\${local.aws_account_id}:log-group:/aws/lambda/test-project-test-function-\${random_string.suffix.result}:*"
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
Sid = "XRayAccess"
|
|
215
|
+
Effect = "Allow"
|
|
216
|
+
Action = [
|
|
217
|
+
"xray:PutTraceSegments",
|
|
218
|
+
"xray:PutTelemetryRecords"
|
|
219
|
+
]
|
|
220
|
+
Resource = ["*"]
|
|
221
|
+
}
|
|
222
|
+
], var.additional_iam_policy_statements)
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
tags = var.tags
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
# Attach the policy to the role
|
|
229
|
+
resource "aws_iam_role_policy_attachment" "lambda_policy_attachment" {
|
|
230
|
+
role = aws_iam_role.lambda_role.name
|
|
231
|
+
policy_arn = aws_iam_policy.lambda_policy.arn
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
data "archive_file" "lambda_zip" {
|
|
235
|
+
type = "zip"
|
|
236
|
+
source_dir = "\${path.module}/../../../../../../../dist/packages/test-project/bundle-test-function"
|
|
237
|
+
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/lambda-functions/test-project-test-function/lambda.zip"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
resource "aws_lambda_function" "lambda_function" {
|
|
241
|
+
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
242
|
+
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple use case
|
|
243
|
+
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
244
|
+
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
245
|
+
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
246
|
+
filename = data.archive_file.lambda_zip.output_path
|
|
247
|
+
function_name = "test-project-test-function-\${random_string.suffix.result}"
|
|
248
|
+
role = aws_iam_role.lambda_role.arn
|
|
249
|
+
handler = "index.handler"
|
|
250
|
+
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
251
|
+
runtime = "nodejs22.x"
|
|
252
|
+
timeout = 30
|
|
253
|
+
|
|
254
|
+
tracing_config {
|
|
255
|
+
mode = "Active"
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
environment {
|
|
259
|
+
variables = merge({
|
|
260
|
+
AWS_CONNECTION_REUSE_ENABLED = "1"
|
|
261
|
+
}, var.env)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
tags = var.tags
|
|
265
|
+
|
|
266
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_policy_attachment]
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
output "function_name" {
|
|
270
|
+
description = "Name of the Lambda function"
|
|
271
|
+
value = aws_lambda_function.lambda_function.function_name
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
output "function_arn" {
|
|
275
|
+
description = "ARN of the Lambda function"
|
|
276
|
+
value = aws_lambda_function.lambda_function.arn
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
output "role_arn" {
|
|
280
|
+
description = "ARN of the Lambda execution role"
|
|
281
|
+
value = aws_iam_role.lambda_role.arn
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
output "role_name" {
|
|
285
|
+
description = "Name of the Lambda execution role"
|
|
286
|
+
value = aws_iam_role.lambda_role.name
|
|
287
|
+
}
|
|
288
|
+
",
|
|
289
|
+
}
|
|
290
|
+
`;
|
|
291
|
+
|
|
292
|
+
exports[`ts-lambda-function generator > terraform iacProvider > should match snapshot for terraform generated files with different configurations > terraform-lambda-snapshot-function.tf 1`] = `
|
|
293
|
+
"variable "tags" {
|
|
294
|
+
description = "Tags to apply to resources"
|
|
295
|
+
type = map(string)
|
|
296
|
+
default = {}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
variable "env" {
|
|
300
|
+
description = "Additional environment variables for the Lambda function"
|
|
301
|
+
type = map(string)
|
|
302
|
+
default = {}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
variable "additional_iam_policy_statements" {
|
|
306
|
+
description = "Additional IAM policy statements to attach to the Lambda role"
|
|
307
|
+
type = list(object({
|
|
308
|
+
Effect = string
|
|
309
|
+
Action = list(string)
|
|
310
|
+
Resource = list(string)
|
|
311
|
+
}))
|
|
312
|
+
default = []
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
data "aws_caller_identity" "current" {}
|
|
316
|
+
data "aws_region" "current" {}
|
|
317
|
+
|
|
318
|
+
locals {
|
|
319
|
+
aws_account_id = data.aws_caller_identity.current.account_id
|
|
320
|
+
aws_region = data.aws_region.current.name
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
resource "random_string" "suffix" {
|
|
324
|
+
length = 8
|
|
325
|
+
special = false
|
|
326
|
+
upper = false
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
resource "aws_iam_role" "lambda_role" {
|
|
330
|
+
name = "test-project-snapshot-function-role-\${random_string.suffix.result}"
|
|
331
|
+
|
|
332
|
+
assume_role_policy = jsonencode({
|
|
333
|
+
Version = "2012-10-17"
|
|
334
|
+
Statement = [
|
|
335
|
+
{
|
|
336
|
+
Sid = "LambdaAssumeRolePolicy"
|
|
337
|
+
Effect = "Allow"
|
|
338
|
+
Principal = {
|
|
339
|
+
Service = "lambda.amazonaws.com"
|
|
340
|
+
}
|
|
341
|
+
Action = "sts:AssumeRole"
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
tags = var.tags
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
resource "aws_iam_policy" "lambda_policy" {
|
|
350
|
+
name = "test-project-snapshot-function-policy-\${random_string.suffix.result}"
|
|
351
|
+
description = "Policy for test-project-snapshot-function Lambda function"
|
|
352
|
+
|
|
353
|
+
policy = jsonencode({
|
|
354
|
+
Version = "2012-10-17"
|
|
355
|
+
Statement = concat([
|
|
356
|
+
{
|
|
357
|
+
Sid = "CloudWatchLogsAccess"
|
|
358
|
+
Effect = "Allow"
|
|
359
|
+
Action = [
|
|
360
|
+
"logs:CreateLogGroup",
|
|
361
|
+
"logs:CreateLogStream",
|
|
362
|
+
"logs:PutLogEvents"
|
|
363
|
+
]
|
|
364
|
+
Resource = [
|
|
365
|
+
"arn:aws:logs:\${local.aws_region}:\${local.aws_account_id}:log-group:/aws/lambda/test-project-snapshot-function-\${random_string.suffix.result}:*"
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
Sid = "XRayAccess"
|
|
370
|
+
Effect = "Allow"
|
|
371
|
+
Action = [
|
|
372
|
+
"xray:PutTraceSegments",
|
|
373
|
+
"xray:PutTelemetryRecords"
|
|
374
|
+
]
|
|
375
|
+
Resource = ["*"]
|
|
376
|
+
}
|
|
377
|
+
], var.additional_iam_policy_statements)
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
tags = var.tags
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
# Attach the policy to the role
|
|
384
|
+
resource "aws_iam_role_policy_attachment" "lambda_policy_attachment" {
|
|
385
|
+
role = aws_iam_role.lambda_role.name
|
|
386
|
+
policy_arn = aws_iam_policy.lambda_policy.arn
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
data "archive_file" "lambda_zip" {
|
|
390
|
+
type = "zip"
|
|
391
|
+
source_dir = "\${path.module}/../../../../../../../dist/packages/test-project/bundle-snapshot-function"
|
|
392
|
+
output_path = "\${path.module}/../../../../../../../dist/packages/common/terraform/lambda-functions/test-project-snapshot-function/lambda.zip"
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
resource "aws_lambda_function" "lambda_function" {
|
|
396
|
+
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
397
|
+
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple use case
|
|
398
|
+
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
399
|
+
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
400
|
+
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
401
|
+
filename = data.archive_file.lambda_zip.output_path
|
|
402
|
+
function_name = "test-project-snapshot-function-\${random_string.suffix.result}"
|
|
403
|
+
role = aws_iam_role.lambda_role.arn
|
|
404
|
+
handler = "index.handler"
|
|
405
|
+
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
406
|
+
runtime = "nodejs22.x"
|
|
407
|
+
timeout = 30
|
|
408
|
+
|
|
409
|
+
tracing_config {
|
|
410
|
+
mode = "Active"
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
environment {
|
|
414
|
+
variables = merge({
|
|
415
|
+
AWS_CONNECTION_REUSE_ENABLED = "1"
|
|
416
|
+
}, var.env)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
tags = var.tags
|
|
420
|
+
|
|
421
|
+
depends_on = [aws_iam_role_policy_attachment.lambda_policy_attachment]
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
output "function_name" {
|
|
425
|
+
description = "Name of the Lambda function"
|
|
426
|
+
value = aws_lambda_function.lambda_function.function_name
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
output "function_arn" {
|
|
430
|
+
description = "ARN of the Lambda function"
|
|
431
|
+
value = aws_lambda_function.lambda_function.arn
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
output "role_arn" {
|
|
435
|
+
description = "ARN of the Lambda execution role"
|
|
436
|
+
value = aws_iam_role.lambda_role.arn
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
output "role_name" {
|
|
440
|
+
description = "Name of the Lambda execution role"
|
|
441
|
+
value = aws_iam_role.lambda_role.name
|
|
442
|
+
}
|
|
443
|
+
"
|
|
444
|
+
`;
|
|
@@ -8,9 +8,7 @@ const tslib_1 = require("tslib");
|
|
|
8
8
|
*/
|
|
9
9
|
const devkit_1 = require("@nx/devkit");
|
|
10
10
|
const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
11
|
-
const shared_constructs_constants_1 = require("../../utils/shared-constructs-constants");
|
|
12
11
|
const names_1 = require("../../utils/names");
|
|
13
|
-
const ast_1 = require("../../utils/ast");
|
|
14
12
|
const format_1 = require("../../utils/format");
|
|
15
13
|
const object_1 = require("../../utils/object");
|
|
16
14
|
const nx_1 = require("../../utils/nx");
|
|
@@ -19,6 +17,7 @@ const versions_1 = require("../../utils/versions");
|
|
|
19
17
|
const lodash_camelcase_1 = tslib_1.__importDefault(require("lodash.camelcase"));
|
|
20
18
|
const io_1 = require("./io");
|
|
21
19
|
const esbuild_1 = require("../../utils/esbuild");
|
|
20
|
+
const function_constructs_1 = require("../../utils/function-constructs/function-constructs");
|
|
22
21
|
exports.TS_LAMBDA_FUNCTION_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
23
22
|
/**
|
|
24
23
|
* Generates a TypeScript Lambda Function to add to a TypeScript project
|
|
@@ -48,16 +47,23 @@ const tsLambdaFunctionGenerator = (tree, schema) => tslib_1.__awaiter(void 0, vo
|
|
|
48
47
|
if (tree.exists(functionPath)) {
|
|
49
48
|
throw new Error(`This project already has a lambda function with the name ${functionNameKebabCase}. Please remove the lambda function before running this generator or use a different name.`);
|
|
50
49
|
}
|
|
51
|
-
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree
|
|
50
|
+
yield (0, shared_constructs_1.sharedConstructsGenerator)(tree, {
|
|
51
|
+
iacProvider: schema.iacProvider,
|
|
52
|
+
});
|
|
52
53
|
// Add bundle-<name> target for this specific lambda function
|
|
53
54
|
const bundleTargetName = `bundle-${lambdaFunctionKebabCase}`;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
(0, function_constructs_1.addLambdaFunctionInfra)(tree, {
|
|
56
|
+
functionProjectName: projectConfig.name,
|
|
57
|
+
functionNameClassName: constructFunctionClassName,
|
|
58
|
+
functionNameKebabCase: constructFunctionNameKebabCase,
|
|
59
|
+
handler: 'index.handler',
|
|
60
|
+
runtime: 'node',
|
|
61
|
+
bundlePathFromRoot: (0, devkit_1.joinPathFragments)('dist', dir, bundleTargetName),
|
|
62
|
+
iacProvider: schema.iacProvider,
|
|
63
|
+
});
|
|
64
|
+
const enhancedOptions = Object.assign(Object.assign({}, schema), { lambdaFunctionCamelCase,
|
|
58
65
|
lambdaFunctionClassName,
|
|
59
|
-
lambdaFunctionKebabCase,
|
|
60
|
-
bundleTargetName, returnType: io_1.TS_HANDLER_RETURN_TYPES[schema.eventSource] });
|
|
66
|
+
lambdaFunctionKebabCase, returnType: io_1.TS_HANDLER_RETURN_TYPES[schema.eventSource] });
|
|
61
67
|
// Add a bundle target for the function
|
|
62
68
|
(0, esbuild_1.addEsbuildBundleTarget)(projectConfig, {
|
|
63
69
|
bundleTargetName,
|
|
@@ -68,24 +74,6 @@ const tsLambdaFunctionGenerator = (tree, schema) => tslib_1.__awaiter(void 0, vo
|
|
|
68
74
|
(0, devkit_1.updateProjectConfiguration)(tree, projectConfig.name, projectConfig);
|
|
69
75
|
// Generate the lambda handler file
|
|
70
76
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', 'handler'), (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, (_b = schema.functionPath) !== null && _b !== void 0 ? _b : ''), enhancedOptions, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
71
|
-
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app'), enhancedOptions, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
72
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'index.ts'), './lambda-functions/index.js');
|
|
73
|
-
(0, ast_1.addStarExport)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'src', 'app', 'lambda-functions', 'index.ts'), `./${constructFunctionNameKebabCase}.js`);
|
|
74
|
-
// Ensure common constructs builds after our lambda function project
|
|
75
|
-
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_CONSTRUCTS_DIR, 'project.json'), (config) => {
|
|
76
|
-
var _a;
|
|
77
|
-
if (!config.targets) {
|
|
78
|
-
config.targets = {};
|
|
79
|
-
}
|
|
80
|
-
if (!config.targets.build) {
|
|
81
|
-
config.targets.build = {};
|
|
82
|
-
}
|
|
83
|
-
config.targets.build.dependsOn = [
|
|
84
|
-
...((_a = config.targets.build.dependsOn) !== null && _a !== void 0 ? _a : []).filter((t) => t !== `${projectConfig.name}:build`),
|
|
85
|
-
`${projectConfig.name}:build`,
|
|
86
|
-
];
|
|
87
|
-
return config;
|
|
88
|
-
});
|
|
89
77
|
(0, devkit_1.addDependenciesToPackageJson)(tree, (0, versions_1.withVersions)([
|
|
90
78
|
'@aws-lambda-powertools/tracer',
|
|
91
79
|
'@aws-lambda-powertools/logger',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/lambda-function/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/lambda-function/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCASoB;AAEpB,qEAA0E;AAC1E,6CAAyE;AACzE,+CAA0D;AAC1D,+CAAoD;AACpD,uCAIwB;AACxB,iDAAsE;AACtE,mDAAoD;AACpD,gFAAyC;AACzC,6BAA+C;AAC/C,iDAA6D;AAC7D,6FAA6F;AAEhF,QAAA,iCAAiC,GAC5C,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAE/B;;GAEG;AACI,MAAM,yBAAyB,GAAG,CACvC,IAAU,EACV,MAAuC,EACX,EAAE;;IAC9B,MAAM,aAAa,GAAG,IAAA,wCAAmC,EACvD,IAAI,EACJ,MAAM,CAAC,OAAO,CACf,CAAC;IAEF,MAAM,YAAY,GAAG,IAAA,0BAAiB,EAAC,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAE5E,gDAAgD;IAChD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CACb,oDAAoD,MAAM,CAAC,OAAO,yEAAyE,CAC5I,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CACb,gIAAgI,CACjI,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC;IAC/B,MAAM,uBAAuB,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACpE,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EAAC,uBAAuB,CAAC,C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,iCAAyB,CAAC"}
|
|
@@ -76,6 +76,14 @@
|
|
|
76
76
|
],
|
|
77
77
|
"default": "Any",
|
|
78
78
|
"x-prompt": "Enter the event source schema to use for the lambda function"
|
|
79
|
+
},
|
|
80
|
+
"iacProvider": {
|
|
81
|
+
"type": "string",
|
|
82
|
+
"description": "The preferred IaC provider",
|
|
83
|
+
"enum": ["CDK", "Terraform"],
|
|
84
|
+
"x-priority": "important",
|
|
85
|
+
"default": "CDK",
|
|
86
|
+
"x-prompt": "Which provider would you like to manage your infrastructure? (default: CDK)"
|
|
79
87
|
}
|
|
80
88
|
},
|
|
81
89
|
"required": ["project", "functionName"]
|