Connecting to Aurora Serverless V1 via typeorm

0

I'm currently connecting to an Aurora Serverless V1 postgres database using typeorm via Data API. I've been experiencing issues due to the hard limits on the quotas for Data API. Is there another way to connect to an Aurora Serverless V1 database via typeorm so that Data API does not have to be used?

질문됨 일 년 전490회 조회
1개 답변
0

You can connect to an Aurora Serverless V1 database using TypeORM without using the Data API.

configure the TypeORM connection in your project. Create an ormconfig.json file

{
  "type": "postgres",
  "host": "your_aurora_serverless_host",
  "port": 5432,
  "username": "your_username",
  "password": "your_password",
  "database": "your_database_name",
  "synchronize": true,
  "logging": false,
  "entities": [
    "src/entity/**/*.ts"
  ],
  "migrations": [
    "src/migration/**/*.ts"
  ],
  "subscribers": [
    "src/subscriber/**/*.ts"
  ],
  "cli": {
    "entitiesDir": "src/entity",
    "migrationsDir": "src/migration",
    "subscribersDir": "src/subscriber"
  }
}

Connect to the Aurora Serverless database using TypeORM in your code

import { createConnection } from 'typeorm';

async function main() {
  try {
    const connection = await createConnection();
    console.log('Connected to the Aurora Serverless database');
  } catch (error) {
    console.error('Error connecting to the Aurora Serverless database:', error);
  }
}

main();
profile picture
전문가
답변함 일 년 전
  • Thanks for the detailed answer.

    I'm using typeorm version 0.3.10, where createConnection is deprecated and the way to connect to a database is by creating a DataSource object and initialising it to create the connection. Unfortunately, typeorm timesout trying to connect to aurora serverless V1 in the way you specified.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠