【问题标题】:How to import the existing ECS Service into code_pipeline using cdk python如何使用 cdk python 将现有 ECS 服务导入 code_pipeline
【发布时间】:2021-01-29 01:18:12
【问题描述】:

在我使用 EC2 实例部署 ECS 集群之后。

现在我想编写 code_pipeline 用于将服务部署到 ECS 服务集群。

deploy_actions = aws_codepipeline_actions.EcsDeployAction(
                action_name="DeployAction",
                service=ecs.IBaseService(cluster=cluster_name,service=service_name),
                input=build_output,
            )

Cluster_name 和 ecs service_name 已经存在。

我想使用 cdk python 将现有集群和服务导入 code_pipeline。

但它不起作用。

请教我如何定义service=ecs.IBaseService

【问题讨论】:

    标签: python amazon-ecs aws-cdk


    【解决方案1】:

    正如this answer 中提到的,我们需要from_cluster_attributes 函数。

    但您需要提供 vpc 实例以及安全组。

    这里是完整的代码:

    vpc = ec2.Vpc.from_lookup(self, "spin",vpc_id ='vpc-')
    security_group = ec2.SecurityGroup.from_security_group_id(self, 'r-sg', 'sg-')
    cluster = ecs.Cluster.from_cluster_attributes(self, cluster_name="-pi",
                                                  security_groups[security_group], 
                                                  id="i-0", vpc=vpc)
    

    【讨论】:

      【解决方案2】:

      有一种方法可以导入现有的ECS集群 from_cluster_attributes

      CDK 存在多个问题或缺陷,因此可能无法正常工作。例如,导入现有 VPC 的 from 方法不起作用(不确定是否已修复)。

      【讨论】:

      • 是的,我正在使用from_ec2_service_attributes 导入ecs服务
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2020-03-22
      • 2021-10-17
      • 1970-01-01
      相关资源
      最近更新 更多