Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions airflow/providers/amazon/aws/hooks/redshift_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ def get_iam_token(self, conn: Connection) -> tuple[str, str, int]:
serverless_token_duration_seconds = conn.extra_dejson.get(
"serverless_token_duration_seconds", 3600
)
redshift_client = AwsBaseHook(
redshift_serverless_client = AwsBaseHook(
aws_conn_id=self.aws_conn_id, client_type="redshift-serverless"
).conn
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-serverless/client/get_credentials.html#get-credentials
cluster_creds = redshift_client.get_cluster_credentials(
DbName=conn.schema,
cluster_creds = redshift_serverless_client.get_credentials(
dbName=conn.schema,
workgroupName=serverless_work_group,
durationSeconds=serverless_token_duration_seconds,
)
token = cluster_creds["dbPassword"]
login = cluster_creds["dbUser"]
else:
# Pull the custer-identifier from the beginning of the Redshift URL
# ex. my-cluster.ccdre4hpd39h.us-east-1.redshift.amazonaws.com returns my-cluster
Expand All @@ -139,8 +141,8 @@ def get_iam_token(self, conn: Connection) -> tuple[str, str, int]:
ClusterIdentifier=cluster_identifier,
AutoCreate=False,
)
token = cluster_creds["DbPassword"]
login = cluster_creds["DbUser"]
token = cluster_creds["DbPassword"]
login = cluster_creds["DbUser"]
return login, token, port

def get_uri(self) -> str:
Expand Down
10 changes: 5 additions & 5 deletions tests/providers/amazon/aws/hooks/test_redshift_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ def test_get_conn_iam_serverless_redshift(self, mock_connect, mock_aws_hook_conn
mock_db_pass = "aws_token"

# Mock AWS Connection
mock_aws_hook_conn.get_cluster_credentials.return_value = {
"DbPassword": mock_db_pass,
"DbUser": mock_db_user,
mock_aws_hook_conn.get_credentials.return_value = {
"dbPassword": mock_db_pass,
"dbUser": mock_db_user,
}

self.db_hook.get_conn()

# Check boto3 'redshift' client method `get_cluster_credentials` call args
mock_aws_hook_conn.get_cluster_credentials.assert_called_once_with(
DbName=LOGIN_SCHEMA,
mock_aws_hook_conn.get_credentials.assert_called_once_with(
dbName=LOGIN_SCHEMA,
workgroupName=mock_work_group,
durationSeconds=3600,
)
Expand Down