-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from digorgonzola/db_aws_secret
Db aws secret
- Loading branch information
Showing
8 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import boto3 | ||
from botocore.exceptions import ClientError | ||
|
||
|
||
def get_secret(secret_name, region_name): | ||
|
||
secret_name = secret_name | ||
region_name = region_name | ||
|
||
# Create a Secrets Manager client | ||
session = boto3.session.Session() | ||
client = session.client( | ||
service_name='secretsmanager', | ||
region_name=region_name | ||
) | ||
|
||
try: | ||
get_secret_value_response = client.get_secret_value( | ||
SecretId=secret_name | ||
) | ||
except ClientError as e: | ||
# For a list of exceptions thrown, see | ||
# https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html | ||
raise e | ||
|
||
secret = get_secret_value_response['SecretString'] | ||
|
||
return secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
version: "3" | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
image: api | ||
ports: | ||
- "8000:8000" | ||
volumes: | ||
- ./app:/app | ||
- ${HOME}/.aws:/home/user/.aws | ||
command: > | ||
sh -c "python manage.py wait_for_db && | ||
python manage.py migrate && | ||
python manage.py runserver 0.0.0.0:8000" | ||
environment: | ||
- AWS_PROFILE=YOUR_AWS_PROFILE | ||
- DB_HOST=db | ||
- DB_NAME=api | ||
- DB_USER=postgres | ||
- DB_SECRET_NAME=/your/rds/secret | ||
- DB_SECRET_REGION=aa-something-1 | ||
- DEBUG=1 | ||
- S3_STORAGE_BACKEND=0 | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
|
||
db: | ||
image: postgres:12-alpine | ||
environment: | ||
- POSTGRES_DB=api | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=PUT_THE_SECRET_PASSWORD_VALUE_HERE | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters