From 3498b840c918aa6f036ab6c02ddaffd710e8c3cb Mon Sep 17 00:00:00 2001 From: bqbn Date: Mon, 13 Jun 2016 08:19:42 -0700 Subject: [PATCH] Fixes #16095: Maximumly 199 filter values (#16184) When making calls to AWS EC2 api with DescribeTags actiion and if the number of filter values is greater than or equal to 200, it results in 400 bad request reply and the error message is: "Error connecting to AWS backend.\n The maximum number of filter values specified on a single call is 200". The change is so that we call get_all_tags with maximum 199 filter values one at a time until all are consumed. --- contrib/inventory/ec2.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index bf3ba28ea06..9c565fdf798 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -527,7 +527,12 @@ class Ec2Inventory(object): instance_ids = [] for reservation in reservations: instance_ids.extend([instance.id for instance in reservation.instances]) - tags = conn.get_all_tags(filters={'resource-type': 'instance', 'resource-id': instance_ids}) + + max_filter_value = 199 + tags = [] + for i in range(0, len(instance_ids), max_filter_value): + tags.extend(conn.get_all_tags(filters={'resource-type': 'instance', 'resource-id': instance_ids[i:i+max_filter_value]})) + tags_by_instance_id = defaultdict(dict) for tag in tags: tags_by_instance_id[tag.res_id][tag.name] = tag.value