-
Notifications
You must be signed in to change notification settings - Fork 0
/
tf_deploy_core_subsetting.tf
670 lines (493 loc) · 19.2 KB
/
tf_deploy_core_subsetting.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
########## COMMON DECLARATIONS ##########
## 0. CONFIGURE AWS PROVIDER ##
provider "aws" {
shared_credentials_files = [var.aws_creds_path]
region = var.aws_region
}
## 1.1. CREATE ROLE AND ATTACH IAM ROLE POLICY ##
# FOR WORKERS
resource "aws_iam_role" "lambda_exec" {
name = "serverless_lambda_subsetting_workers"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
data "aws_iam_policy_document" "lamda_s3_access" {
statement {
effect = "Allow"
actions = [
"s3:*",
"s3-object-lambda:*"
]
resources = ["*"]
# TODO: make resource specific
}
}
resource "aws_iam_policy" "lamda_s3_access" {
name = "lambda_s3_access"
path = "/"
description = "IAM policy for rd wr access to s3 data from a lambda"
policy = data.aws_iam_policy_document.lamda_s3_access.json
}
# attach IAM role to the lambda function
resource "aws_iam_role_policy_attachment" "lambda_policy" {
role = aws_iam_role.lambda_exec.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "lambda_s3_access" {
role = aws_iam_role.lambda_exec.name
policy_arn = aws_iam_policy.lamda_s3_access.arn
}
# FOR TRIGGER
resource "aws_iam_role" "lambda_trigger" {
name = "serverless_lambda_subsetting_trigger"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
data "aws_iam_policy_document" "lambda_invoke_lambda" {
statement {
effect = "Allow"
actions = ["lambda:InvokeFunction"]
resources = ["*"]
# TODO: make resource specific
}
}
resource "aws_iam_policy" "lambda_invoke_lambda" {
name = "lambda_invoke_lambda"
path = "/"
description = "IAM policy that allows a lambda to invoke another lambda"
policy = data.aws_iam_policy_document.lambda_invoke_lambda.json
}
# attach IAM role to the lambda function
resource "aws_iam_role_policy_attachment" "lambda_policy_basic" {
role = aws_iam_role.lambda_trigger.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "lambda_invoke_lambda" {
role = aws_iam_role.lambda_trigger.name
policy_arn = aws_iam_policy.lambda_invoke_lambda.arn
}
## 2.1. CREATE BUCKET ##
resource "aws_s3_bucket" "lambda_bucket" {
bucket = "fcx-subsetting-tool-terraform"
}
########## LAMBDA SPECIFIC DECLARATIONS ##########
## 2.2. ZIP AND UPLOAD THE LAMBDA CODES ##
# ZIP
# zip CRS
data "archive_file" "lambda_CRS_subset_worker" {
type = "zip"
source_dir = "${path.module}/src/CRS_subsetting"
output_path = "${path.module}/dist/CRS_subsetting.zip"
}
# zip FEGS
data "archive_file" "lambda_FEGS_subset_worker" {
type = "zip"
source_dir = "${path.module}/src/FEGS_subsetting"
output_path = "${path.module}/dist/FEGS_subsetting.zip"
}
# zip GLM
data "archive_file" "lambda_GLM_subset_worker" {
type = "zip"
source_dir = "${path.module}/src/GLM_subsetting"
output_path = "${path.module}/dist/GLM_subsetting.zip"
}
# zip LIP
data "archive_file" "lambda_LIP_subset_worker" {
type = "zip"
source_dir = "${path.module}/src/LIP_subsetting"
output_path = "${path.module}/dist/LIP_subsetting.zip"
}
# zip LIS
data "archive_file" "lambda_LIS_subset_worker" {
type = "zip"
source_dir = "${path.module}/src/LIS_subsetting"
output_path = "${path.module}/dist/LIS_subsetting.zip"
}
# zip LMA
data "archive_file" "lambda_LMA_subset_worker" {
type = "zip"
source_dir = "${path.module}/src/LMA_subsetting"
output_path = "${path.module}/dist/LMA_subsetting.zip"
}
# zip TRIGGER
data "archive_file" "lambda_subset_trigger" {
type = "zip"
source_dir = "${path.module}/src/trigger_subsetting"
output_path = "${path.module}/dist/trigger_subsetting.zip"
}
# UPLOAD
# upload CRS zip
resource "aws_s3_object" "lambda_CRS_subset_worker" {
bucket = aws_s3_bucket.lambda_bucket.id
key = "CRS_subsetting.zip"
source = data.archive_file.lambda_CRS_subset_worker.output_path
etag = filemd5(data.archive_file.lambda_CRS_subset_worker.output_path)
}
# upload FEGS zip
resource "aws_s3_object" "lambda_FEGS_subset_worker" {
bucket = aws_s3_bucket.lambda_bucket.id
key = "FEGS_subsetting.zip"
source = data.archive_file.lambda_FEGS_subset_worker.output_path
etag = filemd5(data.archive_file.lambda_FEGS_subset_worker.output_path)
}
# upload GLM zip
resource "aws_s3_object" "lambda_GLM_subset_worker" {
bucket = aws_s3_bucket.lambda_bucket.id
key = "GLM_subsetting.zip"
source = data.archive_file.lambda_GLM_subset_worker.output_path
etag = filemd5(data.archive_file.lambda_GLM_subset_worker.output_path)
}
# upload LIP zip
resource "aws_s3_object" "lambda_LIP_subset_worker" {
bucket = aws_s3_bucket.lambda_bucket.id
key = "LIP_subsetting.zip"
source = data.archive_file.lambda_LIP_subset_worker.output_path
etag = filemd5(data.archive_file.lambda_LIP_subset_worker.output_path)
}
# upload LIS zip
resource "aws_s3_object" "lambda_LIS_subset_worker" {
bucket = aws_s3_bucket.lambda_bucket.id
key = "LIS_subsetting.zip"
source = data.archive_file.lambda_LIS_subset_worker.output_path
etag = filemd5(data.archive_file.lambda_LIS_subset_worker.output_path)
}
# upload LMA zip
resource "aws_s3_object" "lambda_LMA_subset_worker" {
bucket = aws_s3_bucket.lambda_bucket.id
key = "LMA_subsetting.zip"
source = data.archive_file.lambda_LMA_subset_worker.output_path
etag = filemd5(data.archive_file.lambda_LMA_subset_worker.output_path)
}
# upload TRIGGER zip
resource "aws_s3_object" "lambda_subset_trigger" {
bucket = aws_s3_bucket.lambda_bucket.id
key = "trigger_subsetting.zip"
source = data.archive_file.lambda_subset_trigger.output_path
etag = filemd5(data.archive_file.lambda_subset_trigger.output_path)
}
## 2.3. CREATE LAMBDA FUNCTION ##
# Lambda CRS
resource "aws_lambda_function" "CRS_Subset_Worker" {
function_name = "fcx-subsetting-CRS-worker"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_CRS_subset_worker.key
runtime = "python3.8"
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.lambda_CRS_subset_worker.output_base64sha256
role = aws_iam_role.lambda_exec.arn
layers = [aws_lambda_layer_version.xarr_scipy.arn, aws_lambda_layer_version.ws_client.arn]
memory_size = var.lambda_execution_memory
timeout = var.lambda_execution_timeout
ephemeral_storage {
size = var.lambda_execution_ephimeral_storage
}
environment {
variables = {
BUCKET_AWS_REGION = var.aws_region
SOURCE_BUCKET_NAME = var.SOURCE_BUCKET_NAME
WS_URL = aws_apigatewayv2_stage.subsetting_ws.invoke_url
}
}
depends_on = [ aws_apigatewayv2_stage.subsetting_ws, aws_lambda_layer_version.xarr_scipy, aws_lambda_layer_version.ws_client ]
}
# Lambda FEGS
resource "aws_lambda_function" "FEGS_Subset_Worker" {
function_name = "fcx-subsetting-FEGS-worker"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_FEGS_subset_worker.key
runtime = "python3.8"
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.lambda_FEGS_subset_worker.output_base64sha256
role = aws_iam_role.lambda_exec.arn
layers = [aws_lambda_layer_version.xarr_s3fs_h5ncf.arn, aws_lambda_layer_version.ws_client.arn]
memory_size = var.lambda_execution_memory
timeout = var.lambda_execution_timeout
ephemeral_storage {
size = var.lambda_execution_ephimeral_storage
}
environment {
variables = {
BUCKET_AWS_REGION = var.aws_region
SOURCE_BUCKET_NAME = var.SOURCE_BUCKET_NAME
WS_URL = aws_apigatewayv2_stage.subsetting_ws.invoke_url
}
}
depends_on = [ aws_apigatewayv2_stage.subsetting_ws, aws_lambda_layer_version.xarr_s3fs_h5ncf, aws_lambda_layer_version.ws_client ]
}
# Lambda GLM
resource "aws_lambda_function" "GLM_Subset_Worker" {
function_name = "fcx-subsetting-GLM-worker"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_GLM_subset_worker.key
runtime = "python3.8"
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.lambda_GLM_subset_worker.output_base64sha256
role = aws_iam_role.lambda_exec.arn
layers = [aws_lambda_layer_version.xarr_s3fs_h5ncf.arn, aws_lambda_layer_version.ws_client.arn]
memory_size = var.lambda_execution_memory
timeout = var.lambda_execution_timeout
ephemeral_storage {
size = var.lambda_execution_ephimeral_storage
}
environment {
variables = {
BUCKET_AWS_REGION = var.aws_region
SOURCE_BUCKET_NAME = var.SOURCE_BUCKET_NAME
WS_URL = aws_apigatewayv2_stage.subsetting_ws.invoke_url
}
}
depends_on = [ aws_apigatewayv2_stage.subsetting_ws, aws_lambda_layer_version.xarr_s3fs_h5ncf, aws_lambda_layer_version.ws_client ]
}
# Lambda LIP
resource "aws_lambda_function" "LIP_Subset_Worker" {
function_name = "fcx-subsetting-LIP-worker"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_LIP_subset_worker.key
runtime = "python3.8"
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.lambda_LIP_subset_worker.output_base64sha256
role = aws_iam_role.lambda_exec.arn
layers = [aws_lambda_layer_version.xarr_s3fs_h5ncf.arn, aws_lambda_layer_version.ws_client.arn]
memory_size = var.lambda_execution_memory
timeout = var.lambda_execution_timeout
ephemeral_storage {
size = var.lambda_execution_ephimeral_storage
}
environment {
variables = {
BUCKET_AWS_REGION = var.aws_region
SOURCE_BUCKET_NAME = var.SOURCE_BUCKET_NAME
WS_URL = aws_apigatewayv2_stage.subsetting_ws.invoke_url
}
}
depends_on = [ aws_apigatewayv2_stage.subsetting_ws, aws_lambda_layer_version.xarr_s3fs_h5ncf, aws_lambda_layer_version.ws_client ]
}
# Lambda LIS
resource "aws_lambda_function" "LIS_Subset_Worker" {
function_name = "fcx-subsetting-LIS-worker"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_LIS_subset_worker.key
runtime = "python3.8"
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.lambda_LIS_subset_worker.output_base64sha256
role = aws_iam_role.lambda_exec.arn
layers = [aws_lambda_layer_version.xarr_s3fs_h5ncf.arn, aws_lambda_layer_version.ws_client.arn]
memory_size = var.lambda_execution_memory
timeout = var.lambda_execution_timeout
ephemeral_storage {
size = var.lambda_execution_ephimeral_storage
}
environment {
variables = {
BUCKET_AWS_REGION = var.aws_region
SOURCE_BUCKET_NAME = var.SOURCE_BUCKET_NAME
WS_URL = aws_apigatewayv2_stage.subsetting_ws.invoke_url
}
}
depends_on = [ aws_apigatewayv2_stage.subsetting_ws, aws_lambda_layer_version.xarr_s3fs_h5ncf, aws_lambda_layer_version.ws_client ]
}
# Lambda LMA
resource "aws_lambda_function" "LMA_Subset_Worker" {
function_name = "fcx-subsetting-LMA-worker"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_LMA_subset_worker.key
runtime = "python3.8"
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.lambda_LMA_subset_worker.output_base64sha256
role = aws_iam_role.lambda_exec.arn
layers = [aws_lambda_layer_version.xarr_s3fs_h5ncf.arn, aws_lambda_layer_version.ws_client.arn]
memory_size = var.lambda_execution_memory
timeout = var.lambda_execution_timeout
ephemeral_storage {
size = var.lambda_execution_ephimeral_storage
}
environment {
variables = {
BUCKET_AWS_REGION = var.aws_region
SOURCE_BUCKET_NAME = var.SOURCE_BUCKET_NAME
WS_URL = aws_apigatewayv2_stage.subsetting_ws.invoke_url
}
}
depends_on = [ aws_apigatewayv2_stage.subsetting_ws, aws_lambda_layer_version.xarr_s3fs_h5ncf, aws_lambda_layer_version.ws_client ]
}
# Lambda TRIGGER
resource "aws_lambda_function" "subset_trigger" {
function_name = "fcx-subsetting-trigger"
s3_bucket = aws_s3_bucket.lambda_bucket.id
s3_key = aws_s3_object.lambda_subset_trigger.key
runtime = "python3.8"
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.lambda_subset_trigger.output_base64sha256
role = aws_iam_role.lambda_trigger.arn
layers = [aws_lambda_layer_version.marshmallow_json.arn]
depends_on = [aws_lambda_layer_version.marshmallow_json]
}
## 2.4. CREATE CLOUDWATCH LOG GROUP ##
# log CRS worker
resource "aws_cloudwatch_log_group" "CRS_Subset_Worker" {
name = "/aws/lambda/${aws_lambda_function.CRS_Subset_Worker.function_name}"
retention_in_days = 5
}
# log FEGS worker
resource "aws_cloudwatch_log_group" "FEGS_Subset_Worker" {
name = "/aws/lambda/${aws_lambda_function.FEGS_Subset_Worker.function_name}"
retention_in_days = 5
}
# log GLM worker
resource "aws_cloudwatch_log_group" "GLM_Subset_Worker" {
name = "/aws/lambda/${aws_lambda_function.GLM_Subset_Worker.function_name}"
retention_in_days = 5
}
# log LIP worker
resource "aws_cloudwatch_log_group" "LIP_Subset_Worker" {
name = "/aws/lambda/${aws_lambda_function.LIP_Subset_Worker.function_name}"
retention_in_days = 5
}
# log LIS worker
resource "aws_cloudwatch_log_group" "LIS_Subset_Worker" {
name = "/aws/lambda/${aws_lambda_function.LIS_Subset_Worker.function_name}"
retention_in_days = 5
}
# log LMA worker
resource "aws_cloudwatch_log_group" "LMA_Subset_Worker" {
name = "/aws/lambda/${aws_lambda_function.LMA_Subset_Worker.function_name}"
retention_in_days = 5
}
# log trigger main
resource "aws_cloudwatch_log_group" "Subset_Trigger" {
name = "/aws/lambda/${aws_lambda_function.subset_trigger.function_name}"
retention_in_days = 5
}
## REST API GATEWAY
# API Gateway name
resource "aws_api_gateway_rest_api" "subset_trigger_api" {
name = "fcx-subsetting-trigger-api"
}
## create resource
resource "aws_api_gateway_resource" "subset_trigger_api_resource" {
path_part = aws_lambda_function.subset_trigger.function_name
parent_id = aws_api_gateway_rest_api.subset_trigger_api.root_resource_id
rest_api_id = aws_api_gateway_rest_api.subset_trigger_api.id
}
## create method
resource "aws_api_gateway_method" "subset_trigger_api_method" {
rest_api_id = aws_api_gateway_rest_api.subset_trigger_api.id
resource_id = aws_api_gateway_resource.subset_trigger_api_resource.id
http_method = "POST"
authorization = "NONE"
api_key_required = true # need api key
}
## allow CORS on preflight
module "subset_trigger_api_cors" {
source = "squidfunk/api-gateway-enable-cors/aws"
version = "0.3.3"
api_id = aws_api_gateway_rest_api.subset_trigger_api.id
api_resource_id = aws_api_gateway_resource.subset_trigger_api_resource.id
depends_on = [ aws_api_gateway_rest_api.subset_trigger_api, aws_api_gateway_resource.subset_trigger_api_resource ]
}
## INTEGRATION OF GATEWAY AND LAMBDA TRIGGER
resource "aws_api_gateway_integration" "subset_trigger_api_integration" {
rest_api_id = aws_api_gateway_rest_api.subset_trigger_api.id
resource_id = aws_api_gateway_resource.subset_trigger_api_resource.id
http_method = aws_api_gateway_method.subset_trigger_api_method.http_method
integration_http_method = aws_api_gateway_method.subset_trigger_api_method.http_method
type = "AWS_PROXY"
uri = aws_lambda_function.subset_trigger.invoke_arn
}
## PERMISSIONS to trigger lamba from api gateway
resource "aws_lambda_permission" "subset_trigger_api_gateway_lambda" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.subset_trigger.function_name
principal = "apigateway.amazonaws.com"
# More: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html
source_arn = "arn:aws:execute-api:${var.aws_region}:${var.accountId}:${aws_api_gateway_rest_api.subset_trigger_api.id}/*/${aws_api_gateway_method.subset_trigger_api_method.http_method}${aws_api_gateway_resource.subset_trigger_api_resource.path}"
}
## SET RESPONSE HANDLERS FOR API-GATEWAY (NOT NEEDED FOR AWS PROXY INTEGRATION) HANDLE CORS HEADERS FROM LAMBDA RESPONSE ITSELF
## Create deployment for subset_trigger_api
resource "aws_api_gateway_deployment" "subset_trigger_api_deployment" {
rest_api_id = aws_api_gateway_rest_api.subset_trigger_api.id
triggers = {
# NOTE: The configuration below will satisfy ordering considerations,
# but not pick up all future REST API changes. More advanced patterns
# are possible, such as using the filesha1() function against the
# Terraform configuration file(s) or removing the .id references to
# calculate a hash against whole resources. Be aware that using whole
# resources will show a difference after the initial implementation.
# It will stabilize to only change when resources change afterwards.
redeployment = sha1(jsonencode([
aws_api_gateway_resource.subset_trigger_api_resource.id,
aws_api_gateway_method.subset_trigger_api_method.id,
aws_api_gateway_integration.subset_trigger_api_integration.id,
# for subets_list_resource
aws_api_gateway_resource.subsets_filename.id,
aws_api_gateway_method.subsets_filename.id,
aws_api_gateway_integration.subsets_filename_api_integration,
]))
}
lifecycle {
create_before_destroy = true
}
}
## create stage for the subset_trigger_api
resource "aws_api_gateway_stage" "subset_trigger_api_stage" {
deployment_id = aws_api_gateway_deployment.subset_trigger_api_deployment.id
rest_api_id = aws_api_gateway_rest_api.subset_trigger_api.id
stage_name = var.stage_name
depends_on = [aws_cloudwatch_log_group.subset_trigger_api]
}
### to enable api key and its usage plan for subset_trigger_api
# create api key
resource "aws_api_gateway_api_key" "subset_trigger_api_key" {
name = "subset_trigger_api-key"
}
# create usage plans
resource "aws_api_gateway_usage_plan" "subset_trigger_api_usagePlan" {
name = "subset_trigger_api-usagePlan"
description = "Usage plan for the subset_trigger_api key"
api_stages {
api_id = aws_api_gateway_rest_api.subset_trigger_api.id
stage = aws_api_gateway_stage.subset_trigger_api_stage.stage_name
}
}
resource "aws_api_gateway_usage_plan_key" "usagePlan_with_key" {
key_id = aws_api_gateway_api_key.subset_trigger_api_key.id
key_type = "API_KEY"
usage_plan_id = aws_api_gateway_usage_plan.subset_trigger_api_usagePlan.id
}
## add and enable cloudwatch logs for subset_trigger_api
resource "aws_cloudwatch_log_group" "subset_trigger_api" {
name = "API-Gateway-Execution-Logs_${aws_api_gateway_rest_api.subset_trigger_api.id}/${var.stage_name}"
retention_in_days = 3
}
resource "aws_api_gateway_method_settings" "subset_trigger_api_method" {
rest_api_id = aws_api_gateway_rest_api.subset_trigger_api.id
stage_name = aws_api_gateway_stage.subset_trigger_api_stage.stage_name
method_path = "*/*"
settings {
metrics_enabled = true
logging_level = "INFO"
}
}