来自 AWS SSM 的 Lambda 环境变量

Lambda Environment variable from AWS SSM

我想在 AWS SSM 参数存储中存储一个 webhook URL 并使用 terraform 将值传递给 lambda 环境变量。当我 运行 terraform 时,lambdas 环境变量没有从 SSM 参数中获取值 store.Any 想知道这是否可以通过 terraform 而不更新 lambda 代码?

Lambda Env Variable:

WEBHOOK_URL :

data.aws_ssm_parameter.ecr_scan_notify_ssm.value

配置:

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"
  }
}

您只是传递了一个硬编码字符串 "data.aws_ssm_parameter.ecr_scan_notify_ssm.value"。这里没有查找发生。您要么需要使用字符串插值语法:

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

或者直接引用值:

WEBHOOK_URL = data.aws_ssm_parameter.ecr_scan_notify_ssm.value