简体   繁体   中英

Connection to Postgres (AWS RDS) with Google Firebase Functions still failing

I'm trying to connect to my AWS rds postgres database through my Google Firebase Functions backend. After some trial and error, I successfully managed to connect to it locally (ran firebase emulators:start --only functions and successfully queried the DB). However, I am running into a { Error: connect ECONNREFUSED 127.0.0.1:3306 when I deploy my function to the remote Google Firebase Functions server.

I have set my AWS RDS database to publicly accessible. I know that I need to allow inbound traffic from my Google Firebase server, but from what I managed to dig up, this shows that the Availability Zone I am using (us-central-1) has dozens of IP addresses associated with it. I gave up and allowed all incoming traffic (Yes I know that's bad but I am not in production just yet). However, I am still getting the same error!

I have also read this and this to no avail.

Any ideas on how to get this working, and how to connect it properly so I'm not allowing all incoming traffic?

Below is how I am connecting to my aws db in my firebase function. The function itself (where the code is stored) is us-central:

  const {Pool} = require('pg');

  private static readonly config = {
    user: 'xxxxxxxx',
    host: 'xxxxxxx.yyyyyyyyy.us-east-2.rds.amazonaws.com',
    database: 'postgres',
    password: 'xxxxxxxxxx',
    port: 5432
  };
  private static readonly pool = new Pool(RemoteDBHandler.config);

Edit: Somebody tagged my question as duplicate so I made a copy here. Looking at it now, it is odd that the connection is being attempted on localhost (127.0.0.1). I have no idea why that's happening, since I am making the connection to the aws server. Therefore, I don't think this applies to me

Looks like the issue was actually with how I was calling the functions API itself. I was accidentally sending an https request to XXXXX/widgets/widgets/route instead of XXXXX/widgets/route. Basically, I had my function name in there twice.

Another issue, which may be more relevant to later readers, is that because I was porting over a fully functional express app, I still had a method that I was calling in the index.ts that started up the express server. On Google Functions, this isn't necessary, and may have been another source of my headaches

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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