Kumar
Kumar

Reputation: 209

Lambda Environment variable from AWS SSM

I want to store a webhook URL in AWS SSM parameter store and pass the value to the lambda environment variable using terraform. When I ran the terraform, the lambdas environment variable doesn't get the value from the SSM parameter store.Any idea if this is possible thru terraform without updating lambda code?

Lambda Env Variable:

WEBHOOK_URL :

data.aws_ssm_parameter.ecr_scan_notify_ssm.value

Config:

resource "aws_ssm_parameter" "ecr_scan_notify_ssm" {
    name      = "ecr_scan_notify_ssm"
    type      = "SecureString"
    value     = "not defined here"
    overwrite = false
    lifecycle {
        ignore_changes = [value,]
        }
    }

data "aws_ssm_parameter" "ecr_scan_notify_ssm" {
  name      = "ecr_scan_notify_ssm"
}

environment {
   variables = {
   WEBHOOK_URL = "data.aws_ssm_parameter.ecr_scan_notify_ssm.value"
   CHANNEL     = "test-scan"
  }
}

Upvotes: 0

Views: 3033

Answers (1)

Mark B
Mark B

Reputation: 200537

You're just passing a hard-coded string "data.aws_ssm_parameter.ecr_scan_notify_ssm.value". There is no lookup happening here. You either need to use string interpolation syntax:

WEBHOOK_URL = "${data.aws_ssm_parameter.ecr_scan_notify_ssm.value}"

Or just reference the value directly:

WEBHOOK_URL = data.aws_ssm_parameter.ecr_scan_notify_ssm.value

Upvotes: 4

Related Questions