-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates 2024-07-10 - Updated data catalogue list and addeddd new get …
…creds module
- Loading branch information
1 parent
456c6e3
commit 4549ebd
Showing
2 changed files
with
69 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import boto3 | ||
import json | ||
from loguru import logger | ||
|
||
def get_param(parameter_name: str, region_name: str = "eu-west-2") -> str: | ||
""" | ||
Retrieve a parameter from AWS Systems Manager Parameter Store. | ||
""" | ||
ssm = boto3.client('ssm', region_name=region_name) | ||
try: | ||
response = ssm.get_parameter(Name=parameter_name, WithDecryption=True) | ||
return response['Parameter']['Value'] | ||
except Exception as e: | ||
logger.error(f"Unable to retrieve parameter: {str(e)}") | ||
raise e | ||
|
||
def get_secret(secret_name: str, region_name: str = "eu-west-2") -> json: | ||
""" | ||
Create an AWS Secrets Manager client. | ||
Returns a JSON with env vars. | ||
""" | ||
session = boto3.session.Session() | ||
client = session.client(service_name='secretsmanager', | ||
region_name=region_name) | ||
|
||
try: | ||
get_secret_value_response = client.get_secret_value(SecretId=secret_name) | ||
except Exception as e: | ||
logger.error(f"Unable to retrieve secret: {str(e)}") | ||
raise e | ||
else: | ||
secret = get_secret_value_response['SecretString'] | ||
return json.loads(secret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters