Skip to content

Commit 0d23345

Browse files
committed
docs: refine supabase to AWS
1 parent 08f1eef commit 0d23345

File tree

1 file changed

+115
-72
lines changed

1 file changed

+115
-72
lines changed

content/blog/how-to-migrate-from-supabase-to-aws.md

Lines changed: 115 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,59 +19,71 @@ But as your product matures, new requirements appear that go beyond what Supabas
1919
- **Enterprise-grade compliance and security** – meeting SOC, ISO, HIPAA, or FedRAMP standards.
2020
- **Granular IAM and networking** – unifying database access, APIs, and infrastructure under a single identity and policy system.
2121

22-
That’s where [AWS](https://aws.amazon.com/) comes in. It offers a **best-of-breed ecosystem** — each component is purpose-built, scales independently, and integrates deeply with the rest of your stack.
23-
This guide walks you through how to migrate each Supabase component to its AWS counterpart — practically and step by step.
22+
That's where hyperscalers like [AWS](https://aws.amazon.com/), [GCP](https://cloud.google.com/), and [Azure](https://azure.microsoft.com/) come in. They offer a **best-of-breed ecosystem** — each component is purpose-built, scales independently.
2423

25-
---
24+
**This guide focuses on AWS**, but the migration principles and architecture patterns apply equally to other cloud providers.
25+
26+
We'll walk you through how to migrate each Supabase component to its AWS counterpart.
2627

27-
## The Migration Process
28+
---
2829

29-
Supabase’s integrated platform maps cleanly to AWS’s modular architecture:
30+
## Debundle Supabase
3031

31-
| Supabase Component | AWS Equivalent | Notes |
32-
| -------------------- | ---------------------------------------------- | --------------------------------------------------------- |
33-
| **Database** | Amazon RDS / Aurora | Managed PostgreSQL with Multi-AZ, PITR, and replicas |
34-
| **Auth** | Amazon Cognito / BetterAuth / Auth0 | Centralized user management, SSO, and MFA |
35-
| **Storage** | Amazon S3 | Object storage with IAM-based access and CloudFront CDN |
36-
| **Functions** | AWS Lambda + API Gateway | Event-driven compute for backend logic |
37-
| **Realtime** | AppSync / EventBridge / API Gateway WebSockets | Live updates, subscriptions, or event streams |
38-
| **Networking & IAM** | VPC + IAM roles/policies | Fine-grained control, security, and compliance boundaries |
32+
| Supabase Component | Equivalent | Notes |
33+
| -------------------- | ---------------------------------------------- | ------------------------------------------------------- |
34+
| **Networking & IAM** | VPC + IAM roles/policies | AWS foundation - must be set up first |
35+
| **Auth** | Amazon Cognito / BetterAuth / Auth0 | Centralized user management, SSO, and MFA |
36+
| **Storage** | Amazon S3 | Object storage with IAM-based access and CloudFront CDN |
37+
| **Functions** | AWS Lambda + API Gateway | Event-driven compute for backend logic |
38+
| **Realtime** | AppSync / EventBridge / API Gateway WebSockets | Live updates, subscriptions, or event streams |
39+
| **Database** | Amazon RDS / Aurora | Migrate last - becomes simple PostgreSQL migration |
3940

4041
**Recommended migration order:**
4142

42-
1. **Database** – foundation of everything.
43-
1. **Auth** – migrate user identities and sessions.
44-
1. **Storage** – move file assets and update access logic.
45-
1. **Functions** – redeploy backend logic.
46-
1. **Realtime and Networking** – finalize integration and optimize architecture.
43+
This guide uses a **Services-First** approach — decouple Supabase-specific services first, then migrate the database last as a simple PostgreSQL migration.
44+
45+
1. **Networking & IAM** – set up AWS infrastructure (VPC, subnets, IAM roles).
46+
1. **Auth** – migrate to Cognito (decouples from Supabase `auth` schema).
47+
1. **Storage** – migrate to S3 (decouples from Supabase `storage` schema).
48+
1. **Functions** – redeploy to Lambda (update to use Cognito + S3).
49+
1. **Realtime** – replace with AppSync/EventBridge (removes logical replication dependency).
50+
1. **Database** – simple PostgreSQL migration of application data only (`public` schema).
51+
52+
**Why this order?** By migrating services first, the Supabase `auth` and `storage` schemas become dormant. The final database migration is just your application data — lower risk, simpler cutover, and easier to validate.
4753

4854
Always start in **staging**, validate each part, then proceed to production.
4955

50-
### 1. Database → Amazon RDS / Aurora
56+
### 1. Networking and IAM
57+
58+
> **Note:** The networking and identity concepts in this section apply to all major cloud providers (AWS, GCP, Azure). This guide focuses on AWS implementations, but the architecture patterns translate directly to VPC/IAM (GCP) or VNet/RBAC (Azure).
5159
5260
**Supabase:**
53-
Managed PostgreSQL with limited scaling and shared tenancy.
61+
Abstracted networking and simple project-level access roles.
5462

55-
**AWS replacement:**
63+
**AWS approach:**
64+
Full-control networking and IAM system for isolation and compliance.
5665

57-
- **Amazon RDS (PostgreSQL)** – Multi-AZ, automated backups, PITR, read replicas.
58-
- **Amazon Aurora (PostgreSQL-compatible)** – high-performance clustered Postgres.
59-
- **DynamoDB** – optional for NoSQL or key-value workloads.
66+
| Concept | Supabase | AWS Equivalent |
67+
| ---------------------- | ----------------- | ------------------------------ |
68+
| Top-level entity | Organization | AWS Organization |
69+
| Project | Supabase Project | AWS Account |
70+
| Environment separation | Multiple projects | Separate accounts or VPCs |
71+
| Access control | Role-based in app | IAM users, roles, and policies |
6072

6173
**Migration focus:**
6274

63-
1. Export schema and data using `pg_dump`.
64-
1. Restore into RDS or Aurora (same Postgres version).
65-
1. Recreate extensions (e.g., `pgcrypto`, `uuid-ossp`).
66-
1. Validate schema and queries in staging.
67-
1. Reconnect applications with new connection strings.
75+
1. Create VPC with public and private subnets across multiple Availability Zones.
76+
1. Set up **Security Groups** for database, Lambda, and API Gateway.
77+
1. Configure **Route Tables** and **NAT Gateways** for private subnet internet access.
78+
1. Create **IAM roles** for Lambda, RDS, S3, and Cognito.
79+
1. Set up **VPC endpoints** for AWS service access (S3, DynamoDB, etc.).
80+
1. Use **AWS Organizations** for environment isolation (dev, staging, prod).
6881

6982
**Key advantages:**
7083

71-
- Performance tuning and [CloudWatch metrics](https://aws.amazon.com/cloudwatch/).
72-
- Automated backups and [PITR](https://aws.amazon.com/rds/features/point-in-time-recovery/).
73-
- Private networking and parameter groups.
74-
- Access to AWS analytics tools ([Redshift](https://aws.amazon.com/redshift/), [Athena](https://aws.amazon.com/athena/), [Glue](https://aws.amazon.com/glue/)).
84+
- Granular control over infrastructure and networking.
85+
- Centralized access and audit through IAM.
86+
- Broad compliance coverage — [AWS Compliance](https://aws.amazon.com/compliance) vs [Supabase Security](https://supabase.com/security).
7587

7688
### 2. Auth → Amazon Cognito (or Alternatives)
7789

@@ -89,8 +101,11 @@ Managed PostgreSQL with limited scaling and shared tenancy.
89101
1. Import into Cognito User Pool.
90102
1. Configure OAuth providers (Google, GitHub, etc.).
91103
1. Update frontend SDKs and backend JWT verification.
104+
1. Update application authorization logic (see RLS section below).
92105
1. Require one-time user re-authentication after migration.
93106

107+
> **Important:** If you're using Supabase Row-Level Security (RLS) policies, they reference `auth.uid()` and won't work after migrating to Cognito. See the **Handling RLS Policies** section in the Database migration step for strategies to address this.
108+
94109
**Key advantages:**
95110

96111
- Deep IAM integration with AWS services.
@@ -153,7 +168,7 @@ Realtime engine based on Postgres logical replication and WebSockets.
153168

154169
- [AppSync](https://aws.amazon.com/appsync/) – GraphQL subscriptions for live updates.
155170
- [EventBridge](https://aws.amazon.com/eventbridge/), [SNS](https://aws.amazon.com/sns/), or [SQS](https://aws.amazon.com/sqs/) – event-driven messaging.
156-
- [API Gateway WebSockets](https://aws.amazon.com/api-gateway/features/websocket/) – persistent connections for custom protocols.
171+
- [API Gateway WebSockets](https://aws.amazon.com/api-gateway/) – persistent connections for custom protocols.
157172

158173
**Migration focus:**
159174

@@ -167,63 +182,91 @@ Realtime engine based on Postgres logical replication and WebSockets.
167182
- Scalable pub/sub and async event flows.
168183
- Integrates natively with Lambda and analytics pipelines.
169184

170-
### 6. Networking and IAM
185+
### 6. Database → Amazon RDS / Aurora
171186

172187
**Supabase:**
173-
Abstracted networking and simple project-level access roles.
188+
Managed PostgreSQL with `auth`, `storage`, and `public` schemas.
174189

175190
**AWS replacement:**
176-
Full-control networking and IAM system for isolation and compliance.
177191

178-
| Concept | Supabase | AWS Equivalent |
179-
| ---------------------- | ----------------- | ------------------------------ |
180-
| Top-level entity | Organization | AWS Organization |
181-
| Project | Supabase Project | AWS Account |
182-
| Environment separation | Multiple projects | Separate accounts or VPCs |
183-
| Access control | Role-based in app | IAM users, roles, and policies |
192+
- **Amazon RDS (PostgreSQL)** – Multi-AZ, automated backups, PITR, read replicas.
193+
- **Amazon Aurora (PostgreSQL-compatible)** – high-performance clustered Postgres.
194+
- **DynamoDB** – optional for NoSQL or key-value workloads.
184195

185-
**Migration focus:**
196+
**Why migrate last:**
186197

187-
1. Deploy RDS/Aurora in private subnets (VPC).
188-
1. Connect Lambda and EC2 via **VPC endpoints**.
189-
1. Secure traffic with **Security Groups** and **Route Tables**.
190-
1. Manage access using **IAM policies** and least-privilege principles.
191-
1. Use **AWS Organizations** for environment isolation.
198+
By this point, Auth is on Cognito, Storage is on S3, and Realtime has been replaced with AppSync/EventBridge. The Supabase `auth` and `storage` schemas are now dormant — your application no longer uses them.
192199

193-
**Key advantages:**
200+
This makes the database migration simple — just a vanilla PostgreSQL migration of your application data (the `public` schema).
194201

195-
- Granular control over infrastructure and networking.
196-
- Centralized access and audit through IAM.
197-
- Broad compliance coverage — [AWS Compliance](https://aws.amazon.com/compliance) vs [Supabase Security](https://supabase.com/security).
202+
#### Handling Row-Level Security (RLS) Policies
198203

199-
### Validate, Cut Over, and Optimize
204+
Supabase uses PostgreSQL [Row-Level Security (RLS)](https://supabase.com/docs/guides/auth/row-level-security) policies heavily. These policies reference Supabase-specific functions and the `auth.users` table:
200205

201-
**Migration focus:**
206+
```sql
207+
-- Example Supabase RLS policy
208+
CREATE POLICY "Users can only see their own data"
209+
ON public.profiles
210+
FOR SELECT
211+
USING (auth.uid() = user_id);
212+
```
202213

203-
1. Test schema, auth, and storage in staging.
204-
1. Monitor query performance (RDS/Aurora Performance Insights).
205-
1. Validate endpoints and access patterns.
206-
1. Schedule final cutover during low traffic.
207-
1. Keep Supabase in read-only mode for rollback.
214+
The problem: `auth.uid()` and `auth.jwt()` are Supabase-specific functions that won't work after migrating to Cognito.
208215

209-
**Post-migration optimization:**
216+
**Migration Strategy: Replace RLS with Application-Level Authorization**
210217

211-
1. Enable PITR and automatic backups.
212-
1. Configure **CloudWatch**, **CloudTrail**, and **GuardDuty**.
213-
1. Automate deployments with **CDK**, **Terraform**, or **CodePipeline**.
214-
1. Integrate data pipelines using **Redshift** or **Athena**.
215-
1. Review IAM roles and optimize cost and storage tiers.
218+
The recommended approach is to move authorization logic from the database to your application layer (Lambda functions):
216219

217-
---
220+
- **More flexible** – Works with any auth provider (Cognito, Auth0, BetterAuth, etc.).
221+
- **Easier to test** – Authorization logic can be unit tested independently.
222+
- **Framework-agnostic** – Not tied to PostgreSQL-specific features.
223+
- **Modern best practice** – Industry standard for cloud-native applications.
224+
- **Better debugging** – Authorization failures are easier to trace in application code.
225+
226+
Implementation example:
227+
228+
```javascript
229+
// Lambda function with application-level authorization
230+
const getUserProfile = async (event) => {
231+
// Extract Cognito user ID from JWT claims
232+
const cognitoUserId = event.requestContext.authorizer.claims.sub;
233+
234+
// Enforce authorization in application code
235+
const profile = await db.query('SELECT * FROM profiles WHERE user_id = $1', [cognitoUserId]);
236+
237+
return profile;
238+
};
239+
```
240+
241+
**Database migration focus:**
242+
243+
1. **Audit RLS policies** – Identify all RLS policies in your schema (see RLS migration strategy above).
244+
1. Set up RDS/Aurora instance in the VPC created in step 1.
245+
1. Export `public` schema and data using `pg_dump` (ignore dormant `auth` and `storage` schemas).
246+
1. Restore into RDS or Aurora (same Postgres version).
247+
1. **Implement application-level authorization** – Migrate RLS logic to Lambda functions as shown above.
248+
1. **Remove RLS policies** – Drop policies once application-level authorization is tested and deployed.
249+
1. Recreate extensions (e.g., `pgcrypto`, `uuid-ossp`) if used in application.
250+
1. Validate schema and queries in staging environment.
251+
1. Update application connection strings to point to RDS/Aurora.
252+
1. Perform final cutover during low-traffic window.
253+
254+
**Key advantages:**
255+
256+
- Performance tuning and [CloudWatch metrics](https://aws.amazon.com/cloudwatch/).
257+
- Private networking in VPC with security groups.
258+
- Access to AWS analytics tools ([Redshift](https://aws.amazon.com/redshift/), [Athena](https://aws.amazon.com/athena/), [Glue](https://aws.amazon.com/glue/)).
218259

219260
## Conclusion
220261

221-
Migrating from Supabase to AWS isn’t just a lift-and-shift — it’s a step toward scalable, enterprise-ready infrastructure.
262+
Migrating from Supabase to AWS isn't just a lift-and-shift — it's a step toward scalable, enterprise-ready infrastructure.
263+
264+
Use the **Services-First** approach to decouple components gradually:
265+
**Networking & IAM → Auth → Storage → Functions → Realtime → Database.**
222266

223-
Move one layer at a time:
224-
**Database → Auth → Storage → Functions → Realtime → Networking.**
267+
By migrating services first, the final database migration becomes a simple PostgreSQL-to-PostgreSQL operation with just your application data — lower risk, simpler cutover, and easier to validate.
225268

226269
Supabase helps you **build fast**.
227-
AWS helps you **scale safely** — with advanced database management, analytics, IAM, and compliance.
270+
AWS helps you **scale next** — with advanced database management, analytics, IAM, and compliance.
228271

229-
When done right, the migration lays a foundation your product can grow on for years to come.
272+
When done right, the migration lays a foundation your product can grow on for years to come.

0 commit comments

Comments
 (0)