apache-airflow-providers-amazon 9.6.0__py3-none-any.whl → 9.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. airflow/providers/amazon/__init__.py +1 -1
  2. airflow/providers/amazon/aws/auth_manager/cli/avp_commands.py +15 -18
  3. airflow/providers/amazon/aws/auth_manager/router/login.py +1 -1
  4. airflow/providers/amazon/aws/executors/ecs/ecs_executor.py +3 -4
  5. airflow/providers/amazon/aws/executors/ecs/ecs_executor_config.py +1 -1
  6. airflow/providers/amazon/aws/executors/ecs/utils.py +1 -1
  7. airflow/providers/amazon/aws/hooks/athena.py +1 -1
  8. airflow/providers/amazon/aws/hooks/base_aws.py +12 -15
  9. airflow/providers/amazon/aws/hooks/batch_client.py +11 -0
  10. airflow/providers/amazon/aws/hooks/cloud_formation.py +1 -2
  11. airflow/providers/amazon/aws/hooks/datasync.py +2 -2
  12. airflow/providers/amazon/aws/hooks/dms.py +2 -3
  13. airflow/providers/amazon/aws/hooks/dynamodb.py +1 -2
  14. airflow/providers/amazon/aws/hooks/emr.py +14 -17
  15. airflow/providers/amazon/aws/hooks/glue.py +9 -13
  16. airflow/providers/amazon/aws/hooks/mwaa.py +6 -7
  17. airflow/providers/amazon/aws/hooks/redshift_data.py +1 -1
  18. airflow/providers/amazon/aws/hooks/redshift_sql.py +5 -6
  19. airflow/providers/amazon/aws/hooks/s3.py +3 -6
  20. airflow/providers/amazon/aws/hooks/sagemaker.py +6 -9
  21. airflow/providers/amazon/aws/hooks/sagemaker_unified_studio.py +5 -6
  22. airflow/providers/amazon/aws/links/base_aws.py +2 -2
  23. airflow/providers/amazon/aws/links/emr.py +2 -4
  24. airflow/providers/amazon/aws/log/cloudwatch_task_handler.py +3 -5
  25. airflow/providers/amazon/aws/log/s3_task_handler.py +1 -2
  26. airflow/providers/amazon/aws/operators/athena.py +1 -1
  27. airflow/providers/amazon/aws/operators/batch.py +37 -42
  28. airflow/providers/amazon/aws/operators/bedrock.py +1 -1
  29. airflow/providers/amazon/aws/operators/ecs.py +4 -6
  30. airflow/providers/amazon/aws/operators/eks.py +146 -139
  31. airflow/providers/amazon/aws/operators/emr.py +4 -5
  32. airflow/providers/amazon/aws/operators/mwaa.py +1 -1
  33. airflow/providers/amazon/aws/operators/neptune.py +2 -2
  34. airflow/providers/amazon/aws/operators/redshift_data.py +1 -2
  35. airflow/providers/amazon/aws/operators/s3.py +9 -13
  36. airflow/providers/amazon/aws/operators/sagemaker.py +11 -19
  37. airflow/providers/amazon/aws/secrets/secrets_manager.py +1 -2
  38. airflow/providers/amazon/aws/sensors/batch.py +33 -55
  39. airflow/providers/amazon/aws/sensors/eks.py +64 -54
  40. airflow/providers/amazon/aws/sensors/glacier.py +4 -5
  41. airflow/providers/amazon/aws/sensors/glue.py +6 -9
  42. airflow/providers/amazon/aws/sensors/glue_crawler.py +2 -4
  43. airflow/providers/amazon/aws/sensors/redshift_cluster.py +1 -1
  44. airflow/providers/amazon/aws/sensors/s3.py +1 -2
  45. airflow/providers/amazon/aws/sensors/sagemaker_unified_studio.py +4 -5
  46. airflow/providers/amazon/aws/sensors/sqs.py +1 -2
  47. airflow/providers/amazon/aws/utils/connection_wrapper.py +1 -1
  48. airflow/providers/amazon/aws/utils/sqs.py +1 -2
  49. airflow/providers/amazon/aws/utils/tags.py +2 -3
  50. airflow/providers/amazon/aws/waiters/mwaa.json +1 -1
  51. {apache_airflow_providers_amazon-9.6.0.dist-info → apache_airflow_providers_amazon-9.6.1.dist-info}/METADATA +8 -7
  52. {apache_airflow_providers_amazon-9.6.0.dist-info → apache_airflow_providers_amazon-9.6.1.dist-info}/RECORD +54 -54
  53. {apache_airflow_providers_amazon-9.6.0.dist-info → apache_airflow_providers_amazon-9.6.1.dist-info}/WHEEL +0 -0
  54. {apache_airflow_providers_amazon-9.6.0.dist-info → apache_airflow_providers_amazon-9.6.1.dist-info}/entry_points.txt +0 -0
@@ -28,12 +28,10 @@ from __future__ import annotations
28
28
 
29
29
  from collections.abc import Sequence
30
30
  from datetime import timedelta
31
- from functools import cached_property
32
31
  from typing import TYPE_CHECKING, Any
33
32
 
34
33
  from airflow.configuration import conf
35
34
  from airflow.exceptions import AirflowException
36
- from airflow.models import BaseOperator
37
35
  from airflow.models.mappedoperator import MappedOperator
38
36
  from airflow.providers.amazon.aws.hooks.batch_client import BatchClientHook
39
37
  from airflow.providers.amazon.aws.links.batch import (
@@ -42,18 +40,20 @@ from airflow.providers.amazon.aws.links.batch import (
42
40
  BatchJobQueueLink,
43
41
  )
44
42
  from airflow.providers.amazon.aws.links.logs import CloudWatchEventsLink
43
+ from airflow.providers.amazon.aws.operators.base_aws import AwsBaseOperator
45
44
  from airflow.providers.amazon.aws.triggers.batch import (
46
45
  BatchCreateComputeEnvironmentTrigger,
47
46
  BatchJobTrigger,
48
47
  )
49
48
  from airflow.providers.amazon.aws.utils import trim_none_values, validate_execute_complete_event
49
+ from airflow.providers.amazon.aws.utils.mixins import aws_template_fields
50
50
  from airflow.providers.amazon.aws.utils.task_log_fetcher import AwsTaskLogFetcher
51
51
 
52
52
  if TYPE_CHECKING:
53
53
  from airflow.utils.context import Context
54
54
 
55
55
 
56
- class BatchOperator(BaseOperator):
56
+ class BatchOperator(AwsBaseOperator[BatchClientHook]):
57
57
  """
58
58
  Execute a job on AWS Batch.
59
59
 
@@ -83,10 +83,14 @@ class BatchOperator(BaseOperator):
83
83
  polling is only used when waiters is None
84
84
  :param status_retries: number of HTTP retries to get job status, 10;
85
85
  polling is only used when waiters is None
86
- :param aws_conn_id: connection id of AWS credentials / region name. If None,
87
- credential boto3 strategy will be used.
88
- :param region_name: region name to use in AWS Hook.
89
- Override the region_name in connection (if provided)
86
+ :param aws_conn_id: The Airflow connection used for AWS credentials.
87
+ If this is ``None`` or empty then the default boto3 behaviour is used. If
88
+ running Airflow in a distributed manner and aws_conn_id is None or
89
+ empty, then default boto3 configuration would be used (and must be
90
+ maintained on each worker node).
91
+ :param region_name: AWS region_name. If not specified then the default boto3 behaviour is used.
92
+ :param verify: Whether or not to verify SSL certificates. See:
93
+ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
90
94
  :param tags: collection of tags to apply to the AWS Batch job submission
91
95
  if None, no tags are submitted
92
96
  :param deferrable: Run operator in the deferrable mode.
@@ -106,9 +110,11 @@ class BatchOperator(BaseOperator):
106
110
  waiter = waiters.get_waiter("JobComplete")
107
111
  """
108
112
 
113
+ aws_hook_class = BatchClientHook
114
+
109
115
  ui_color = "#c3dae0"
110
116
  arn: str | None = None
111
- template_fields: Sequence[str] = (
117
+ template_fields: Sequence[str] = aws_template_fields(
112
118
  "job_id",
113
119
  "job_name",
114
120
  "job_definition",
@@ -177,8 +183,6 @@ class BatchOperator(BaseOperator):
177
183
  waiters: Any | None = None,
178
184
  max_retries: int = 4200,
179
185
  status_retries: int | None = None,
180
- aws_conn_id: str | None = None,
181
- region_name: str | None = None,
182
186
  tags: dict | None = None,
183
187
  wait_for_completion: bool = True,
184
188
  deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
@@ -188,7 +192,7 @@ class BatchOperator(BaseOperator):
188
192
  submit_job_timeout: int | None = None,
189
193
  **kwargs,
190
194
  ) -> None:
191
- BaseOperator.__init__(self, **kwargs)
195
+ super().__init__(**kwargs)
192
196
  self.job_id = job_id
193
197
  self.job_name = job_name
194
198
  self.job_definition = job_definition
@@ -215,17 +219,14 @@ class BatchOperator(BaseOperator):
215
219
  # params for hook
216
220
  self.max_retries = max_retries
217
221
  self.status_retries = status_retries
218
- self.aws_conn_id = aws_conn_id
219
- self.region_name = region_name
220
-
221
- @cached_property
222
- def hook(self) -> BatchClientHook:
223
- return BatchClientHook(
224
- max_retries=self.max_retries,
225
- status_retries=self.status_retries,
226
- aws_conn_id=self.aws_conn_id,
227
- region_name=self.region_name,
228
- )
222
+
223
+ @property
224
+ def _hook_parameters(self):
225
+ return {
226
+ **super()._hook_parameters,
227
+ "max_retries": self.max_retries,
228
+ "status_retries": self.status_retries,
229
+ }
229
230
 
230
231
  def execute(self, context: Context) -> str | None:
231
232
  """
@@ -244,9 +245,9 @@ class BatchOperator(BaseOperator):
244
245
  if job_status == self.hook.SUCCESS_STATE:
245
246
  self.log.info("Job completed.")
246
247
  return self.job_id
247
- elif job_status == self.hook.FAILURE_STATE:
248
+ if job_status == self.hook.FAILURE_STATE:
248
249
  raise AirflowException(f"Error while running job: {self.job_id} is in {job_status} state")
249
- elif job_status in self.hook.INTERMEDIATE_STATES:
250
+ if job_status in self.hook.INTERMEDIATE_STATES:
250
251
  self.defer(
251
252
  timeout=self.execution_timeout,
252
253
  trigger=BatchJobTrigger(
@@ -434,7 +435,7 @@ class BatchOperator(BaseOperator):
434
435
  )
435
436
 
436
437
 
437
- class BatchCreateComputeEnvironmentOperator(BaseOperator):
438
+ class BatchCreateComputeEnvironmentOperator(AwsBaseOperator[BatchClientHook]):
438
439
  """
439
440
  Create an AWS Batch compute environment.
440
441
 
@@ -460,15 +461,21 @@ class BatchCreateComputeEnvironmentOperator(BaseOperator):
460
461
  Only useful when deferrable is True.
461
462
  :param max_retries: How many times to poll for the environment status.
462
463
  Only useful when deferrable is True.
463
- :param aws_conn_id: Connection ID of AWS credentials / region name. If None,
464
- credential boto3 strategy will be used.
465
- :param region_name: Region name to use in AWS Hook. Overrides the
466
- ``region_name`` in connection if provided.
464
+ :param aws_conn_id: The Airflow connection used for AWS credentials.
465
+ If this is ``None`` or empty then the default boto3 behaviour is used. If
466
+ running Airflow in a distributed manner and aws_conn_id is None or
467
+ empty, then default boto3 configuration would be used (and must be
468
+ maintained on each worker node).
469
+ :param region_name: AWS region_name. If not specified then the default boto3 behaviour is used.
470
+ :param verify: Whether or not to verify SSL certificates. See:
471
+ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
467
472
  :param deferrable: If True, the operator will wait asynchronously for the environment to be created.
468
473
  This mode requires aiobotocore module to be installed. (default: False)
469
474
  """
470
475
 
471
- template_fields: Sequence[str] = (
476
+ aws_hook_class = BatchClientHook
477
+
478
+ template_fields: Sequence[str] = aws_template_fields(
472
479
  "compute_environment_name",
473
480
  "compute_resources",
474
481
  "service_role",
@@ -486,8 +493,6 @@ class BatchCreateComputeEnvironmentOperator(BaseOperator):
486
493
  tags: dict | None = None,
487
494
  poll_interval: int = 30,
488
495
  max_retries: int | None = None,
489
- aws_conn_id: str | None = None,
490
- region_name: str | None = None,
491
496
  deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
492
497
  **kwargs,
493
498
  ):
@@ -502,18 +507,8 @@ class BatchCreateComputeEnvironmentOperator(BaseOperator):
502
507
  self.tags = tags or {}
503
508
  self.poll_interval = poll_interval
504
509
  self.max_retries = max_retries or 120
505
- self.aws_conn_id = aws_conn_id
506
- self.region_name = region_name
507
510
  self.deferrable = deferrable
508
511
 
509
- @cached_property
510
- def hook(self):
511
- """Create and return a BatchClientHook."""
512
- return BatchClientHook(
513
- aws_conn_id=self.aws_conn_id,
514
- region_name=self.region_name,
515
- )
516
-
517
512
  def execute(self, context: Context):
518
513
  """Create an AWS batch compute environment."""
519
514
  kwargs: dict[str, Any] = {
@@ -927,7 +927,7 @@ class BedrockBatchInferenceOperator(AwsBaseOperator[BedrockHook]):
927
927
  invoke_kwargs: dict[str, Any] | None = None,
928
928
  wait_for_completion: bool = True,
929
929
  waiter_delay: int = 60,
930
- waiter_max_attempts: int = 10,
930
+ waiter_max_attempts: int = 20,
931
931
  deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
932
932
  **kwargs,
933
933
  ):
@@ -567,8 +567,7 @@ class EcsRunTaskOperator(EcsBaseOperator):
567
567
 
568
568
  if self.do_xcom_push and self.task_log_fetcher:
569
569
  return self.task_log_fetcher.get_last_log_message()
570
- else:
571
- return None
570
+ return None
572
571
 
573
572
  def execute_complete(self, context: Context, event: dict[str, Any] | None = None) -> str | None:
574
573
  validated_event = validate_execute_complete_event(event)
@@ -729,11 +728,10 @@ class EcsRunTaskOperator(EcsBaseOperator):
729
728
  f"This task is not in success state - last {self.number_logs_exception} "
730
729
  f"logs from Cloudwatch:\n{last_logs}"
731
730
  )
732
- else:
733
- raise AirflowException(f"This task is not in success state {task}")
734
- elif container.get("lastStatus") == "PENDING":
731
+ raise AirflowException(f"This task is not in success state {task}")
732
+ if container.get("lastStatus") == "PENDING":
735
733
  raise AirflowException(f"This task is still pending {task}")
736
- elif "error" in container.get("reason", "").lower():
734
+ if "error" in container.get("reason", "").lower():
737
735
  raise AirflowException(
738
736
  f"This containers encounter an error during launching: "
739
737
  f"{container.get('reason', '').lower()}"