简体   繁体   English

指定 aws ECS/Fargate 容器依赖项无法部署

[英]specifying aws ECS/Fargate container dependency fails to deply

I got the below code using aws-cdk Python language but is failing to deploy, with redis_container not available error, what am I doing wrong, I want redis container to start first and then the rest.我使用 aws-cdk Python 语言得到了以下代码,但无法部署,出现 redis_container not available 错误,我做错了什么,我希望 redis 容器先启动,然后再启动 Z65E88600B5C68A1B907D54BF7010394BF316E183E67Z 容器maybe my understanding of the container dependency is not correct??也许我对容器依赖的理解不正确??

        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)

If I remove the dependency code, it deploys fine!如果我删除依赖代码,它部署得很好!

Error:错误:

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)

I just tried this code and it works as expected adding the dependency in the Task definition, only thing changed from your code is the image 1 :我刚刚尝试了这段代码,它按预期工作,在任务定义中添加了依赖项,你的代码中唯一改变的是图像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)

CloudFormation after cdk synth: 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"
              }
            ]
          }
        ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Aws X 射线不适用于 fargate 上的边车容器 - Aws x-ray doesn't work for a sidecar container on fargate AWS CDK 并在现有 ALB 上创建 ECS/Fargate 服务。 使用现有的监听器? - AWS CDK and creating ECS/Fargate Service on existing ALB. Use existing listener? 将参数传递给在AWS Fargate上的Docker容器中运行的Python - Pass arguments to Python running in Docker container on AWS Fargate 无法使用 python SDK 在 ECS fargate 作业上发送邮件,并在另一个 aws 帐户中使用经过验证的 SES 的凭据 - Unable to send mail on an ECS fargate job using python SDK with credentials of a verified SES in another aws account 将环境变量传递给 ECS Fargate 任务的容器的正确 python CDK 语法是什么? - What is the correct python CDK syntax for passing environment variables to an ECS Fargate task's container? 在 ECS Fargate 中操作 Celery Worker - Operating the Celery Worker in the ECS Fargate AWS ECS 上的容器中的 Scapy 不下载或创建文件 - Scapy in container on AWS ECS does not download or create files 如何从 AWS ECS 上的容器中检索私有 IP? - How can I retrieve private IP from a container on AWS ECS? 如果 Flask 入口点失败,则让 Amazon ECS 容器退出 - Get Amazon ECS container to exit if Flask Entrypoint fails 在 ECS fargate 中运行前端和后端服务 - Run front end and Backend services in ECS fargate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM