Reputation: 16645
I have a script that needs to update a named AutoScalingGroup with a new LaunchConfiguration for some new just-created AMI. Unfortunately the documentation isn't good, and I'm tired of trial-and-error. This is what I have so far:
build_autoscale_name = "build_autoscaling"
build_autoscale_lc = LaunchConfiguration(
...launch config stuff...
, image_id=imid # new AMI
)
as_conn.create_launch_configuration(build_autoscale_lc)
ag = AutoScalingGroup(
group_name=build_autoscale_name
, launch_config=build_autoscale_lc
...other ASG stuff...
)
as_conn.create_auto_scaling_group(ag)
The latest way this is failing is with:
Launch Configuration by this name already exists
If I comment out the create_launch_configuration()
I then get:
AutoScalingGroup by this name already exists
I see AutoScalingGroup has an update
method; do I need to perhaps get_all_groups()
then do update with a new LaunchConfiguration with the same name? Or does it matter if I create a newly-named LaunchConfiguration
every time (i.e. will I run into some limit)?
Upvotes: 2
Views: 3543
Reputation: 580
I was experiencing a similar problem, when trying to update an existing autoscaling group, and managed to sort it out with the the process you suggested in your original post: using get_all_groups()
to fetch the autoscaling group, and then calling update()
on the object after updating the attributes.
Full example:
autoscaling_group_name = 'my-test-asg'
launch_config_name = 'my-test-lc'
launch_config = LaunchConfiguration( name=launch_config_name,
image_id=image_id,
key_name=ssh_key_name,
security_groups=security_groups,
user_data=user_data,
instance_type=instance_type,
associate_public_ip_address=associate_public_ip )
as_group = as_conn.get_all_groups(names=[autoscaling_group_name])[0]
setattr(as_group, launch_config_name, launch_config)
as_group.update()
Upvotes: 8
Reputation: 2282
I am not familiar with boto
, but I can clear few doubts about autoscaling in AWS. To update launch configuration of an autoscaling group you will have to create a new launch configuration and update the launch config for autoscaling group. You can either keep two names for launchconfig. So if the first name is in use then delete the launch config with the second name and create a new one with the second name after that update autoscaling group and same if launchconfig in use has the second name. So, you will have only two launch configs at a time.
Hope I have understood you problem correctly.
Upvotes: 2