指定 aws ECS/Fargate 容器依赖项部署失败
specifying aws ECS/Fargate container dependency fails to deply
我使用 aws-cdk Python 语言获得了以下代码,但部署失败,出现 redis_container 不可用错误,我做错了什么,我希望首先启动 redis 容器,然后然后剩下的。也许我对容器依赖的理解不正确??
ecs_redis_task = ecs.FargateTaskDefinition(self,
id = 'redis',
cpu=512,
memory_limit_mib =1024
)
redis_container = ecs_redis_task.add_container(id = 'redis_container',
image = img_.from_ecr_repository(repository=repo_, tag='redis_5.0.5')
)
redis_container.add_port_mappings({
'containerPort' : 6379
})
redis_dependency = ecs.ContainerDependency(container = redis_container, condition = ecs.ContainerDependencyCondition.HEALTHY)
ecs_webserver_task = ecs.FargateTaskDefinition(self,
id = 'webserver',
cpu=256,
memory_limit_mib =512
)
webserver_container = ecs_webserver_task.add_container(id = 'webserver_container',
image = img_.from_ecr_repository(repository=repo_, tag='airflow_1.10.9')
)
webserver_container.add_port_mappings({
'containerPort' : 8080
})
webserver_container.add_container_dependencies(redis_dependency)
如果我删除依赖代码,它可以正常部署!
错误:
12/24 | 2:46:51 PM | CREATE_FAILED | AWS::ECS::TaskDefinition | webserver (webserverEE139216) Cannot depend on container + 'redis_container' because it does not exist (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: 81828979-9e65-474e-ab0e-b163168d5613)
我刚刚尝试了这段代码,它按预期工作,在任务定义中添加了依赖项,唯一改变的是图像 1:
from aws_cdk import (
#aws_s3 as s3,
aws_ecs as ecs,
core
)
class HelloCdkStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
#bucket = s3.Bucket(self, "MyFirstBucket", versioned=True,)
ecs_redis_task = ecs.FargateTaskDefinition(self, id='redis', cpu=512, memory_limit_mib=1024)
redis_container = ecs_redis_task.add_container(id = 'redis_container', image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),)
redis_container.add_port_mappings({
'containerPort' : 6379
})
redis_dependency = ecs.ContainerDependency(container = redis_container, condition = ecs.ContainerDependencyCondition.HEALTHY)
ecs_webserver_task = ecs.FargateTaskDefinition(self, id='webserver', cpu=256, memory_limit_mib=512)
webserver_container = ecs_webserver_task.add_container(id = 'webserver_container', image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),)
webserver_container.add_port_mappings({
'containerPort' : 8080
})
webserver_container.add_container_dependencies(redis_dependency)
cdk 合成后的 CloudFormation:
"webserverEE139216": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"ContainerDefinitions": [
{
"DependsOn": [
{
"Condition": "HEALTHY",
"ContainerName": "redis_container"
}
],
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Name": "webserver_container",
"PortMappings": [
{
"ContainerPort": 8080,
"Protocol": "tcp"
}
]
}
],
我使用 aws-cdk Python 语言获得了以下代码,但部署失败,出现 redis_container 不可用错误,我做错了什么,我希望首先启动 redis 容器,然后然后剩下的。也许我对容器依赖的理解不正确??
ecs_redis_task = ecs.FargateTaskDefinition(self,
id = 'redis',
cpu=512,
memory_limit_mib =1024
)
redis_container = ecs_redis_task.add_container(id = 'redis_container',
image = img_.from_ecr_repository(repository=repo_, tag='redis_5.0.5')
)
redis_container.add_port_mappings({
'containerPort' : 6379
})
redis_dependency = ecs.ContainerDependency(container = redis_container, condition = ecs.ContainerDependencyCondition.HEALTHY)
ecs_webserver_task = ecs.FargateTaskDefinition(self,
id = 'webserver',
cpu=256,
memory_limit_mib =512
)
webserver_container = ecs_webserver_task.add_container(id = 'webserver_container',
image = img_.from_ecr_repository(repository=repo_, tag='airflow_1.10.9')
)
webserver_container.add_port_mappings({
'containerPort' : 8080
})
webserver_container.add_container_dependencies(redis_dependency)
如果我删除依赖代码,它可以正常部署!
错误:
12/24 | 2:46:51 PM | CREATE_FAILED | AWS::ECS::TaskDefinition | webserver (webserverEE139216) Cannot depend on container + 'redis_container' because it does not exist (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: 81828979-9e65-474e-ab0e-b163168d5613)
我刚刚尝试了这段代码,它按预期工作,在任务定义中添加了依赖项,唯一改变的是图像 1:
from aws_cdk import (
#aws_s3 as s3,
aws_ecs as ecs,
core
)
class HelloCdkStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
#bucket = s3.Bucket(self, "MyFirstBucket", versioned=True,)
ecs_redis_task = ecs.FargateTaskDefinition(self, id='redis', cpu=512, memory_limit_mib=1024)
redis_container = ecs_redis_task.add_container(id = 'redis_container', image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),)
redis_container.add_port_mappings({
'containerPort' : 6379
})
redis_dependency = ecs.ContainerDependency(container = redis_container, condition = ecs.ContainerDependencyCondition.HEALTHY)
ecs_webserver_task = ecs.FargateTaskDefinition(self, id='webserver', cpu=256, memory_limit_mib=512)
webserver_container = ecs_webserver_task.add_container(id = 'webserver_container', image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),)
webserver_container.add_port_mappings({
'containerPort' : 8080
})
webserver_container.add_container_dependencies(redis_dependency)
cdk 合成后的 CloudFormation:
"webserverEE139216": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"ContainerDefinitions": [
{
"DependsOn": [
{
"Condition": "HEALTHY",
"ContainerName": "redis_container"
}
],
"Essential": true,
"Image": "amazon/amazon-ecs-sample",
"Name": "webserver_container",
"PortMappings": [
{
"ContainerPort": 8080,
"Protocol": "tcp"
}
]
}
],