# AWS ALB Target group and instance association/dissociation.

**URL:** <https://forum.ansible.com/t/aws-alb-target-group-and-instance-association-dissociation/27999>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 10, 2018, 5:20am UTC](https://forum.ansible.com/t/aws-alb-target-group-and-instance-association-dissociation/27999 "2018-07-10T05:20:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bond](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bond](https://forum.ansible.com/u/Bond)\
**Post date:** [July 10, 2018, 5:20am UTC](https://forum.ansible.com/t/aws-alb-target-group-and-instance-association-dissociation/27999/1 "2018-07-10T05:20:04Z")

</div>

Hi,  
I am trying to understand the best way to remove and add an instance to a target group. Basically, what I want to do is

1. Query an ALB to get the list of the target groups by supplying the name of the ALB ( in a variable ).
2. Filter the list to get the target group that we need ( using a regular expression as the target group name can change from time to time ) from the list returned by the above query…
3. Remove an instance one at a time from the target group.
4. Apply updates on the instance.
5. Add the instance back to the target group.
6. Repeat 3-5.

Thanks.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [July 10, 2018, 5:35am UTC](https://forum.ansible.com/t/aws-alb-target-group-and-instance-association-dissociation/27999/2 "2018-07-10T05:35:18Z")

</div>

Why?

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [July 10, 2018, 12:31pm UTC](https://forum.ansible.com/t/aws-alb-target-group-and-instance-association-dissociation/27999/3 "2018-07-10T12:31:04Z")

</div>

Is this target group maintained by a scaling group, or are they all “pets”? A “pet” being an instance that is in some way uniquely configured.

The usual way to get things updated is to make a new AMI incorporating your changes, test the new AMI in a dev environment, then if all is well update the launch configuration to use the new AMI and start killing the running instances; they will be replaced by instances based on your new, improved AMI.

If you do have “pets”, go look at AWS System manager: [https://aws.amazon.com/systems-manager/](https://aws.amazon.com/systems-manager/)

Regards, K.

---

<div class="post-metadata">

**Author:** ![Bond](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bond](https://forum.ansible.com/u/Bond)\
**Post date:** [July 10, 2018, 5:32pm UTC](https://forum.ansible.com/t/aws-alb-target-group-and-instance-association-dissociation/27999/4 "2018-07-10T17:32:28Z")

</div>

Thanks for the reply. Basically, I am trying to do a deployment like what we usually do in the instances connected to an ELB. I do not need to update the AMI for the deployment.  
Basically, if there are 2 instances behind the target group, I would take one of them out first, do the deployment and put it back to the target group. I would repeat the same for the other instance too.
