Skip to content

Commit

Permalink
Merge pull request #107 from aws/add_retries_for_get_cluster_creds
Browse files Browse the repository at this point in the history
Add retries for get cluster credentials API call and remove unused variables
  • Loading branch information
sathiish-kumar authored Sep 22, 2023
2 parents 85793da + 48d0c56 commit 120eb0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
14 changes: 6 additions & 8 deletions common/aws_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import logging
import boto3
from botocore.config import Config
from botocore.exceptions import ClientError
import asyncio
import functools
Expand Down Expand Up @@ -34,22 +35,19 @@ def redshift_describe_logging_status(source_cluster_endpoint):


def redshift_get_cluster_credentials(
region,
user,
database_name,
cluster_id,
duration=900,
auto_create=False,
additional_client_args={},
region, user, database_name, cluster_id, duration=900, auto_create=False, additional_args={}
):
rs_client = boto3.client("redshift", region, **additional_client_args)
# see https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html#standard-retry-mode
config = Config(retries={"max_attempts": 10, "mode": "standard"})
rs_client = boto3.client("redshift", region, config=config)
try:
response = rs_client.get_cluster_credentials(
DbUser=user,
DbName=database_name,
ClusterIdentifier=cluster_id,
DurationSeconds=duration,
AutoCreate=auto_create,
**additional_args,
)
except Exception as e:
if e == rs_client.exceptions.ClusterNotFoundFault:
Expand Down
7 changes: 2 additions & 5 deletions core/replay/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ def correlate_transactions_with_connections(self, replay_id):
total_connections,
)

def get_connection_credentials(
self, username, database=None, max_attempts=10, skip_cache=False
):
def get_connection_credentials(self, username, database=None, skip_cache=False):
credentials_timeout_sec = 3600
retry_delay_sec = 10

# how long to cache credentials per user
cache_timeout_sec = 1800
Expand Down Expand Up @@ -177,7 +174,7 @@ def get_connection_credentials(
cluster_id=cluster_id,
duration=credentials_timeout_sec,
auto_create=False,
additional_client_args=additional_args,
additional_args=additional_args,
)

if response is None:
Expand Down

0 comments on commit 120eb0f

Please sign in to comment.