diff --git a/templates/run-glue-crawler.js.tpl b/lambdas/run-glue-crawler.js similarity index 83% rename from templates/run-glue-crawler.js.tpl rename to lambdas/run-glue-crawler.js index 4bc73be..fb32a6e 100644 --- a/templates/run-glue-crawler.js.tpl +++ b/lambdas/run-glue-crawler.js @@ -5,14 +5,14 @@ const AWS = require('aws-sdk') AWS.config.update({region: process.env.AWS_REGION}) const glue = new AWS.Glue() -const crawlerName = '${glue_crawler_name}' +const crawlerName = process.env.GLUE_CRAWLER_NAME exports.handler = async (event, context) => { const { body } = event.Records[0] const parsed_body = JSON.parse(body) if (parsed_body.table !== 'signatures' || parsed_body.kind !== 'full') { - const logMessage = `Ignoring notification for table $${parsed_body.table} and kind $${parsed_body.kind}` + const logMessage = `Ignoring notification for table ${parsed_body.table} and kind ${parsed_body.kind}` console.log(logMessage) return { diff --git a/templates/run-glue-job.js.tpl b/lambdas/run-glue-job.js similarity index 93% rename from templates/run-glue-job.js.tpl rename to lambdas/run-glue-job.js index ace039b..8391c16 100644 --- a/templates/run-glue-job.js.tpl +++ b/lambdas/run-glue-job.js @@ -5,7 +5,7 @@ const AWS = require('aws-sdk') AWS.config.update({region: process.env.AWS_REGION}) const glue = new AWS.Glue() -const jobName = '${glue_job_name}' +const jobName = process.env.GLUE_JOB_NAME exports.handler = async function (event, context) { return new Promise((resolve, reject) => { diff --git a/run_glue_crawler.tf b/run_glue_crawler.tf index d14a1fe..b7ce98a 100644 --- a/run_glue_crawler.tf +++ b/run_glue_crawler.tf @@ -1,19 +1,7 @@ -data "template_file" "run_glue_crawler_script" { - template = file("${path.module}/templates/run-glue-crawler.js.tpl") - - vars = { - glue_crawler_name = aws_glue_crawler.signatures_crawler.name - } -} - data "archive_file" "run_glue_crawler_zip" { type = "zip" - - source { - content = "${data.template_file.run_glue_crawler_script.rendered}" - filename = "index.js" - } - + + source_file = "${path.module}/lambdas/run-glue-crawler.js" output_path = "${path.module}/lambdas/run-glue-crawler.zip" } @@ -25,6 +13,12 @@ resource "aws_lambda_function" "glue_crawler_lambda" { runtime = "nodejs12.x" timeout = 60 source_code_hash = data.archive_file.run_glue_crawler_zip.output_base64sha256 + + environment { + variables = { + GLUE_CRAWLER_NAME = aws_glue_crawler.signatures_crawler.name + } + } } resource "aws_lambda_event_source_mapping" "run_crawler_on_new_data_export_task" { diff --git a/run_glue_job.tf b/run_glue_job.tf index 2619034..4f0efb3 100644 --- a/run_glue_job.tf +++ b/run_glue_job.tf @@ -1,19 +1,7 @@ -data "template_file" "run_glue_job_script" { - template = file("${path.module}/templates/run-glue-job.js.tpl") - - vars = { - glue_job_name = aws_glue_job.signatures_full.id - } -} - data "archive_file" "run_glue_job_zip" { type = "zip" - source { - content = "${data.template_file.run_glue_job_script.rendered}" - filename = "index.js" - } - + source_file = "${path.module}/lambdas/run-glue-job.js" output_path = "${path.module}/lambdas/run-glue-job.zip" } @@ -25,6 +13,12 @@ resource "aws_lambda_function" "glue_job_lambda" { runtime = "nodejs12.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" {