Skip to content

Instantly share code, notes, and snippets.

@samof76
Created February 18, 2020 12:24
Show Gist options
  • Save samof76/d7e6d9ec1b55a62df61c435381d81cf6 to your computer and use it in GitHub Desktop.
Save samof76/d7e6d9ec1b55a62df61c435381d81cf6 to your computer and use it in GitHub Desktop.
Update the NLB targets
# The following code gets the EKS endpoint IPs
endpoint = $eks_client.describe_cluster({name: eks_name}).data.cluster.endpoint
u = URI.parse(endpoint)
ips = []
txt = Resolv::DNS.open do |dns|
records = dns.getresources(u.host, Resolv::DNS::Resource::IN::A)
records.each {|r|
ips << r.address.to_s
}
# The following registers the IP on the target groups of the NLB
ips.each {|ip|
tgs << {:id => ip}
}
$elbv2_client.register_targets({:target_group_arn => tg_arn, :targets => tgs})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment