无法在 ApplicationLoadBalancedFargateService 中为容器设置环境变量
Can't set environment variables for container in ApplicationLoadBalancedFargateService
(CDK 1.18.0 和 Python 3.6)
task_role = iam.Role(
self,
id=f"...",
assumed_by=iam.ServicePrincipal("ecs-tasks.amazonaws.com"),
managed_policies=[...]
)
repo = get_repo(self)
task_def = ecs.FargateTaskDefinition(
self,
"...",
memory_limit_mib=30720,
cpu=4096,
task_role=task_role,
execution_role=self.ecs_execution_role,
)
cont = task_def.add_container(
"...",
image=ecs.ContainerImage.from_ecr_repository(repo),
logging=ecs.LogDrivers.aws_logs(stream_prefix=f"Logging"),
command=["bash", "start.sh"],
environment={"NAME1": 'VALUE1', "NAME2": 'VALUE2'} # what would I have to put here?
)
cont.add_port_mappings(ecs.PortMapping(container_port=8080))
fg = ecsp.ApplicationLoadBalancedFargateService(
self,
"...",
task_definition=task_def,
assign_public_ip=True,
)
我想将 NAME1=VALUE1 和 NAME2=VALUE2 传递给容器。
我尝试了各种表达环境变量的方式。但是 none 有效。我在这里做错了什么吗?
除此特定问题外,服务部署和运行。
您采用的方法似乎适用于最新版本 (1.23.0)。但是我在发行说明中找不到任何提示为什么这可能已经改变。可以更新到最新版本吗?
task_def.add_container("container", environment={"a": "b", "c": "d"}, image=aws_ecs.ContainerImage.from_registry(name="TestImage"), memory_limit_mib=512)
newtask1C300F30:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Environment:
- Name: a
Value: b
- Name: c
Value: d
Essential: true
Image: TestImage
Memory: 512
Name: container
(CDK 1.18.0 和 Python 3.6)
task_role = iam.Role(
self,
id=f"...",
assumed_by=iam.ServicePrincipal("ecs-tasks.amazonaws.com"),
managed_policies=[...]
)
repo = get_repo(self)
task_def = ecs.FargateTaskDefinition(
self,
"...",
memory_limit_mib=30720,
cpu=4096,
task_role=task_role,
execution_role=self.ecs_execution_role,
)
cont = task_def.add_container(
"...",
image=ecs.ContainerImage.from_ecr_repository(repo),
logging=ecs.LogDrivers.aws_logs(stream_prefix=f"Logging"),
command=["bash", "start.sh"],
environment={"NAME1": 'VALUE1', "NAME2": 'VALUE2'} # what would I have to put here?
)
cont.add_port_mappings(ecs.PortMapping(container_port=8080))
fg = ecsp.ApplicationLoadBalancedFargateService(
self,
"...",
task_definition=task_def,
assign_public_ip=True,
)
我想将 NAME1=VALUE1 和 NAME2=VALUE2 传递给容器。
我尝试了各种表达环境变量的方式。但是 none 有效。我在这里做错了什么吗?
除此特定问题外,服务部署和运行。
您采用的方法似乎适用于最新版本 (1.23.0)。但是我在发行说明中找不到任何提示为什么这可能已经改变。可以更新到最新版本吗?
task_def.add_container("container", environment={"a": "b", "c": "d"}, image=aws_ecs.ContainerImage.from_registry(name="TestImage"), memory_limit_mib=512)
newtask1C300F30:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Environment:
- Name: a
Value: b
- Name: c
Value: d
Essential: true
Image: TestImage
Memory: 512
Name: container