[英]nodejs error connecting to AWS RDS postgres database
我正在嘗試連接到我的PostgreSQL數據庫,我正在使用pg庫,我的代碼如下所示
const dbcreds = require("./dbconfig.json")
const { Pool } = require('pg')
pushToDB = async function (shiftData) {
const pool = await new Pool({
host: dbcreds.dbhost,
user: dbcreds.user,
password: dbcreds.dbpassword,
database: dbcreds.dbname,
})
await pool.connect()
await pool.query('INSERT into working (shift_id, client_id, organisational_unit, discipline, site, starts_at, ends_at, status) VALUES($1, $2, $3) returning id', ['shift id', 'client id', 'third'], function (err, result) {
done();
if (err) {
return console.error('error running query', err);
}
res.send(result);
});
}
運行代碼后,檢查AWS上的日志會向我顯示此信息,我認為這可能是由於AWS權限錯誤所致,但我不確定確切需要更改什么:
2019-06-26 09:09:46 UTC:46-247-17-105.fluidata.co.uk(50780):robert@sstreamdb:[9627]:FATAL: password authentication failed for user "robert"
2019-06-26 09:09:46 UTC:46-247-17-105.fluidata.co.uk(50780):robert@sstreamdb:[9627]:DETAIL: Role "robert" does not exist.
Connection matched pg_hba.conf line 13: "host all all 0.0.0.0/0 md5"
----------------------- END OF LOG ----------------------
RDS數據庫用戶名和密碼不是您的AWS用戶名和密碼,它們是不同的身份。
在這種情況下,錯誤消息非常清楚: FATAL: password authentication failed for user "robert"
因此,Postgres RDS用戶名或密碼不正確。 與RDS數據庫的所有者聯系,檢查正確的憑據是什么。 如果創建了RDS數據庫,請確保在Postgres級別創建一個Robert
用戶。 您可以參考此博客以獲取更多詳細信息https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/ 。
最后,當您開始使用此功能時,我們強烈建議您不要在應用程序中嵌入數據庫憑據。 我建議您改用AWS Secret Manager,然后重寫代碼以在運行時獲取密碼。 您將在此處找到示例: https : //aws.amazon.com/blogs/security/rotate-amazon-rds-database-credentials-automatically-with-aws-secrets-manager/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.