Description
RDS defaults include 3306 for MySQL, 5432 for PostgreSQL, 1521 for Oracle and 1433 for SQL Server. Network rules and database permissions determine who can connect.
Potential impact
A broad security group lets unnecessary clients attempt connections on any port it permits.
Remediation
Check the subnets and routes, restrict the security group to required clients, and use database authentication and TLS. If you need another port, choose one the engine supports and update connection strings and firewall rules together. A port change reboots an existing DB instance immediately.
Examples
The examples change the PostgreSQL port from 5432 to 5433. For deployment, configure storage and networking, replace the sample password and decide whether to retain a final snapshot.
Before
resource "aws_db_instance" "example" {
engine = "postgres"
instance_class = "db.t3.micro"
username = "foo"
password = "foobarbaz"
skip_final_snapshot = true
port = 5432
}
After
resource "aws_db_instance" "example" {
engine = "postgres"
instance_class = "db.t3.micro"
username = "foo"
password = "foobarbaz"
skip_final_snapshot = true
port = 5433
}