def get_secret()

in lambda/lambda-pg-generator/postgresql.py [0:0]


def get_secret():
    
    secret_name = "c360view-secret-placeholder"
    region_name = "us-west-2"

    # Create a Secrets Manager client
    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'] == 'DecryptionFailureException':
            raise e
        elif e.response['Error']['Code'] == 'InternalServiceErrorException':
            raise e
        elif e.response['Error']['Code'] == 'InvalidParameterException':
            raise e
        elif e.response['Error']['Code'] == 'InvalidRequestException':
            raise e
        elif e.response['Error']['Code'] == 'ResourceNotFoundException':
            raise e
    else:
        if 'SecretString' in get_secret_value_response:
            secret = get_secret_value_response['SecretString']
            secretj=json.loads(secret)
            return secretj['password'] 
        else:
            decoded_binary_secret = base64.b64decode(get_secret_value_response['SecretBinary'])
            decoded_binary_secretj=json.loads(decoded_binary_secret)
            return decoded_binary_secretj['password']