您如何在应用程序代码中引用动态地形输出?

How do you reference a dynamic terraform output in application code?

我正在使用 terraform 创建一个 dynamodb table,table 的名称属性看起来像这样...

name = "${var.service}-${var.environment}-Item-table"

根据环境,名称可能是 items-service-dev-Item-tableitems-service-prod-Item-table。在我的应用程序代码 (JS) 中,我显然需要知道 table 的名称才能与之交互,但动态特性使其变得更加棘手。

我考虑过使用 terraform 和应用程序代码都引用的环境变量的路径,但它看起来很乱。处理此类问题的最佳做法是什么?

terraform 是否也在部署您的应用程序代码?通常,您会让 Terraform 在其部署的应用程序中将该值作为环境变量注入。

如果不可能,请将值存储在 AWS Parameter Store