1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWS GlueでRAC構成のOracle DBに接続する

Last updated at Posted at 2020-12-13

Glueでは以下のようなロードバランスをONにした接続設定を作成できません。

jdbc:oracle:thin:@(DESCRIPTION = (LOAD_BALANCE=ON)(FAILOVER=ON)(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.yyy)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = my_ora_service)))

公式のドキュメントにあるOracleDBに接続するJDBC URLの書式は以下の通りです。
https://docs.aws.amazon.com/ja_jp/glue/latest/dg/connection-defining.html

employee サービス名を使用して Amazon RDS for Oracle データストアに接続する。
jdbc:oracle:thin://@xxx-cluster.cluster-xxx.us-east-1.rds.amazonaws.com:1521/employee

Amazon RDS for Oracle の構文は次のパターンに従います。これらのパターンでは、host, port, service_name, および SID 独自の情報を使用することもできます。
・jdbc:oracle:thin://@host:port/service_name
・jdbc:oracle:thin://@host:port:SID

そのためジョブ内でspark dataframeを用いてJDBC接続し、データ取得を行う必要があります。

sample.py
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

sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)

url = "jdbc:oracle:thin:@(DESCRIPTION = (LOAD_BALANCE=ON)(FAILOVER=ON)(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.yyy)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = my_ora_service)))"

dataframe = spark \
  .read \
  .format("jdbc") \
  .option("driver", "oracle.jdbc.driver.OracleDriver") \
  .option("url", url) \
  .option("user", "xxx") \
  .option("password", "xxx") \
  .option("dbtable", "DUAL") \
  .load()
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?