Don't error out on route53.list_tags_for_resource when resource has no tags

Without the added `return {}`, calling route53.list_tags_for_resource
when called with a ResourceId of a resource without any tags would
result in the error:
    jinja2.exceptions.UndefinedError: 'None' has no attribute 'items'

Because the LIST_TAGS_FOR_RESOURCE_RESPONSE was given None instead of
empty dict.

This now allows list_tags_for_resource to be called without issue on
tag-less resources.
This commit is contained in:
Don Kuntz 2019-08-28 13:55:19 -05:00
parent 3a5d857a60
commit 35507f33df
No known key found for this signature in database
GPG Key ID: 24499CE2571D5CEB
2 changed files with 8 additions and 0 deletions

View File

@ -305,6 +305,7 @@ class Route53Backend(BaseBackend):
def list_tags_for_resource(self, resource_id):
if resource_id in self.resource_tags:
return self.resource_tags[resource_id]
return {}
def get_all_hosted_zones(self):
return self.zones.values()

View File

@ -404,6 +404,13 @@ def test_list_or_change_tags_for_resource_request():
)
healthcheck_id = health_check['HealthCheck']['Id']
# confirm this works for resources with zero tags
response = conn.list_tags_for_resource(
ResourceType="healthcheck", ResourceId=healthcheck_id)
response["ResourceTagSet"]["Tags"].should.be.empty
print(response)
tag1 = {"Key": "Deploy", "Value": "True"}
tag2 = {"Key": "Name", "Value": "UnitTest"}