Skip to content

Commit

Permalink
Merge pull request #445 from aws-samples/xuhan-dev
Browse files Browse the repository at this point in the history
fix: fix credential mismatch for opensearch
  • Loading branch information
NingLu authored Nov 28, 2024
2 parents 292ee45 + fbd244c commit 8146b0d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/lambda/intention/intention.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
aos_client = LLMBotOpenSearchClient(aos_endpoint).client
awsauth = AWS4Auth(refreshable_credentials=credentials,
region=region, service="es")
except sm_client.exceptions.InvalidRequestException:
logger.info("InvalidRequestException. It might caused by getting secret value from a deleting secret")
logger.info("Fallback to authentication with IAM")
aos_client = LLMBotOpenSearchClient(aos_endpoint).client
awsauth = AWS4Auth(refreshable_credentials=credentials,
region=region, service="es")
except Exception as err:
logger.error("Error retrieving secret '%s': %s", aos_secret, str(err))
raise
Expand Down
4 changes: 4 additions & 0 deletions source/lambda/job/glue-job-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def get_aws_auth():

except sm_client.exceptions.ResourceNotFoundException:
aws_auth = AWS4Auth(refreshable_credentials=credentials, region=region, service="es")
except sm_client.exceptions.InvalidRequestException:
logger.info("InvalidRequestException. It might caused by getting secret value from a deleting secret")
logger.info("Fallback to authentication with IAM")
aws_auth = AWS4Auth(refreshable_credentials=credentials, region=region, service="es")
except Exception as e:
logger.error(f"Error retrieving secret '{aos_secret}': {str(e)}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
except sm_client.exceptions.ResourceNotFoundException:
logger.info(f"Secret '{aos_secret}' not found in Secrets Manager")
aos_client = LLMBotOpenSearchClient(aos_endpoint)
except sm_client.exceptions.InvalidRequestException:
logger.info("InvalidRequestException. It might caused by getting secret value from a deleting secret")
logger.info("Fallback to authentication with IAM")
aos_client = LLMBotOpenSearchClient(aos_endpoint)
except Exception as e:
logger.error(f"Error retrieving secret '{aos_secret}': {str(e)}")
raise
Expand Down

0 comments on commit 8146b0d

Please sign in to comment.