-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
42 lines (36 loc) · 955 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { createConnection } from "any-db";
import AWS from "aws-sdk";
import { exit } from "process";
import { readFileSync } from "fs";
require("dotenv").config();
const signer = new AWS.RDS.Signer({
hostname: process.env.DB_HOST,
username: process.env.DB_USER,
region: "us-east-1",
port: 5432,
});
signer.getAuthToken({}, (err, token) => {
if (err) {
console.error("Couldn't retrieve auth token...");
console.log(err);
exit(255);
} else {
const dbUrl = {
adapter: "postgres",
user: process.env.DB_USER,
password: token,
database: "testdb",
host: process.env.DB_HOST,
port: 5432,
ssl: {
ca: readFileSync(__dirname + "/rds-ca-2019-root.pem").toString(),
rejectUnauthorized: true,
},
};
let db = createConnection(dbUrl);
let sql = "SELECT * FROM movies";
db.query(sql).on("data", (row: any): void => {
console.log(row);
});
}
});