2017-12-05 70 views
2

Google AppsスクリプトからSSLを使用してAWS RDSのMysqlインスタンスに接続しようとしています。私は過去2日間、ここで同様の質問をしてきましたが、解決策を見つける運がありません。Google AppsスクリプトからSSLを使用してRDS Mysqlに接続する際のエラー

RDSの場合、Amazonのサーバー証明書(rds-combined-ca-bundle)のみが使用可能で、クライアントキー/証明書はないので、_serverSslCertificateパラメータで指定しました。資格情報が正しい。これは、SequelProのような他のツールから動作します。 RDSセキュリティグループには[Googleのサーバー] [1]がすべて含まれています。

しかし、「データベース接続の確立に失敗しました。接続文字列、ユーザー名、パスワードを確認してください」というエラーが表示されても、アプリケーションスクリプトは失敗し続けます。ここで

は私のコードは

var address = 'hostname:3306'; 
var user = 'xxxx'; 
var userPwd = 'yyyy'; 
var db = 'zzzz'; 
var dbUrl = 'jdbc:mysql://' + address + '/' + db ;  

var serverSslCertificate = UrlFetchApp.fetch("https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem"); 


var serverSslCert = serverSslCertificate.getContentText(); 
var conn = Jdbc.getConnection(dbUrl, 
          {user:user, 
          password: userPwd, 
          _serverSslCertificate: serverSslCert 
          }); 


var stmt = conn.createStatement(); 

で誰かが作業例を共有していただけますか?それとも問題ですか? あなたの貴重な応答をありがとう!

+0

すべてのGoogle ipsをホワイトリストに登録してもよろしいですか? – Ritz

+0

はい、私はすべてのGoogle ips to RDSセキュリティグループをポート3306に追加しました – user9053517

答えて

0

How to connect to an Amazon RDS Instance using Google Apps Script?で詳細なガイドをチェック:

セットアップ後:RDS Instanc Eに接続するために

Google Appsのスクリプトを

のGoogle Appsスクリプトを使用することができますJDBCと呼ばれるサービスを提供してい

外部データベースに接続します。次のスクリプトを使用してRDSエンドポイントに接続し、「ユーザー」という表からすべての行を取得します

function sampleFunction() { 
    // Replace the variables in this block with real values. 
    var address = '####'; //End point provided by the RDS Instance 
    var user = '####'; //Username you have supplied while configuring the database instance 
    var userPwd = '####'; //Password you have supplied while configuring the database instance 
    var db = '####'; //Database name to which you want to connect 

    var dbUrl = 'jdbc:mysql://' + address + '/' + db; //Generates the database url to which you can connect to 

    var conn = Jdbc.getConnection(dbUrl, user, userPwd); //Start the connection using getConnection method of Jdbc 

    //The following lines executes a SQL statement 
    var stmt = conn.createStatement(); 
    stmt.setMaxRows(1000); 
    var results = stmt.executeQuery('SELECT * FROM user;'); 
    var numCols = results.getMetaData().getColumnCount(); 

    //Printing each row of the result 
    while (results.next()) { 
    var rowString = ''; 
    for (var col = 0; col < numCols; col++) { 
     rowString += results.getString(col + 1) + '\t'; 
    } 
    Logger.log(rowString); 
    } 

    results.close(); 
    stmt.close(); 
} 
関連する問題