Repository: cloud-custodian/cloud-custodian

Issue:
Update Lambda deployments via mu to default to Python 3.7
According to https://pythonclock.org/ support will end 1/1/2020, which is starting to get close enough that upgrading mu.py to at least default of the python 3.7 runtime should be done. 


Discussion:
thanks for filing we should definitely start going this way.  i didn't even realize lambda had a 3.7 runtime available. 

there's one last item on 3x that we need to cover off on #3087, its more user experience on the cli though. 

we'll also need to do some testing on migration and cross uploads from different cli language runtimes, probably a manual effort. 
That news was so 24 hours ago ;-). https://aws.amazon.com/about-aws/whats-new/2018/11/aws-lambda-supports-python-37/

Resolving patch:
diff --git a/c7n/handler.py b/c7n/handler.py
--- a/c7n/handler.py
+++ b/c7n/handler.py
@@ -33,6 +33,7 @@
 
 logging.root.setLevel(logging.DEBUG)
 logging.getLogger('botocore').setLevel(logging.WARNING)
+logging.getLogger('urllib3').setLevel(logging.WARNING)
 log = logging.getLogger('custodian.lambda')
 
 account_id = None
diff --git a/c7n/mu.py b/c7n/mu.py
--- a/c7n/mu.py
+++ b/c7n/mu.py
@@ -296,6 +296,8 @@ def publish(self, func, alias=None, role=None, s3_uri=None):
                     e, func.alias)
         return result
 
+    add = publish
+
     def remove(self, func, alias=None):
         for e in func.get_events(self.session_factory):
             e.remove(func)
@@ -735,7 +737,7 @@ def role(self):
 
     @property
     def runtime(self):
-        return self.policy.data['mode'].get('runtime', 'python2.7')
+        return self.policy.data['mode'].get('runtime', 'python3.7')
 
     @property
     def memory_size(self):
diff --git a/c7n/query.py b/c7n/query.py
--- a/c7n/query.py
+++ b/c7n/query.py
@@ -210,9 +210,11 @@ def _napi(op_name):
 @sources.register('describe')
 class DescribeSource(object):
 
+    QueryFactory = ResourceQuery
+
     def __init__(self, manager):
         self.manager = manager
-        self.query = ResourceQuery(self.manager.session_factory)
+        self.query = self.QueryFactory(self.manager.session_factory)
 
     def get_resources(self, ids, cache=True):
         return self.query.get(self.manager, ids)


Test patch:
diff --git a/tests/test_mu.py b/tests/test_mu.py
--- a/tests/test_mu.py
+++ b/tests/test_mu.py
@@ -263,7 +263,7 @@ def test_cwe_update_config_and_code(self):
             {
                 "resource": "s3",
                 "name": "s3-bucket-policy",
-                "mode": {"type": "cloudtrail", "events": ["CreateBucket"]},
+                "mode": {"type": "cloudtrail", "events": ["CreateBucket"], 'runtime': 'python2.7'},
                 "filters": [
                     {
                         "type": "missing-policy-statement",
@@ -286,6 +286,7 @@ def test_cwe_update_config_and_code(self):
                 "mode": {
                     "type": "cloudtrail",
                     "memory": 256,
+                    'runtime': 'python2.7',
                     "events": [
                         "CreateBucket",
                         {
@@ -737,7 +738,7 @@ def test_config_defaults(self):
                 "KMSKeyArn": "",
                 "MemorySize": 512,
                 "Role": "",
-                "Runtime": "python2.7",
+                "Runtime": "python3.7",
                 "Tags": {},
                 "Timeout": 60,
                 "TracingConfig": {"Mode": "PassThrough"},