@classmethod<EOL><INDENT>def from_env(cls, prefix, kms_decrypt=False, aws_profile=None):<DEDENT>
if len(prefix) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(set(prefix).difference(set(string.ascii_uppercase + "<STR_LIT:_>"))):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not prefix.endswith("<STR_LIT:_>"):<EOL><INDENT>prefix = prefix + "<STR_LIT:_>"<EOL><DEDENT>data = dict(<EOL>host=os.getenv(prefix + "<STR_LIT>"),<EOL>port=os.getenv(prefix + "<STR_LIT>"),<EOL>database=os.getenv(prefix + "<STR_LIT>"),<EOL>username=os.getenv(prefix + "<STR_LIT>"),<EOL>password=os.getenv(prefix + "<STR_LIT>"),<EOL>)<EOL>if kms_decrypt is True:  <EOL><INDENT>import boto3<EOL>from base64 import b64decode<EOL>if aws_profile is not None:<EOL><INDENT>kms = boto3.client("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>ses = boto3.Session(profile_name=aws_profile)<EOL>kms = ses.client("<STR_LIT>")<EOL><DEDENT>def decrypt(kms, text):<EOL><INDENT>return kms.decrypt(<EOL>CiphertextBlob=b64decode(text.encode("<STR_LIT:utf-8>"))<EOL>)["<STR_LIT>"].decode("<STR_LIT:utf-8>")<EOL><DEDENT>data = {<EOL>key: value if value is None else decrypt(kms, str(value))<EOL>for key, value in data.items()<EOL>}<EOL><DEDENT>return cls(**data)<EOL>
Load database credential from env variable.

- host: ENV.{PREFIX}_HOST
- port: ENV.{PREFIX}_PORT
- database: ENV.{PREFIX}_DATABASE
- username: ENV.{PREFIX}_USERNAME
- password: ENV.{PREFIX}_PASSWORD

:param prefix: str
:param kms_decrypt: bool
:param aws_profile: str