如何从 Terraform 获取 AWS 机密到我的 docker 容器 运行 Python?

How can I get AWS secrets from Terraform into my docker container running Python?

我有一个 fargate 实例,运行 Python(Flask) Docker 个容器。我无法像从 Lambda 和我的本地主机那样读取 AWS 机密。系统在 30 秒后超时,我已经部分放弃了将其作为解决方案。 (问题是我的 Python 容器无法读取 AWS 机密管理器)但是我知道我可以将我的 AWS 机密导入 Terraform 并且我可以看到它们在 Terraform 中。

如何将这些变量作为全局变量从 Terraform 获取到我的 docker 容器中?无论如何注入它们然后用例如 os.environ.get("zzz)"?

读取它们

在你的aws_ecs_task_definition, when you specify container_definitions, you can provide secrets中:

The secrets to pass to the container. For more information, see Specifying Sensitive Data in the Amazon Elastic Container Service Developer Guide.

这允许您:

inject sensitive data into your containers by storing your sensitive data in either AWS Secrets Manager secrets or AWS Systems Manager Parameter Store parameters and then referencing them in your container definition.

因此,如果您将 container_definitions 修改为使用 secrets,它们将自动注入到您的容器中。