PostgreSQL AWS RDS Outbound DNS

Situation

In an AWS RDS PostgreSQL database with a foreign server, access from PG to the foreign server broke after changing the target database (also hosted by RDS in the same VPC) from private to public. The AWS-provided DNS name should still resolve to its private IP address for servers inside the same VPC in order to make use of security groups, and avoid traffic looping out and back into the VPC.

Diagnosis

The foreign server’s DNS name used in the PG foreign server configuration (the default one defined by AWS) did not change. Other servers (EC2) in the same VPC were able to access the target database using the original DNS name successfully, resolving to the private IP address.

Reverting the target RDS database to private restored access via the foreign server.

Creating a CNAME record in Route 53 pointing at the DNS name of the target server did not resolve the issue.

Defining a foreign server pointing at the private IP address instead of using the DNS name of the target server worked, but I did not want to hard code the IP address in our configuration.

Solution

I was able to use the original AWS DNS name in the foreign server configuration after I set the custom DB parameter group variable rds.custom_dns_resolution to 1, and restarted the database instance. The “custom” DNS server is defined by the VPC’s DHCP options set, which I left at the default “AmazonProvidedDNS”.

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.PostgreSQL.CommonDBATasks.CustomDNS.html