Skip to content

Node.js TypeScript project demonstrating a Prisma integration with PostgreSQL

Notifications You must be signed in to change notification settings

ChristianRich/prisma-postgresql-typescript-setup

Repository files navigation

Prisma with PostgreSQL, TypeScript, Serverless and Parameter Store

This project is the outcome of following the Prisma Getting Started guide.

In addition, Serverless features have been added for seamless AWS deployments.

Prerequisites

  • AWS account
  • A running PostgreSQL database e.g Amazon Aurora RDS PostgreSQL
  • A valid database connection string

To run this project:

npm i

Modify .env

See .env.sample

This step is only required if you plan on running the app on localhost.

DATABASE_URL=postgresql://user:password@host:port/db-name

Add secret database string to AWS Parameter Store

When Serverless builds the deployment package, it fetches the database connection string from Parameter Store.

Modify the provider block in serverless.yaml:

environment:
    DATABASE_URL: ${ssm:/dev/my-app/my-connection}

Then go to Parameter Store and create the following secret e.g

/dev/my-app/my-connection = postgresql://user:password@host:port/db-name

Create Prisma client

This generates a custom built Prisma client based on your schema

npx prisma generate

Run sample migration

This will create the desired tables for you

npx prisma migrate dev

Seed the DB

Next, create two users Alice and Bob

npm run db:seed

Deploy application to AWS Lambda

sls deploy

Test the service

Copy the API Gateway URL from the Serverless output in the console to Postman.

GET https://xxxxxxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev/users/alice

Should return Alice:

{
    "id": 1,
    "email": "[email protected]",
    "name": "Alice"
}

About

Node.js TypeScript project demonstrating a Prisma integration with PostgreSQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published