Я использую приведенный ниже код Python для извлечения деталей базы данных из менеджера паролей, но продолжаю получать ту же ошибку «Невозможно найти учетные данные». Что я делаю не так?
import boto3 # Required to interact with AWS
import psycopg2
import base64
from botocore.exceptions import ClientError
secret_name = "X"
region_name = "X"
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 ClientError as e:
if e.response['Error']['Code'] == 'ResourceNotFoundException':
print("The requested secret " + secret_name + " was not found")
elif e.response['Error']['Code'] == 'InvalidRequestException':
print("The request was invalid due to:", e)
elif e.response['Error']['Code'] == 'InvalidParameterException':
print("The request had invalid params:", e)
else:
# Decrypted secret using the associated KMS CMK
# Depending on whether the secret was a string or binary, one of these fields will be populated
if 'SecretString' in get_secret_value_response:
secret = json.loads(get_secret_value_response['SecretString'])
else:
binary_secret_data = get_secret_value_response['SecretBinary']
user = secret['username']
password = secret['password']
db_name = secret['dbname']
host = secret['host']
conn = psycopg2.connect(host='host',port='5432',database=db_name, user=user, password=password)