我正在尝试将RDS Aurora凭据设置为ECS任务的环境变量。
最初我在environments
上以明文形式传递它。
我知道正确的方法是使用secrets
,但是ApplicationLoadBalancedTaskImageOptions
需要一个Secret
,而rds.DatabaseCluster
返回另一种类型。
管理此案例中的凭据的正确方法是什么
task_image_options=ecs_patterns.ApplicationLoadBalancedTaskImageOptions(
image=ecs.ContainerImage.from_registry("sonarqube:8.2-community"),
container_port=9000,
# FIXME: by documentation this is the right way to pass creds, however this fail, the database secret is not the same type than the expected
# secrets={
# "sonar.jdbc.password": ecs.Secret.from_secrets_manager(self.db.secret)
# },
environment={
'sonar.jdbc.url': url,
"sonar.jdbc.username": username,
"sonar.jdbc.password": self.db.secret.secret_value_from_json("password").to_string() #plaintext, FIXME
}
)
如果您想要使用来自秘密存储的值,那么它应该
secrets
而不是环境变量将环境变量替换为
secrets
,如下所示只需放置ARN,ECS将在运行时注入该值
设置所需的环境变量
那么你的情况呢
多好的德哈乌
两天前我发表了一篇关于这个话题的文章:
https://medium.com/@mchlfchr/i-tell-you-a-secret-provide-database-credentials-to-an-ecs-fargate-task-in-aws-cdk-339df4e3d071
在这里,您可以清楚地发现使用秘密和环境变量之间的差异
如果要将其作为机密传递,首先必须将该值存储在AWS SecretsManager或AWS参数存储中。然后,您将来自这两个服务之一的机密的ARN作为ECS任务定义中的值传递,ECS将在实例化容器时自动从SecretsManager或参数存储中提取实际值。这被记录在案here
相关问题 更多 >
编程相关推荐