-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.tf
685 lines (601 loc) · 20.5 KB
/
main.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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
provider "aws" {
region = var.region
}
data "aws_caller_identity" "this" {}
# DOCS
# Lambda memory - https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html
# https://stackoverflow.com/questions/66522916/aws-lambda-memory-vs-cpu-configuration
#
locals {
build_cpp_path = abspath("${path.module}/build_cpp.sh")
shared_source_path = abspath("${path.module}/lambda/shared/source")
gzip_source_path = abspath("${path.module}/lambda/shared/gzip")
maximum_load_file_size = 750000000
vcf_processed_file_size = 50000000
# TODO use the following organisation to refactor the IAM policy assignment
# this makes the code simpler
# sbeacon info variables
sbeacon_variables = {
# beacon variables
BEACON_API_VERSION = var.beacon-api-version
BEACON_ID = var.beacon-id
BEACON_NAME = var.beacon-name
BEACON_ENVIRONMENT = var.beacon-environment
BEACON_DESCRIPTION = var.beacon-description
BEACON_VERSION = var.beacon-version
BEACON_WELCOME_URL = var.beacon-welcome-url
BEACON_ALTERNATIVE_URL = var.beacon-alternative-url
BEACON_CREATE_DATETIME = var.beacon-create-datetime
BEACON_UPDATE_DATETIME = var.beacon-update-datetime
BEACON_HANDOVERS = var.beacon-handovers
BEACON_DOCUMENTATION_URL = var.beacon-documentation-url
BEACON_DEFAULT_GRANULARITY = var.beacon-default-granularity
BEACON_URI = var.beacon-uri
# organisation variables
BEACON_ORG_ID = var.organisation-id
BEACON_ORG_NAME = var.organisation-name
BEACON_ORG_DESCRIPTION = var.beacon-org-description
BEACON_ORG_ADDRESS = var.beacon-org-address
BEACON_ORG_WELCOME_URL = var.beacon-org-welcome-url
BEACON_ORG_CONTACT_URL = var.beacon-org-contact-url
BEACON_ORG_LOGO_URL = var.beacon-org-logo-url
# beacon service variables
BEACON_SERVICE_TYPE_GROUP = var.beacon-service-type-group
BEACON_SERVICE_TYPE_ARTIFACT = var.beacon-service-type-artifact
BEACON_SERVICE_TYPE_VERSION = var.beacon-service-type-version
# authentication variables
BEACON_ENABLE_AUTH = var.beacon-enable-auth
# configurations
CONFIG_MAX_VARIANT_SEARCH_BASE_RANGE = var.config-max-variant-search-base-range
}
# athena related variables
athena_variables = {
ATHENA_WORKGROUP = aws_athena_workgroup.sbeacon-workgroup.name
ATHENA_METADATA_DATABASE = aws_glue_catalog_database.metadata-database.name
ATHENA_METADATA_BUCKET = aws_s3_bucket.metadata-bucket.bucket
ATHENA_DATASETS_TABLE = aws_glue_catalog_table.sbeacon-datasets.name
ATHENA_DATASETS_CACHE_TABLE = aws_glue_catalog_table.sbeacon-datasets-cache.name
ATHENA_COHORTS_TABLE = aws_glue_catalog_table.sbeacon-cohorts.name
ATHENA_COHORTS_CACHE_TABLE = aws_glue_catalog_table.sbeacon-cohorts-cache.name
ATHENA_INDIVIDUALS_TABLE = aws_glue_catalog_table.sbeacon-individuals.name
ATHENA_INDIVIDUALS_CACHE_TABLE = aws_glue_catalog_table.sbeacon-individuals-cache.name
ATHENA_BIOSAMPLES_TABLE = aws_glue_catalog_table.sbeacon-biosamples.name
ATHENA_BIOSAMPLES_CACHE_TABLE = aws_glue_catalog_table.sbeacon-biosamples-cache.name
ATHENA_RUNS_TABLE = aws_glue_catalog_table.sbeacon-runs.name
ATHENA_RUNS_CACHE_TABLE = aws_glue_catalog_table.sbeacon-runs-cache.name
ATHENA_ANALYSES_TABLE = aws_glue_catalog_table.sbeacon-analyses.name
ATHENA_ANALYSES_CACHE_TABLE = aws_glue_catalog_table.sbeacon-analyses-cache.name
ATHENA_TERMS_TABLE = aws_glue_catalog_table.sbeacon-terms.name
ATHENA_TERMS_INDEX_TABLE = aws_glue_catalog_table.sbeacon-terms-index.name
ATHENA_TERMS_CACHE_TABLE = aws_glue_catalog_table.sbeacon-terms-cache.name
ATHENA_RELATIONS_TABLE = aws_glue_catalog_table.sbeacon-relations.name
}
# dynamodb variables
dynamodb_variables = {
DYNAMO_DATASETS_TABLE = aws_dynamodb_table.datasets.name
DYNAMO_VCF_SUMMARIES_TABLE = aws_dynamodb_table.vcf_summaries.name
DYNAMO_VARIANT_DUPLICATES_TABLE = aws_dynamodb_table.variant_duplicates.name
DYNAMO_VARIANT_QUERIES_TABLE = aws_dynamodb_table.variant_queries.name
DYNAMO_VARIANT_QUERY_RESPONSES_TABLE = aws_dynamodb_table.variant_query_responses.name
DYNAMO_ONTOLOGIES_TABLE = aws_dynamodb_table.ontologies.name
DYNAMO_ANSCESTORS_TABLE = aws_dynamodb_table.anscestor_terms.name
DYNAMO_DESCENDANTS_TABLE = aws_dynamodb_table.descendant_terms.name
}
# layers
binaries_layer = "${aws_lambda_layer_version.binaries_layer.layer_arn}:${aws_lambda_layer_version.binaries_layer.version}"
python_libraries_layer = module.python_libraries_layer.lambda_layer_arn
python_modules_layer = module.python_modules_layer.lambda_layer_arn
}
#
# submitDataset Lambda Function
#
module "lambda-submitDataset" {
source = "terraform-aws-modules/lambda/aws"
function_name = "submitDataset"
description = "Creates or updates a dataset and triggers summariseVcf."
handler = "lambda_function.lambda_handler"
runtime = "python3.12"
architectures = ["x86_64"]
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-submitDataset.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json,
data.aws_iam_policy_document.dynamodb-onto-write-access.json
]
number_of_policy_jsons = 4
source_path = "${path.module}/lambda/submitDataset"
tags = var.common-tags
environment_variables = merge(
{
DYNAMO_DATASETS_TABLE = aws_dynamodb_table.datasets.name
INDEXER_LAMBDA = module.lambda-indexer.lambda_function_name
},
local.sbeacon_variables,
local.athena_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.binaries_layer,
local.python_modules_layer
]
}
#
# getInfo Lambda Function
#
module "lambda-getInfo" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getInfo"
description = "Returns basic information about the beacon and the datasets."
handler = "lambda_function.lambda_handler"
runtime = "python3.12"
memory_size = 1769
timeout = 60
attach_policy_json = true
policy_json = data.aws_iam_policy_document.lambda-getInfo.json
source_path = "${path.module}/lambda/getInfo"
tags = var.common-tags
environment_variables = merge(
local.sbeacon_variables,
local.athena_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getConfiguration Lambda Function
#
module "lambda-getConfiguration" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getConfiguration"
description = "Get the beacon configuration."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_json = true
policy_json = data.aws_iam_policy_document.lambda-getConfiguration.json
source_path = "${path.module}/lambda/getConfiguration"
tags = var.common-tags
environment_variables = merge(
local.sbeacon_variables,
local.athena_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getMap Lambda Function
#
module "lambda-getMap" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getMap"
description = "Get the beacon map."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_json = true
policy_json = data.aws_iam_policy_document.lambda-getMap.json
source_path = "${path.module}/lambda/getMap"
tags = var.common-tags
environment_variables = merge(
local.sbeacon_variables,
local.athena_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getEntryTypes Lambda Function
#
module "lambda-getEntryTypes" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getEntryTypes"
description = "Get the beacon map."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_json = true
policy_json = data.aws_iam_policy_document.lambda-getEntryTypes.json
source_path = "${path.module}/lambda/getEntryTypes"
tags = var.common-tags
environment_variables = merge(
local.sbeacon_variables,
local.athena_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getFilteringTerms Lambda Function
#
module "lambda-getFilteringTerms" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getFilteringTerms"
description = "Get the beacon map."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json,
]
number_of_policy_jsons = 2
source_path = "${path.module}/lambda/getFilteringTerms"
tags = var.common-tags
environment_variables = merge(
local.sbeacon_variables,
local.athena_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getAnalyses Lambda Function
#
module "lambda-getAnalyses" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getAnalyses"
description = "Get the beacon map."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-getAnalyses.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json
]
number_of_policy_jsons = 3
source_path = "${path.module}/lambda/getAnalyses"
tags = var.common-tags
environment_variables = merge(
{
SPLIT_QUERY_LAMBDA = module.lambda-splitQuery.lambda_function_name,
SPLIT_QUERY_TOPIC_ARN = aws_sns_topic.splitQuery.arn
},
local.athena_variables,
local.sbeacon_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getGenomicVariants Lambda Function
#
module "lambda-getGenomicVariants" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getGenomicVariants"
description = "Get the variants."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-getGenomicVariants.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json
]
number_of_policy_jsons = 3
source_path = "${path.module}/lambda/getGenomicVariants"
tags = var.common-tags
environment_variables = merge(
{
SPLIT_QUERY_LAMBDA = module.lambda-splitQuery.lambda_function_name,
SPLIT_QUERY_TOPIC_ARN = aws_sns_topic.splitQuery.arn
},
local.athena_variables,
local.sbeacon_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getIndividuals Lambda Function
#
module "lambda-getIndividuals" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getIndividuals"
description = "Get the individuals."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-getIndividuals.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json
]
number_of_policy_jsons = 3
source_path = "${path.module}/lambda/getIndividuals"
tags = var.common-tags
environment_variables = merge(
{
SPLIT_QUERY_LAMBDA = module.lambda-splitQuery.lambda_function_name,
SPLIT_QUERY_TOPIC_ARN = aws_sns_topic.splitQuery.arn
},
local.athena_variables,
local.sbeacon_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getBiosamples Lambda Function
#
module "lambda-getBiosamples" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getBiosamples"
description = "Get the biosamples."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-getBiosamples.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json
]
number_of_policy_jsons = 3
source_path = "${path.module}/lambda/getBiosamples"
tags = var.common-tags
environment_variables = merge(
{
SPLIT_QUERY_LAMBDA = module.lambda-splitQuery.lambda_function_name,
SPLIT_QUERY_TOPIC_ARN = aws_sns_topic.splitQuery.arn
},
local.athena_variables,
local.sbeacon_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getDatasets Lambda Function
#
module "lambda-getDatasets" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getDatasets"
description = "Get the datasets."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-getDatasets.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json
]
number_of_policy_jsons = 3
source_path = "${path.module}/lambda/getDatasets"
tags = var.common-tags
environment_variables = merge(
{
SPLIT_QUERY_LAMBDA = module.lambda-splitQuery.lambda_function_name,
SPLIT_QUERY_TOPIC_ARN = aws_sns_topic.splitQuery.arn
},
local.athena_variables,
local.sbeacon_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getCohorts Lambda Function
#
module "lambda-getCohorts" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getCohorts"
description = "Get the cohorts."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-getCohorts.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json
]
number_of_policy_jsons = 3
source_path = "${path.module}/lambda/getCohorts"
tags = var.common-tags
environment_variables = merge(
{
SPLIT_QUERY_LAMBDA = module.lambda-splitQuery.lambda_function_name
},
local.athena_variables,
local.sbeacon_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# getRuns Lambda Function
#
module "lambda-getRuns" {
source = "terraform-aws-modules/lambda/aws"
function_name = "getRuns"
description = "Get the runs."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-getRuns.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json
]
number_of_policy_jsons = 3
source_path = "${path.module}/lambda/getRuns"
tags = var.common-tags
environment_variables = merge(
{
SPLIT_QUERY_LAMBDA = module.lambda-splitQuery.lambda_function_name,
SPLIT_QUERY_TOPIC_ARN = aws_sns_topic.splitQuery.arn
},
local.athena_variables,
local.sbeacon_variables,
local.dynamodb_variables
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# splitQuery Lambda Function
#
module "lambda-splitQuery" {
source = "terraform-aws-modules/lambda/aws"
function_name = "splitQuery"
description = "Splits a dataset into smaller slices of VCFs and invokes performQuery on each."
handler = "lambda_function.lambda_handler"
runtime = "python3.12"
memory_size = 1769
timeout = 30
attach_policy_json = true
policy_json = data.aws_iam_policy_document.lambda-splitQuery.json
source_path = "${path.module}/lambda/splitQuery"
tags = var.common-tags
environment_variables = {
PERFORM_QUERY_LAMBDA = module.lambda-performQuery.lambda_function_name,
PERFORM_QUERY_TOPIC_ARN = aws_sns_topic.performQuery.arn
}
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# performQuery Lambda Function
#
module "lambda-performQuery" {
source = "terraform-aws-modules/lambda/aws"
function_name = "performQuery"
description = "Queries a slice of a vcf for a specified variant."
handler = "lambda_function.lambda_handler"
runtime = "python3.12"
memory_size = 1769
timeout = 10
ephemeral_storage_size = 1024
attach_policy_json = true
policy_json = data.aws_iam_policy_document.lambda-performQuery.json
source_path = "${path.module}/lambda/performQuery"
tags = var.common-tags
layers = [
local.binaries_layer,
local.python_libraries_layer,
local.python_modules_layer
]
environment_variables = merge({
VARIANTS_BUCKET = aws_s3_bucket.variants-bucket.bucket
},
local.sbeacon_variables,
local.dynamodb_variables)
}
#
# indexer Lambda Function
#
module "lambda-indexer" {
source = "terraform-aws-modules/lambda/aws"
function_name = "indexer"
description = "Run the indexing tasks."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 1769
timeout = 600
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.lambda-indexer.json,
data.aws_iam_policy_document.athena-full-access.json,
data.aws_iam_policy_document.dynamodb-onto-access.json,
data.aws_iam_policy_document.dynamodb-onto-write-access.json
]
number_of_policy_jsons = 4
source_path = "${path.module}/lambda/indexer"
tags = var.common-tags
environment_variables = merge(
local.dynamodb_variables,
local.sbeacon_variables,
local.athena_variables,
{ INDEXER_TOPIC_ARN : aws_sns_topic.indexer.arn }
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}
#
# admin Lambda Function
#
module "lambda-admin" {
source = "terraform-aws-modules/lambda/aws"
function_name = "admin"
description = "Run the admin tasks."
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
memory_size = 512
timeout = 60
attach_policy_jsons = true
policy_jsons = [
data.aws_iam_policy_document.admin-lambda-access.json
]
number_of_policy_jsons = 1
source_path = "${path.module}/lambda/admin"
tags = var.common-tags
environment_variables = merge(
local.sbeacon_variables,
{ COGNITO_USER_POOL_ID = aws_cognito_user_pool.BeaconUserPool.id }
)
layers = [
local.python_libraries_layer,
local.python_modules_layer
]
}