- Create an Amazon RDS PostgreSQL instance.
- Configure network access so the EC2 application can connect.
- Update the Flask app to use the RDS endpoint and verify data persistence.
- Open the RDS console and click Create database.
- For a simple demo, choose the Easy create option and select PostgreSQL (Free tier if eligible).
- Provide a DB instance identifier (example:
database-one) and the master username (example:postgres). Let RDS auto-generate the master password or set your own.

- On the Create database page, there is an optional “Set up EC2 connection” section. Enabling it and selecting your EC2 instance gives RDS permission to adjust network settings (security group/VPC) so the selected EC2 instance can reach the DB instance directly.
- This simplifies networking when your DB and EC2 instance are in different subnets or VPCs.

When RDS shows the auto-generated master password, copy it immediately and store it securely. The password is only visible once on the creation success page — refreshing will hide it and require a reset via the RDS console.
- After creation, wait until the DB instance status becomes Available.
- Open the DB details and copy the endpoint and port (PostgreSQL default port: 5432). Note the master username and password you used/received.
| Parameter | Example value / notes |
|---|---|
| Host (endpoint) | database-1.caywlfxrbtml.eu-central-1.rds.amazonaws.com |
| Port | 5432 |
| Username | postgres (or your master user) |
| Password | Auto-generated or chosen at creation — store it securely |
| Database name | postgres (default) |
| Table name | postgres_user (example used in code) |
- SSH into the EC2 instance running the application (or use the EC2 console Connect option).
- Become root if necessary and navigate to the application directory to edit the code.
- Uses psycopg2 to connect to PostgreSQL.
- Creates the
postgres_usertable if it does not exist. - Starts the Flask app listening on 0.0.0.0:5000.
Do not hardcode production credentials in source code. Use environment variables, AWS Secrets Manager, or AWS Systems Manager Parameter Store to manage secrets securely. Also ensure security groups and VPC/subnet routing restrict access to only necessary IPs and services.
- Start the Flask application (for example: python3 app.py or using your process manager).
- Open the application URL in your browser and submit user details.
- The app will insert rows into the RDS PostgreSQL table.
- The sample application provides a /getdata endpoint that queries the table and renders results.
- Visit http://<ec2_ip>:5000/getdata to confirm entries are stored.

- Created a PostgreSQL instance in Amazon RDS and captured the endpoint, port, username, and password.
- Used the optional RDS “Set up EC2 connection” helper to simplify networking when applicable.
- Updated the Flask application to connect to the RDS endpoint, ensuring the required table is created at startup.
- Verified data insertion and retrieval via the application UI and the /getdata endpoint.
- Amazon RDS Documentation
- Amazon RDS for PostgreSQL
- psycopg2 — PostgreSQL adapter for Python
- AWS Secrets Manager
- AWS Systems Manager Parameter Store