Python 指定aws ECS/Fargate容器依赖项失败
我使用aws cdk Python语言获得了以下代码,但部署失败,出现redis_容器不可用错误,我做错了什么,我希望redis容器先启动,然后再启动其余的。也许我对容器依赖性的理解不正确Python 指定aws ECS/Fargate容器依赖项失败,python,amazon-web-services,amazon-ecs,aws-fargate,aws-cdk,Python,Amazon Web Services,Amazon Ecs,Aws Fargate,Aws Cdk,我使用aws cdk Python语言获得了以下代码,但部署失败,出现redis_容器不可用错误,我做错了什么,我希望redis容器先启动,然后再启动其余的。也许我对容器依赖性的理解不正确 ecs_redis_task = ecs.FargateTaskDefinition(self, id = 'redis', cpu=512, memory_limit_mib =1024 ) redis_con
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)
我刚刚尝试了这段代码,它在任务定义中添加依赖项后效果如预期,代码中唯一改变的是图像: cdk合成后的云形成:
"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"
}
]
}
],
确切的错误是什么添加了错误,它没有提供太多这是不允许的循环依赖项。@shariqmaws您能指出循环依赖项在哪里吗?感谢您的回答,我能够解决这个问题,看起来ecr.Repository.from_Repository_name没有返回正确的引用:arn看起来像arn:${Token[AWS::Partition.3]}:ecr:${Token[AWS::Region.4]}:${Token[AWS::AccountId.0]}:Repository/afflow将其更改为ecr.Repository.from_Repository_arn现在引用工作正常。arn:aws:ecr:us-east-1:XXXXXXXXXX:repository/airflow
"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"
}
]
}
],