diff --git a/providers/src/airflow/providers/amazon/aws/hooks/eks.py b/providers/src/airflow/providers/amazon/aws/hooks/eks.py index 4e8c0ca7ad6c3..2b31f5afb66d3 100644 --- a/providers/src/airflow/providers/amazon/aws/hooks/eks.py +++ b/providers/src/airflow/providers/amazon/aws/hooks/eks.py @@ -32,7 +32,6 @@ from botocore.signers import RequestSigner from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook -from airflow.providers.amazon.aws.hooks.sts import StsHook from airflow.utils import yaml from airflow.utils.json import AirflowJsonEncoder @@ -613,7 +612,9 @@ def generate_config_file( def fetch_access_token_for_cluster(self, eks_cluster_name: str) -> str: session = self.get_session() service_id = self.conn.meta.service_model.service_id - sts_url = f"{StsHook().conn_client_meta.endpoint_url}/?Action=GetCallerIdentity&Version=2011-06-15" + sts_url = ( + f"https://sts.{session.region_name}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15" + ) signer = RequestSigner( service_id=service_id, diff --git a/providers/tests/amazon/aws/hooks/test_eks.py b/providers/tests/amazon/aws/hooks/test_eks.py index 10a93790ac6ca..cf3638d30d37d 100644 --- a/providers/tests/amazon/aws/hooks/test_eks.py +++ b/providers/tests/amazon/aws/hooks/test_eks.py @@ -1283,13 +1283,11 @@ def test_generate_config_file(self, mock_conn, aws_conn_id, region_name, expecte } @mock.patch("airflow.providers.amazon.aws.hooks.eks.RequestSigner") - @mock.patch("airflow.providers.amazon.aws.hooks.eks.StsHook") @mock.patch("airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook.conn") @mock.patch("airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook.get_session") - def test_fetch_access_token_for_cluster(self, mock_get_session, mock_conn, mock_sts_hook, mock_signer): + def test_fetch_access_token_for_cluster(self, mock_get_session, mock_conn, mock_signer): mock_signer.return_value.generate_presigned_url.return_value = "http://example.com" mock_get_session.return_value.region_name = "us-east-1" - mock_sts_hook.return_value.conn_client_meta.endpoint_url = "https://sts.us-east-1.amazonaws.com" hook = EksHook() token = hook.fetch_access_token_for_cluster(eks_cluster_name="test-cluster") mock_signer.assert_called_once_with(