fromtypingimportAnnotatedfrompydantic_settings_awsimportAWSBaseSettings,AWSSettingsConfigDict,SSM,SecretsclassParameterStoreSettings(AWSBaseSettings):model_config=AWSSettingsConfigDict(secrets_name="my/secret")username:Annotated[str,Secrets()]password:Annotated[str,Secrets()]mongodb_host:Annotated[str,SSM(name="/mysystem/mongodb/host")]mongodb_db_name:Annotated[str,SSM()]# will look for a parameter named mongodb_db_nameenvironment:str# not related to aws. If you have an environment named ENVIRONMENT, it will work as if you were using BaseSettings
fromtypingimportAnnotatedfrompydantic_settings_awsimportAWSBaseSettings,AWSSettingsConfigDictclassParameterStoreSettings(AWSBaseSettings):model_config=AWSSettingsConfigDict(secrets_name="my/secret")username:Annotated[str,{"service":"secrets"}]password:Annotated[str,{"service":"secrets"}]mongodb_host:Annotated[str,{"service":"ssm","ssm":"/mysystem/mongodb/host"}]mongodb_db_name:Annotated[str,{"service":"ssm"}]# will look for a parameter named mongodb_db_nameenvironment:str# not related to aws. If you have an environment named ENVIRONMENT, it will work as if you were using BaseSettings
In this case, pydantic-settings-aws will leave to boto3 to try to identify how he can connect to AWS.
Structured exceptions
pydantic-settings-aws wraps errors into its own exception hierarchy so you can catch them precisely:
SecretNotFoundError — the secret does not exist in Secrets Manager
SecretContentError — the secret exists but its content is empty or cannot be decoded
SecretDecodeError — the secret content is not valid JSON
ParameterNotFoundError — the parameter does not exist in Parameter Store
AWSClientError — a boto3 session or client could not be created
AWSSettingsConfigError — the settings configuration is invalid or missing required fields
All of these inherit from PydanticSettingsAWSError, so you can catch them at any level.
Unrecognised boto3 / botocore errors are re-raised as-is.