$ aws rds create-db-instance \
--db-instance-identifier cruddur-db-instance \
--db-instance-class db.t3.micro \
--engine postgres \
--engine-version 14.6 \
--master-username ${POSTGRES_MASTER_USERNAME} \
--master-user-password ${POSTGRES_MASTER_PASSWORD} \
--allocated-storage 20 \
--availability-zone "${AWS_DEFAULT_REGION}" \
--backup-retention-period 0 \
--port ${POSTGRES_PORT} \
--no-multi-az \
--db-name cruddur \
--storage-type gp2 \
--publicly-accessible \
--storage-encrypted \
--enable-performance-insights \
--performance-insights-retention-period 7 \
--no-deletion-protection
add a schema.sql file to cruddur ---- adding an extension
psql cruddur < db/schema.sql -h localhost -U postgres
Command to setup Connection URL:
postgresql://[username[:password]@][netloc][:port][/dbname][?param1=value1&...]
export CONNECTION_URL="postgresql://postgres:password@localhost:5432/cruddur"
gp env CONNECTION_URL="postgresql://postgres:password@localhost:5432/cruddur"
Create anew folder 'bin' in backend-url and place all the bash scripts
mkdir /workspace/aws-bootcamp-cruddur-2023/backend-flask/bin
export CONNECTION_URL="postgresql://postgres:pssword@127.0.0.1:5432/cruddur"
gp env CONNECTION_URL="postgresql://postgres:pssword@127.0.0.1:5432/cruddur"
inside db-connect file
#! /usr/bin/bash
psql $CONNECTION_URL
To make the file executable:
chmod u+x bin/db-connect
To execute the script:
./bin/db-connect
bin/db-create
#! /usr/bin/bash
NO_DB_CONNECTION_URL=$(sed 's/\/cruddur//g' <<<"$CONNECTION_URL")
createdb cruddur $NO_DB_CONNECTION_URL
bin/db-schema-load
#! /usr/bin/bash
schema_path="$(realpath .)/db/schema.sql"
echo $schema_path
NO_DB_CONNECTION_URL=$(sed 's/\/cruddur//g' <<<"$CONNECTION_URL")
psql $NO_DB_CONNECTION_URL cruddur < $schema_path
https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
CYAN='\033[1;36m'
NO_COLOR='\033[0m'
LABEL="db-schema-load"
printf "${CYAN}== ${LABEL}${NO_COLOR}\n"
bin/db-drop
#! /usr/bin/bash
NO_DB_CONNECTION_URL=$(sed 's/\/cruddur//g' <<<"$CONNECTION_URL")
psql $NO_DB_CONNECTION_URL -c "DROP database cruddur;"
- Relational database ex: cstomer databse, credit card info, username & password
- Makes sure where the database is created, check where the region is (Best practice)
- Set the password for database - a secure one (Best practise)
- 5432 - default port for Postgres
- Check for security group (Inboubd & Outbound), region, port, publically accessible
- Postgress app - check for the postgres database to test connection (DBeaver)
- Use VPC to protect the RDS instamnce from unauthorized access
- Meet compliance rewuirements for data
- use in region wher you are legally allowed to hold user data
- Use SCP to protect RDS from deletion, enforce encryption region lock etc....
- Enable CloudTrail to trigger alerts on malicioud behaviour by anu identity
- Enable Guardduty in the same region as RDS
- Dont use default autentication(use IAM authentication, Kerberos etc)
- Database user Lifecycle Management(create, delete & modify users)
- User Access Lifecycle management (create, delete & revoke access to users)
- RTestrict security groups to known IPs
- Not internet accessible
- Encryption in transit
- Rotate Master password automatically by using Secret Manager