How to create dynamic dataframe from AWS Glue catalog in local environment?

0

I I have performed some AWS Glue version 3.0 jobs testing using Docker containers as detailed here. The following code outputs two lists, one per connection, with the names of the tables in a database:

import boto3


db_name_s3 = "s3_connection_db"
db_name_mysql = "glue_catalog_mysql_connection_db"

def retrieve_tables(database_name):
    session = boto3.session.Session()
    glue_client = session.client("glue")
    response_get_tables = glue_client.get_tables(DatabaseName=database_name)
    return response_get_tables


s3_tables_list = [table_dict["Name"] for table_dict in retrieve_tables(db_name_s3)["TableList"]]
mysql_tables_list = [table_dict["Name"] for table_dict in retrieve_tables(db_name_mysql)["TableList"]]

print(f"These are the tables from {db_name_s3} db: {s3_tables_list}\n")
print(f"These are the tables from {db_name_mysql} db {mysql_tables_list}")

Now, I try to create a dynamic dataframe with the from_catalog method in this way:

import sys
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
from awsglue.dynamicframe import DynamicFrame

source_activities = glueContext.create_dynamic_frame.from_catalog(
database = db_name, 
table_name =table_name
)

When database="s3_connection_db", everything works fine, however, when I set database="glue_catalog_mysql_connection_db", I get the following error:

Py4JJavaError: An error occurred while calling o45.getDynamicFrame.
: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver

I understand the issue is related to the fact that I am trying to fetch data from a mysql table but I am not sure how to solve this. By the way, the job runs fine on the Glue console.

I would really appreciate some help, thanks!

1개 답변
1
수락된 답변

It looks like you're missing the MySQL driver, you can provide your own JAR files via the "Dependent jars path" parameter. Your code looks fine so I'd assume the error is right, missing drivers/libraries.

AWS
전문가
Raphael
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인