Taragolis commented on PR #35163: URL: https://github.com/apache/airflow/pull/35163#issuecomment-1777884728
If you need create boto3 client then is already exists `AwsBaseHook(aws_conn_id="foo", client_type="one-of-355-aws-service").conn` maybe this behaviour not well documented --- Let's compare abstract Hooks (this is worst possible a worst possible scenario) ```python class AwsServiceNameThick(AwsBaseHook): def __init__(self, foo: str, spam: str, *args, **kwargs) -> None: kwargs.update(dict(client_type="service", resource_type=None)) super().__init__(*args, **kwargs) self.foo = foo self.spam = spam def method1(self): if self.foo == "bar": ... def method2(self): if self.spam == "egg": ... ``` ```python class AwsServiceNameThin(AwsBaseHook): def __init__(self, *args, **kwargs) -> None: kwargs.update(dict(client_type="service", resource_type=None)) super().__init__(*args, **kwargs) def method1(self, foo: str): if foo == "bar": ... def method2(self, spam: str): if spam == "egg": ... ``` `AwsServiceNameThick` - `foo` and `bar` uses only for specific methods, but mandatory. In case if you need to run same method multiple times with same credentials then you need to create new Hook object ```python hook1 = AwsServiceNameThick("bar", "spam", aws_conn_i) hook1.method1() hook2 = AwsServiceNameThick("baz", "qux") hook2.method1() ``` or change attribute 🙄 ```python hook = AwsServiceNameThick("bar", "spam) hook.method1() hook.foo = "baz" hook.method1() ``` In opposite `AwsServiceNameThin` still would works in user code as `AwsServiceNameThin("aws_default", "eu-west-1")`, do not required to recreate it ```python hook = AwsServiceNameThin() hook.method1("bar") hook.method1("baz") ``` --- Most of the hooks with class attributes created years ago, all new one usually created as ``` class AwsServiceNameThin(AwsBaseHook): def __init__(self, *args, **kwargs) -> None: ... ``` This is not complete list but pattern the same [DynamoDBHook](https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/hooks/dynamodb.py#L27): Table names and table keys, for a long period of time it was mandatory fields and usage of this Hook was limited by single transfer operator. [BatchClientHook](https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/hooks/batch_client.py) class attributes as hook configurations, class instance attributes which not relevant for all methods [S3Hook](https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/hooks/s3.py): Defined as client but also required resource-specific objects. Object attributes simultaneously use in methods. [Ec2Hook](https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/hooks/ec2.py): could create boto3.client or boto3.resource, depend on hook specific constructor attribute `api_type` 🙄 [GlueJobHook](https://github.com/apache/airflow/blob/main/airflow/providers/amazon/aws/hooks/glue.py): My favorite one seems like it created by support only specific thing around Glue service, however it also uses in places where all parameters non relevant and methods implement own methods -- 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. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org