From 6e06666346d0731d61f3c27bd53fa189cd20cb95 Mon Sep 17 00:00:00 2001 From: Stuart Kemp Date: Wed, 12 Feb 2020 15:58:48 +0000 Subject: [PATCH 1/2] Switched to urllib3 for requests as its bundled botocore (boto3) --- update_security_groups_lambda/update_security_groups.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/update_security_groups_lambda/update_security_groups.py b/update_security_groups_lambda/update_security_groups.py index 4e848e8..2e447cd 100644 --- a/update_security_groups_lambda/update_security_groups.py +++ b/update_security_groups_lambda/update_security_groups.py @@ -17,7 +17,7 @@ import json import logging import os -import urllib.request, urllib.error, urllib.parse +import urllib3.request logger = logging.getLogger(__name__) @@ -69,7 +69,8 @@ def lambda_handler(event, context): def get_ip_groups_json(url, expected_hash): logger.info("Updating from " + url) - response = urllib.request.urlopen(url) + http = urllib3.PoolManager() + response = http.request('GET', url) ip_json = response.read() m = hashlib.md5() From 524066f2a8b31534e617a62ec44e09c560f9555a Mon Sep 17 00:00:00 2001 From: Stuart Kemp Date: Wed, 12 Feb 2020 16:24:16 +0000 Subject: [PATCH 2/2] Read urllib3 response correctly. Passes test. --- update_security_groups_lambda/update_security_groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update_security_groups_lambda/update_security_groups.py b/update_security_groups_lambda/update_security_groups.py index 2e447cd..2c3e7e9 100644 --- a/update_security_groups_lambda/update_security_groups.py +++ b/update_security_groups_lambda/update_security_groups.py @@ -71,7 +71,7 @@ def get_ip_groups_json(url, expected_hash): http = urllib3.PoolManager() response = http.request('GET', url) - ip_json = response.read() + ip_json = response.data m = hashlib.md5() m.update(ip_json)