-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_glue_job.tf
60 lines (53 loc) · 1.76 KB
/
run_glue_job.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
data "archive_file" "run_glue_job_zip" {
type = "zip"
source_file = "${path.module}/lambdas/run-glue-job.js"
output_path = "${path.module}/lambdas/run-glue-job.zip"
}
resource "aws_lambda_function" "glue_job_lambda" {
filename = data.archive_file.run_glue_job_zip.output_path
function_name = "controlshift-run-glue-job"
role = aws_iam_role.run_glue_job_lambda_role.arn
handler = "run-glue-job.handler"
runtime = "nodejs16.x"
timeout = 60
source_code_hash = data.archive_file.run_glue_job_zip.output_base64sha256
environment {
variables = {
GLUE_JOB_NAME = aws_glue_job.signatures_full.id
}
}
}
resource "aws_cloudwatch_event_rule" "trigger_glue_job_on_crawler_finished" {
name = "trigger-glue-job-on-crawler-finished"
description = "Trigger Lambda to start Glue job when crawler finishes successfully"
event_pattern = <<PATTERN
{
"source": [
"aws.glue"
],
"detail-type": [
"Glue Crawler State Change"
],
"detail": {
"state": [
"Succeeded"
],
"crawlerName": [
"${aws_glue_crawler.signatures_crawler.name}"
]
}
}
PATTERN
}
resource "aws_cloudwatch_event_target" "trigger_run_glue_job_lambda" {
rule = aws_cloudwatch_event_rule.trigger_glue_job_on_crawler_finished.name
target_id = "trigger-controlshift-run-glue-job"
arn = aws_lambda_function.glue_job_lambda.arn
}
resource "aws_lambda_permission" "allow_crawler_ran_cloudwatch_event" {
function_name = aws_lambda_function.glue_job_lambda.function_name
statement_id = "AllowExecutionFromGlueCloudWatchEventOnCrawlerRan"
action = "lambda:InvokeFunction"
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.trigger_glue_job_on_crawler_finished.arn
}