node.js - 连接到 AWS RDS postgres 数据库的 nodejs 错误

标签 node.js postgresql amazon-web-services amazon-rds

我正在尝试连接到我正在使用 pg 的 postgresql 数据库库,我的代码看起来像这样

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 并重写代码以在运行时获取 key 。你会在这里找到一个例子:https://aws.amazon.com/blogs/security/rotate-amazon-rds-database-credentials-automatically-with-aws-secrets-manager/

关于node.js - 连接到 AWS RDS postgres 数据库的 nodejs 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56770014/

相关文章:

MySQL 过程到 PostgreSQL 函数

sql - 在 Postgresql 中,如何按列选择前 n% 的行?

postgresql - 使用 ARRAY 输出类型从 PostgreSQL 过程生成 JOOQ

amazon-web-services - 我可以在自动扩展时使用 AWS code Deploy 提取应用程序代码吗?

javascript - TypeError : You may only yield a function, promise ,生成器...当产生 app.listen() 时

javascript - AWS CodeBuild : How to run tests that require starting Docker?

node.js - 如何从 mongoose 获取 mongodb 版本

node.js - 使用npm安装hexo报错

amazon-web-services - 如何使用 AWS VPN 从 EC2 实例 ping 到本地 Windows Server?

amazon-web-services - 在默认 Amazon S3 存储桶上设置元数据