Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 4 min read How-to mediumAdept

How to create an AWS S3 bucket for Postgres backups

Part 1 of a series on automating nightly Postgres backups from many Neon projects to S3 via scheduled GitHub Actions covers the AWS setup. It registers GitHub's OIDC identity provider (token.actions.githubusercontent.com, audience sts.amazonaws.com), creates a web-identity IAM role scoped to a specific repository, and creates a general-purpose S3 bucket. A bucket policy then grants that role List, Get, Put and Delete access. Bucket region matters, since distance from the databases lengthens backup jobs, and the account ID, bucket name and role name should be stored as GitHub Secrets for part 2.

Related posts

  • How to Set Up Nightly Backups to AWS S3 for Multiple Neon Projects

    Neon mediumAdept

    Nightly backups of multiple Neon Postgres databases can be automated with one GitHub Actions workflow per database. Each workflow runs on a cron schedule, installs a matching Postgres client version, and assumes an AWS IAM role via OIDC. It then pipes pg_dump through gzip, deletes .gz files in that database's S3 folder older than a configurable retention period, and uploads the new dump. Workflows differ only in name, connection-string secret and retention. GitHub-hosted runners time out after about 6 hours, so large databases may need self-hosted runners.

  • Automated PostgreSQL Backups

    Railway mediumAdept

    A deployable Node.js template automates PostgreSQL backups on Railway by running a cron job that uploads compressed dumps to an S3 bucket. Setup involves creating an S3 bucket and an IAM user with programmatic access, ideally restricted to s3:PutObject on that bucket rather than AmazonS3FullAccess. The service is then configured through environment variables for AWS credentials, bucket, region, the BACKUP_DATABASE_URL and an optional cron schedule that defaults to daily at 5 AM UTC. Restoring means extracting the tar.gz and running pg_restore against the target database URL.

  • Neon Twin: Move Dev/Test/Staging to Neon, Keep Production on RDS

    Neon mediumAdept

    A Neon Twin is a nightly-synced copy of an RDS Postgres production database kept in Neon for dev, test and staging, so teams get instant provisioning, branching and scale-to-zero without migrating production. A scheduled GitHub Actions workflow installs Postgres, runs pg_dump in custom format against RDS, then pg_restore with --clean, --if-exists, --no-owner and --no-acl into a Neon main branch, with per-engineer branches created from it. Caveats include GitHub Actions' 6-hour job limit (use self-hosted runners for large databases), IP allowlisting problems with GitHub's changing runner IPs, and SSL certificate handling. Co-locating both databases in the same AWS region speeds up the job and cuts egress costs.

  • Add files to your branches

    Neon mediumAdept

    Neon Object Storage is an S3-compatible store whose buckets belong to database branches: child branches inherit buckets and objects via the same copy-on-write model as Neon Postgres, so previews get isolated, unbilled-until-diverged copies of production files. Branch reset restores buckets along with the database, but instant restore only rolls back Postgres. Migration mostly means repointing S3 clients at the branch endpoint with path-style addressing, with limits such as no bucket notifications, lifecycle rules, ACL writes or objects over 10 GiB. Function Triggers fire Neon Functions on object creation or on a cron schedule, and inherited triggers start disabled on child branches to avoid reprocessing.

  • Recreating S3 in Postgres using PostgREST

    Neon mediumAdept

    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. A custom "*/*" domain lets a PL/pgSQL function return arbitrary media types and set Content-Type, Content-Disposition and Cache-Control headers, and generated columns compute size, MIME type and SHA-256 hash. Row-level security policies on anonymous and authenticated roles, with JWT-based user IDs, restrict access to public or owned blobs. Tables grant SELECT to anonymous users by default, so RLS setup is essential, and the pattern is meant as a teaching vehicle rather than a real S3 replacement.

The quest for software engineering knowledge.

Look:
Layout: