I am new to CDK and I don't manage to find a way to change the Name tag of the EC2 instances created by an AutoScaling Group when used as a capacity provider for ECS.
Here is my code:
const cluster = new ecs.Cluster (
this,
"ECSCluster",
{
clusterName: "myCluster",
vpc: my-vpc
}
);
const autoScalingGroup = new autoscaling.AutoScalingGroup (
this,
"autoScalingGroup",
{
autoScalingGroupName: "myAutoScalingGroup",
vpc: my-vpc,
instanceType: new ec2.InstanceType("t3.2xlarge"),
...
}
);
const capacityProvider = new ecs.AsgCapacityProvider (
this,
"capacityProvider",
{ autoScalingGroup }
);
cluster.addAsgCapacityProvider(capacityProvider);
So this code works and it creates well my EC2 instances within an ECS cluster. The issue is I would like to change the Name tag which is a concatenation of the stack ID and the autoScalingGroup ID. So for me it's "ECSStack/autoScalingGroup".
How can I change the EC2 instances' Name tag?
Thank you for your help :)
Well, I found! Actually you don't have to retag the stack but autoScalingGroup instead. Here is the command based on the variables I have written above
Tags.of(autoScalingGroup).add("Name", "my-ecs")