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
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,
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With