Reputation: 2229
Hi I am working on AWS CDK. I am creating ECS. I have created auto scaling group as below.
autoScallingGroup=asg.AutoScalingGroup(self, id = "auto scalling", vpc= vpc, machine_image=ecs.EcsOptimizedImage.amazon_linux(), desired_capacity=1, key_name="mws-location", max_capacity=1, min_capacity=1, instance_type=ec2.InstanceType("t2.xlarge"))
This will generate default launch configuration also. I want to write my own launch configuration for this auto scaling group.
Can someone help me to fix this? Any help would be appreciated. Thanks
Upvotes: 5
Views: 3153
Reputation: 5625
There is no specific construct to create a launch configuration in CDK. However, you can construct one by passing in arguments to aws_autoscaling.AutoScalingGroup constructor.
You need to specifiy the following attributes of AutoScalingGroup class:
You can also add security groups using the add_security_group()
function.
For example, if you want to add user data to the LaunchConfig:
userdata = ec2.UserData.for_linux(shebang="#!/bin/bash -xe")
userdata.add_commands(
"echo '======================================================='",
"echo \"ECS_CLUSTER=${MWSServiceCluster}\" >> /etc/ecs/ecs.config"
)
asg = autoscaling.AutoScalingGroup(
self,
"asg-identifier",
...
user_data=userdata,
)
Upvotes: 4