Thanh Nguyen Van
Thanh Nguyen Van

Reputation: 11752

How to import the existing ECS Service into code_pipeline using cdk python

After I deployed ECS Cluster using EC2 instances.

Now I would like to write code_pipeline for deploying service to ECS Service cluster.

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

Cluster_name and ecs service_name have already existed.

I would like to import the existing cluster and service into code_pipeline using cdk python.

But it does not work.

Please guild me how to define service=ecs.IBaseService

Upvotes: 0

Views: 1693

Answers (2)

Espoir Murhabazi
Espoir Murhabazi

Reputation: 6376

As mentionned in this answer we need the from_cluster_attributes function.

But you need to provide the vpc instance as well as the security group .

Here is the full code:

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)

Upvotes: 2

mon
mon

Reputation: 22234

There is a method to import an existing ECS cluster from_cluster_attributes.

CDK has multiple issues or defects so it may not work. For instance, from method to import an existing VPC did not work (not sure if it has been fixed).

Upvotes: 1

Related Questions