0

I've been using drizzle for a new project over the past few weeks, and it has provided a great developer experience. Now, it's time to bring the app to production. However, I'm currently facing an issue with the migrations.

The app is deployed in AWS ECS and connects to a PostgreSQL database in AWS RDS. I have provided the necessary IAM policies in the ECS task role to access the RDS instance. The connection is established but after that when I execute the migrate function, I'm encountering an error that I didn't experience while running locally.

Error Reference:

PostgresError: no pg_hba.conf entry for host <MY_EC2_IP>, user <MY_USER>, database <MY_DATABASE>, no encryption
    at ErrorResponse (/app/node_modules/postgres/cjs/src/connection.js:771:26)
    at handle (/app/node_modules/postgres/cjs/src/connection.js:473:6)
    at Socket.data (/app/node_modules/postgres/cjs/src/connection.js:314:9)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

I tried changing postgres client.

I had never experienced such issue when using other ORMs like Prisma and TypeORM. Is this something specific to how Drizzle executes SQL in Postgres?

  • I could fix this by adding ssl in connection string and postgres client.This is required for new version of Postgres engine in RDS. ``` const dbClient = postgres(dbConfig.url, { ssl: 'require', }); ``` and ``` DATABASE_URL="postgresql://USER:PASSWORD@HOST:5432/DATABASE?ssl=true" ``` then adding `NODE_TLS_REJECT_UNAUTHORIZED = 0` before running the migration script "drizzle:generate": "drizzle-kit generate:pg", "drizzle:migrate": "NODE_TLS_REJECT_UNAUTHORIZED=0 drizzle-kit push:pg", "drizzle:introspect": "NODE_TLS_REJECT_UNAUTHORIZED=0 drizzle-kit introspect:pg" – AAkrit Subedi Aug 03 '23 at 05:46

0 Answers0