Skip to content

Commit 4436bba

Browse files
committed
docs and sample for AWSSecretsManagerSettingsSource
1 parent 94e8554 commit 4436bba

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

docs/index.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,61 @@ Last, run your application inside a Docker container and supply your newly creat
17751775
docker service create --name pydantic-with-secrets --secret my_secret_data pydantic-app:latest
17761776
```
17771777

1778+
## AWS Secrets Manager
1779+
1780+
You must set one parameter:
1781+
1782+
- `secret_id`: The AWS secret id
1783+
1784+
You must have the same naming convention in the key value in secret as in the field name. For example, if the key in secret is named `SqlServerPassword`, the field name must be the same. You can use an alias too.
1785+
1786+
In Key Vault, nested models are supported with the `--` separator. For example, `SqlServer--Password`.
1787+
1788+
Key Vault arrays (e.g. `MySecret--0`, `MySecret--1`) are not supported.
1789+
1790+
```py
1791+
import os
1792+
1793+
from pydantic import BaseModel
1794+
1795+
from pydantic_settings import (
1796+
AWSSecretsManagerSettingsSource,
1797+
BaseSettings,
1798+
PydanticBaseSettingsSource,
1799+
)
1800+
1801+
1802+
class SubModel(BaseModel):
1803+
a: str
1804+
1805+
1806+
class AWSSecretsManagerSettings(BaseSettings):
1807+
foo: str
1808+
bar: int
1809+
sub: SubModel
1810+
1811+
@classmethod
1812+
def settings_customise_sources(
1813+
cls,
1814+
settings_cls: type[BaseSettings],
1815+
init_settings: PydanticBaseSettingsSource,
1816+
env_settings: PydanticBaseSettingsSource,
1817+
dotenv_settings: PydanticBaseSettingsSource,
1818+
file_secret_settings: PydanticBaseSettingsSource,
1819+
) -> tuple[PydanticBaseSettingsSource, ...]:
1820+
aws_secrets_manager_settings = AWSSecretsManagerSettingsSource(
1821+
settings_cls,
1822+
os.environ['AWS_SECRETS_MANAGER_SECRET_ID'],
1823+
)
1824+
return (
1825+
init_settings,
1826+
env_settings,
1827+
dotenv_settings,
1828+
file_secret_settings,
1829+
aws_secrets_manager_settings,
1830+
)
1831+
```
1832+
17781833
## Azure Key Vault
17791834

17801835
You must set two parameters:

0 commit comments

Comments
 (0)