Skip to content

Commit

Permalink
feat: load aws secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
omargawdat committed Feb 20, 2025
1 parent 6cb9ce0 commit 9c3df10
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compose/local/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -o errexit
set -o pipefail
set -o nounset

python manage.py migrate
python manage.py createsu
python manage.py loadfixtures
#python manage.py migrate
#python manage.py createsu
#python manage.py loadfixtures

exec python manage.py runserver_plus 0.0.0.0:8000
21 changes: 21 additions & 0 deletions config/helpers/env.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
import json
import os

import boto3

from config.env_settings import EnvSettings


def load_aws_secrets():
"""Load AWS Secrets into the environment variables if they exist"""
region = os.getenv("AWS_SECRETS_REGION")
secret_id = os.getenv("AWS_SECRET_ID")
if not region or not secret_id:
return

client = boto3.Session().client("secretsmanager", region_name=region)
response = client.get_secret_value(SecretId=secret_id)
secrets_dict = json.loads(response["SecretString"])
for key, value in secrets_dict.items():
os.environ[key.lower()] = str(value)


load_aws_secrets()
env = EnvSettings()
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Pillow==11.1.0
argon2-cffi==23.1.0
pydantic==2.10.6
pydantic-settings==2.7.1
boto3==1.36.24

# Redis
redis==5.2.1
Expand Down

0 comments on commit 9c3df10

Please sign in to comment.