title: Connection timed out with JDBC connection from AWS Glue to RDS
body: <p>I'm trying to connect to my PosgreSQL RDS directly from my AWS Glue script. I've tried connecting using the generated code and it works. But it doesn't work using JDBC type of connection. Here's the code:</p>
  <pre class="lang-py prettyprint-override"><code>import sys
  from awsglue.transforms import *
  from awsglue.utils import getResolvedOptions
  from pyspark.context import SparkContext
  from awsglue.context import GlueContext
  from awsglue.job import Job
  from awsglue.dynamicframe import DynamicFrame
  import pyspark.sql.functions as F
  from pyspark.sql.functions import *
  
  ## Initialize
  args = getResolvedOptions(sys.argv, ['JOB_NAME'])
  
  sc = SparkContext()
  glueContext = GlueContext(sc)
  spark = glueContext.spark_session
  job = Job(glueContext)
  job.init(args['JOB_NAME'], args)
  
  df = spark \
       .read \
       .format('jdbc') \
       .option('url', 'jdbc:postgresql://host/database_name') \
       .option('dbtable', &quot;(SELECT * FROM table WHERE name = 'abcd') AS t&quot;) \
       .option('user', 'username') \
       .option('password', 'password') \
       .load()
  
  job.commit()
  </code></pre>
  <p>Part of the errors:</p>
  <pre><code>An error occurred while calling o74.load. : java.sql.SQLException: [Amazon](500150) Error setting/closing connection: Connection timed out. at com.amazon.redshift.client.PGClient.connect ....
  </code></pre>
  <p>Extra information:</p>
  <ul>
  <li>It actually worked before, but I can't figure out what changed since then</li>
  <li>I've tested the connections by using the &quot;Test connection&quot; in AWS Glue and it works</li>
  <li>I've configured the VPC security group for the RDS to open inbound/outbound to the same security group (this is based on this guide: <a href="https://docs.aws.amazon.com/glue/latest/dg/setup-vpc-for-glue-access.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/glue/latest/dg/setup-vpc-for-glue-access.html</a>)</li>
  </ul>
  <p>Thanks in advance and let me know if you need more information.</p>