You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/04 11:58:38 UTC

[GitHub] [airflow] baolsen commented on a change in pull request #7541: [AIRFLOW-6822] AWS hooks should cache boto3 client

baolsen commented on a change in pull request #7541: [AIRFLOW-6822] AWS hooks should cache boto3 client
URL: https://github.com/apache/airflow/pull/7541#discussion_r387620707
 
 

 ##########
 File path: airflow/providers/amazon/aws/hooks/base_aws.py
 ##########
 @@ -232,6 +261,38 @@ def get_resource_type(self, resource_type, region_name=None, config=None):
             resource_type, endpoint_url=endpoint_url, config=config, verify=self.verify
         )
 
+    @cached_property
+    def conn(self):
+        """Get the underlying boto3 client (cached).
+
+        The return value from this method is cached for efficiency.
+
+        :return: boto3.client or boto3.resource for the current
+            client/resource type and region
+        :rtype: boto3.client() or boto3.resource()
+        :raises AirflowException: self.client_type or self.resource_type are not
+            populated. These are usually specified to this class, by a subclass
+            __init__ method.
+        """
+        if self.client_type:
+            return self.get_client_type(self.client_type, region_name=self.region_name)
+        elif self.resource_type:
+            return self.get_resource_type(self.resource_type, region_name=self.region_name)
+        else:
+            raise AirflowException(
+                'Either self.client_type or self.resource_type'
+                ' must be specified in the subclass')
 
 Review comment:
   Yes, in the `__init__` I do the actual validation. The only way the client_type/resource_type could change after that is if a subclass changes it directly. It would represent a bug in the subclass implementation. Based on the Python docs on Exceptions, a NotImplementedError sounds like the best fit.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services