Knowledge Center Monthly Newsletter - June 2025
Stay up to date with the latest from the Knowledge Center. See all new Knowledge Center articles published in the last month, and re:Post's top contributors.
Wie verwende ich Spark in meinem Amazon EMR-Cluster, um eine Verbindung zu einem Amazon Redshift-Cluster herzustellen?
Ich möchte Spark in meinem Amazon EMR-Cluster verwenden, um eine Verbindung zu einem Amazon Redshift-Cluster herzustellen.
Behebung
Hinweis: Bevor du beginnst, stelle sicher, dass du den Amazon Redshift-Cluster konfigurierst. Verwende dann Spark, um einen Amazon EMR-Cluster 6.4 oder höher zu starten.
Gehe wie folgt vor, um Spark im Amazon EMR-Cluster für die Herstellung einer Verbindung zu einem Amazon Redshift-Cluster zu verwenden:
Teste die Konnektivität zwischen dem Amazon EMR-Cluster und dem Amazon Redshift-Cluster
-
Vergewissere dich, dass die Regeln für eingehenden Datenverkehr der Sicherheitsgruppe des Amazon Redshift-Clusters die Primär-, Core- und Aufgaben-Sicherheitsgruppen von Amazon EMR auf dem TCP-Port 5439 zulassen.
Hinweis: Wenn deine Cluster in zwei verschiedenen Amazon Virtual Private Clouds (Amazon VPC) bereitgestellt werden, konfiguriere Amazon VPC-Peering. -
Verwende SSH, um eine Verbindung zum Amazon EMR-Primärknoten herzustellen. Führe dann den folgenden telnet-Befehl aus:
telnet example-redshift-endpoint 5439
Hinweis: Ersetze example-redshift-endpoint durch deinen Amazon Redshift-Cluster-Endpunkt.
Beispielausgabe:
telnet redshift-cluster-1.XXXXX.us-east-1.redshift.amazonaws.com 5439 Trying 172.31.48.21... Connected to redshift-cluster-1.XXXXX.us-east-1.redshift.amazonaws.com. Escape character is '^]'.
Verwendung von Spark in Amazon EMR 6.4.0 oder höher, um eine Verbindung zum Amazon Redshift-Cluster herzustellen
Führe die folgenden Schritte aus:
- Verwende SSH, um eine Verbindung zum Amazon EMR-Primärknoten herzustellen.
- Verwende den JDBC-Konnektor, um eine Amazon Redshift-Tabelle zu lesen. Weitere Informationen findest du unter Konnektor-Parameter.
PySpark-Beispiel:[hadoop@ip-10-10-10-10 ~]$ pyspark >>> from pyspark.sql import SQLContext >>> sql_context = SQLContext(sc) >>> url = "jdbc:redshift://<redshift-endpoint>:5439/dev?user=<user>&password=<password>" >>> df = sql_context.read \ .format("io.github.spark_redshift_community.spark.redshift") \ .option("url", url) \ .option("query", "select * from table") \ .option("tempdir", "<tempdir>") \ .option("aws_iam_role", "<iam_role>") \ .load() >>> df.show(2) Spark-shell example: [hadoop@ip-192-168-1-113 ~]$ spark-shell scala> import org.apache.spark.sql._ scala> val sql_context = new SQLContext(sc) scala> val url = "jdbc:redshift://<redshift-endpoint>:5439/dev?user=<user>&password=<password>" scala> val df = sql_context.read.format("io.github.spark_redshift_community.spark.redshift").option("url", url).option("query", "select * from table").option("tempdir", "<tempdir>").option("aws_iam_role", "<iam_role>").load() scala> df.show(2)
Hinweis: Weitere sichere Optionen zur Verwaltung von Benutzeranmeldeinformationen, die in der JDBC-Verbindung verwendet werden, findest du unter Identitäts- und Zugriffsmanagement in Amazon Redshift.
Ähnliche Informationen
Verwendung der Amazon Redshift-Integration für Apache Spark mit Amazon EMR

Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 2 Jahren