0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS GlueでConnectionにフェイルオーバーやロードバランシング機能を持たせたい

Last updated at Posted at 2025-06-12

設定画面からはできない

  • AWS Glueの「Connection(接続)」設定で、1つのコネクションに複数のサーバーIPを直接指定し、優先順位や条件(フェイルオーバーやラウンドロビン等)をGlueの設定画面で制御することはできません。

代替策

JDBCのフェイルオーバー機能を利用

接続先がJDBC対応データベース(例:MySQL, PostgreSQL, SQL Server等)の場合、JDBC接続文字列で複数のホストを記述し、ドライバー側のフェイルオーバーやロードバランシング機能を利用できます。

jdbc:mysql://server1,server2,server3/dbname?failOverReadOnly=false&autoReconnect=true

Glueジョブ側で制御

Glueで複数のConnectionを作成し、ETLジョブのスクリプト内で接続先を切り替えるロジックを記述する。
例えば、接続失敗時に別のConnectionを使うようにPython(PySpark)で制御。

  import sys
  from awsglue.context import GlueContext
  from pyspark.context import SparkContext
  from awsglue.dynamicframe import DynamicFrame
  
  sc = SparkContext()
  glueContext = GlueContext(sc)
  
+ # 接続名リスト(優先順)
+ connections = ["my_connection_primary", "my_connection_secondary"]
  
+ for conn in connections:
+     try:
+         # データソースの読み込み(例:JDBC)
+         datasource = glueContext.create_dynamic_frame.from_options(
+             connection_type="mysql",
+             connection_options={"connectionName": conn, "database": "testdb", "dbtable": "my_table"},
+             transformation_ctx="datasource"
+         )
          print(f"接続成功: {conn}")
          break  # 成功したらループ終了
      except Exception as e:
          print(f"接続失敗: {conn} - {str(e)}")
          continue
  
  # この後、datasourceを使って処理を続行

DNSラウンドロビンやロードバランサーの利用

GlueのConnectionには単一のホスト名しか指定できませんが、そのホスト名に対してDNSラウンドロビンやAWS Network Load Balancerなどを使い、裏で複数IPへの分散やフェイルオーバーを実現する

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?