使用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,
)
集群名称和ecs服务名称已经存在。
我想使用cdk python将现有的群集和服务导入到code_pipeline中。
但这不起作用。
请指导我如何定义service=ecs.IBaseService
谢谢。
答案 0 :(得分:1)
有一种方法可以导入现有的ECS群集 from_cluster_attributes。
CDK有多个问题或缺陷,因此可能无法正常工作。例如,从from方法导入现有VPC无效(不确定是否已修复)。
答案 1 :(得分: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)