---
title: "How to Set Up Row-Level Security in Postgres Using AWS Cognito"
description: "Postgres row-level security can be driven by AWS Cognito JWTs: a Cognito User Pool issues tokens, and Neon Authorize validates them and maps claims like `sub` into Postgres session variables."
url: "https://swe.quest/articles/how-to-set-up-row-level-security-in-postgres-using-aws-cognito-7cb6bed6c9694d22"
canonical: "https://neon.com/blog/how-to-set-up-row-level-security-in-postgres-using-aws-cognito"
source: "Neon"
published: "2024-12-04"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["postgres","identity-auth","javascript","serverless"]
---

# How to Set Up Row-Level Security in Postgres Using AWS Cognito

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-12-04, 5 min read, How-to. Original: [https://neon.com/blog/how-to-set-up-row-level-security-in-postgres-using-aws-cognito](https://neon.com/blog/how-to-set-up-row-level-security-in-postgres-using-aws-cognito)

## Summary

Postgres row-level security can be driven by AWS Cognito JWTs: a Cognito User Pool issues tokens, and Neon Authorize validates them and maps claims like \`sub\` into Postgres session variables. A \`notes\` table gets an RLS policy comparing \`user\_id\` to \`current\_setting('jwt.claims.sub')\`, so each user sees only their own rows. The demo app uses Express.js, HTMX and the Neon serverless driver, with step-by-step setup for Cognito, the database schema, environment variables and policy verification. Neon has since folded this functionality into the Neon Data API.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)

## Prerequisites

- Postgres basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- JWT authentication ([easy posts on Identity & auth](https://swe.quest/tags/identity-auth.md?difficulty=easy))
- Express.js

## Keywords

Neon Authorize, AWS Cognito, Neon, row-level security, Express.js, HTMX, JWT, Neon Data API

## Related posts

- [Introducing Neon RLS: Simplifying Row-Level Security For Postgres](https://swe.quest/articles/introducing-neon-rls-simplifying-row-level-security-for-postgres-4b66d76670bb402f.md): Neon · 2024-10-30 · Medium · 6 min read · PostgreSQL, Identity & auth, Multi-tenancy, TypeScript
  Neon RLS lets Postgres row-level security policies authenticate requests with JWTs from any auth provider that exposes a JWKS URL.
- [Higher-level CRUD Abstraction for Postgres RLS](https://swe.quest/articles/higher-level-crud-abstraction-for-postgres-rls-90207e4bb081ead2.md): Neon · 2024-11-13 · Medium · 3 min read · PostgreSQL, Identity & auth, TypeScript
  Postgres Row-Level Security requires separate USING and WITH CHECK policies per operation, which gets repetitive for CRUD apps.
- [Is Postgres RLS for Everything and Everyone?](https://swe.quest/articles/is-postgres-rls-for-everything-and-everyone-1df08667813a2c82.md): Neon · 2024-11-15 · Medium · 4 min read · PostgreSQL, Identity & auth, Multi-tenancy, Security
  Postgres row-level security is a poor fit for expressing an entire app's authorization model.
- [Modelling Authorization for a Social Network with Postgres RLS and Drizzle ORM](https://swe.quest/articles/modelling-authorization-for-a-social-network-with-postgres-rls-and-drizzle-orm-6267eb437b8171e7.md): Neon · 2024-11-11 · Medium · 8 min read · PostgreSQL, Identity & auth, TypeScript, System design
  Postgres Row-Level Security can express the full authorization model for a Twitter-like social network, defined with Drizzle ORM's crudPolicy and pgPolicy helpers and the pg\_session\_jwt extension's auth.user\_id().
- [Recreating S3 in Postgres using PostgREST](https://swe.quest/articles/recreating-s3-in-postgres-using-postgrest-d07b4a06448dac82.md): Neon · 2025-05-27 · Medium · 7 min read · PostgreSQL, API design, Identity & auth, SQL
  A simple S3-like file server can be built inside Postgres by storing binary data in a BYTEA table and exposing it through PostgREST's functions-as-RPC via the Neon Data API.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
