2017-12-05 25 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]이 있습니다.

하지만 "데이터베이스 연결을 설정하지 못했습니다. 연결 문자열, 사용자 이름 및 비밀번호를 확인하십시오."와 함께 apps 스크립트가 계속 실패합니다. 여기

사람이 작업 예제를 공유 주시겠습니까 내 코드

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

예, 포트 3306의 모든 Google ips 대 RDS 보안 그룹을 추가했습니다. – user9053517

답변

0

How to connect to an Amazon RDS Instance using Google Apps Script?에서 자세한 안내 확인 :

설정 후 : RDS Instanc 전자에 연결

Google 애플리케이션 스크립트를

Google 애플리케이션 스크립트를 사용할 수 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(); 
}