简体   繁体   English

连接到AWS RDS postgres数据库的nodejs错误

[英]nodejs error connecting to AWS RDS postgres database

I am trying to connect to my postgresql DB I am using the pg library, my code looks like this 我正在尝试连接到我的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);
    });
}

Checking the logs on AWS shows me this after running my code, I think this may be due to AWS permission errors but I'm not sure exactly what I need to change: 运行代码后,检查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 database username and password is not your AWS user name and password, they are different identities. RDS数据库用户名和密码不是您的AWS用户名和密码,它们是不同的身份。

In this case, the error message is pretty clear : FATAL: password authentication failed for user "robert" 在这种情况下,错误消息非常清楚: FATAL: password authentication failed for user "robert"

So either, the Postgres RDS username or password is incorrect. 因此,Postgres RDS用户名或密码不正确。 Check with the owner of the RDS database what correct credentials are. 与RDS数据库的所有者联系,检查正确的凭据是什么。 If you created the RDS database, be sure to create a Robert user at Postgres level. 如果创建了RDS数据库,请确保在Postgres级别创建一个Robert用户。 You can refer to this blog for more details https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/ . 您可以参考此博客以获取更多详细信息https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/

Finally, when you will get this working, we strongly discourage embedding database credentials in your application. 最后,当您开始使用此功能时,我们强烈建议您不要在应用程序中嵌入数据库凭据。 I would suggest you to use AWS Secret Manager instead and rewrite your code to fetch the secret at runtime. 我建议您改用AWS Secret Manager,然后重写代码以在运行时获取密码。 You will find an example here : https://aws.amazon.com/blogs/security/rotate-amazon-rds-database-credentials-automatically-with-aws-secrets-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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM