Connecting TypeScript backend in EC2 to PostgreSQL RDS

0

I have a TypeScript backend running in a t3.micro EC2 instance. I'm using NPM as the package manager, and TypeORM to seed the database. I have a PostgreSQL database set up in RDS that I'm trying to connect to. In my local dev environment, I didn't have any problem seeding and running the backend and having it connect to RDS. However, in the EC2, it won't finish seeding when running npm run seed which runs the script

ts-node -r tsconfig-paths/register src/seeder/seed.ts

Running npm run migration:run runs the script

yarn run typeorm migration:run

and gives this error:

$ ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:run
Error during migration run:
TypeORMError: No connection options were found in any orm configuration files.
    at new TypeORMError (/home/ec2-user/backend/src/error/TypeORMError.ts:7:9)
    at ConnectionOptionsReader.<anonymous> (/home/ec2-user/backend/src/connection/ConnectionOptionsReader.ts:46:19)
    at step (/home/ec2-user/backend/node_modules/typeorm/node_modules/tslib/tslib.js:144:27)
    at Object.next (/home/ec2-user/backend/node_modules/typeorm/node_modules/tslib/tslib.js:125:57)
    at fulfilled (/home/ec2-user/backend/node_modules/typeorm/node_modules/tslib/tslib.js:115:62)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I'm not too experienced with this, but I've tried deleting node_modules, dist, yarn install, npm install. Any answers as to what I'm missing?

1 回答
0

Hi,

Please check if the EC2 instance security group, if the inbound and outbound rules allow traffic from RDS DB instance.This document can help setup communication between your RDS and EC2 instance [1]https://aws.amazon.com/premiumsupport/knowledge-center/rds-connect-ec2-bastion-host/ [2]https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.Scenarios.html

i hear you want to connect to rds postgres from TypeORM. i have found documentation that will help you connect to Postgres from TypeOrm[3]https://stackoverflow.com/questions/56511947/how-to-connect-to-postgres-amazon-rds-from-typeorm

references [4]https://stackoverflow.com/questions/64011676/error-no-connection-options-were-found-in-any-orm-configuration-files

已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则