Connect to Greenplum by AWS GLue


Good day!

Is there any way to connect to Greenplum db using AWS glue. I need to perform DML operations as well as DDL in Greenplum.

I tried to use psycopg2 library, because it worked fine in local enviriment, however in glue python shell it does not work.

I guess the only way is to use jdbc connection, however I can't find any documentation in case of Greenplum.

Do You have any ideas how to perform it?

asked 9 months ago288 views
1 Answer

Hello Dimitriy,

I don't think AWS Glue provides native support for connecting to Greenplum databases. However, you can use a JDBC connection to connect to Greenplum from AWS Glue.

Here's how I would approach it:

  1. Set Up a JDBC Connection:

    • Go to the AWS Glue Console.
    • Create or edit a Glue connection. In the connection settings, select "JDBC" as the connection type.
    • Provide the necessary connection details for your Greenplum database, including the JDBC URL, username, and password.
  2. Use PySpark with JDBC:

    • In your AWS Glue Python script, you can use PySpark to interact with the Greenplum database using the JDBC connection you set up.
    • Use the method to read data from Greenplum into a DataFrame and spark.write.jdbc to write data back.

Here's an example of how you can read data from Greenplum using PySpark in an AWS Glue Python script:

from pyspark.context import SparkContext
from pyspark.sql import SparkSession

# Initialize SparkContext and SparkSession
sc = SparkContext()
spark = SparkSession(sc)

# JDBC connection properties
jdbc_url = "jdbc:postgresql://your-greenplum-hostname:5432/your-database"
properties = {
    "user": "your-username",
    "password": "your-password",
    "driver": "org.postgresql.Driver"

# Read data from Greenplum into a DataFrame
df =, table="your-table-name", properties=properties)

# Perform DML operations or DDL as needed
# Example: or df.write.jdbc(...) for writing data

Make sure to replace your-greenplum-hostname, your-database, your-username, your-password, and your-table-name with your actual Greenplum database and table details.

Also, please note that AWS Glue is a managed ETL service, and it's primarily designed for data transformation and preparation tasks. While you can use PySpark to perform various data operations, including DML, it's not a replacement for a full-fledged database management tool. For extensive DDL operations, you may still need to use Greenplum-specific tools or interfaces.

Please give a thumbs up if it helps

profile picture
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions