aws: add example of querying secrets manager in python

This commit is contained in:
thomasabishop 2023-09-11 18:20:12 +01:00
parent 4505dcd8fd
commit 3ef147c0df

View file

@ -32,8 +32,18 @@ type SomeCredentials = {
}; };
``` ```
// TODO: Add example of deferring to local env var
## Python ## Python
// TODO: Add Python example ```py
import json
import boto3
def get_secret():
python_env = os.environ.get("PYTHON_ENV", "local")
"""In production, source creds from SecretsManager"""
if python_env == "production":
secrets_manager = boto3.client("secretsmanager")
response = secrets_manager.get_secret_value(SecretId=os.environ["SECRET_ARN"])
secret_values = json.loads(response["SecretString"])
return secret_values["GOOGLE_CREDS"]
```