Overview
The Payload pattern deploys a production-ready Payload CMS application to AWS Lambda with:- Serverless compute - Lambda functions on ARM64 for cost efficiency
- Managed PostgreSQL - RDS PostgreSQL (single instance by default, Aurora Serverless v2 optional)
- S3 storage - media uploads and ISR cache
- CloudFront CDN - global distribution with HTTPS
- Automatic patching - Fjall configures the project for Lambda deployment
Payload CMS 3.x is built on Next.js, so it deploys to Lambda via OpenNext.
Quick Start
1. Create a Payload Project
Start with the official Payload website template:2. Initialise Fjall
fjall/app/ directory with your infrastructure configuration.
3. Deploy
Scaffolding Payload
Payload CMS offers several official templates. Choose based on your needs:Website Template (Recommended)
Full-featured website with pages, posts, and media:- Pages collection with dynamic routing
- Posts collection with categories
- Media collection
- Header/Footer globals
- Draft/publish workflow
- SEO fields
Blank Template
Minimal starting point:- Users collection only
- No pre-built collections
- Clean slate for custom schemas
E-commerce Template
Full e-commerce setup:- Products, Categories, Orders
- Cart functionality
- Stripe integration ready
Interactive Setup
Or let Payload guide you:- Project name
- Template selection
- Database type (choose PostgreSQL for Fjall)
- Package manager
Creating Your Fjall App
Basic Setup
After scaffolding Payload, initialise Fjall:payload is the only supported pattern. The interactive picker also lists a
Next.js option, but it is experimental.
Running fjall create app interactively asks Choose your configuration
tier? with six options: Standard, Lightweight, Resilient, Enterprise,
Tinkerer, and Custom. The Custom tier opens a sub-flow for database type, backup
retention, deletion protection, KMS encryption, and Lambda memory/timeout.
This creates:
Generated Infrastructure
The defaultinfrastructure.ts:
What’s Included
The Payload pattern provisions:| Resource | Purpose |
|---|---|
| RDS PostgreSQL | Payload database (Instance by default, Aurora optional) |
| S3 Assets Bucket | Media uploads, static files |
| S3 Cache Bucket | Next.js ISR cache |
| DynamoDB Table | Tag-to-path cache for ISR |
| SQS FIFO Queue | Background revalidation |
| Lambda (Server) | SSR, API routes, admin panel |
| Lambda (Image) | next/image optimisation |
| Lambda (Revalidation) | Background ISR processing |
| CloudFront | CDN with HTTPS, routing, caching |
Automatic Configuration
When you runfjall deploy, the CLI automatically patches your Payload project:
Database Adapter
Replaces your database adapter with@fjall/payload:
S3 Storage
Adds the S3 storage plugin for media uploads:Next.js Configuration
Configures Next.js for Lambda:output: 'standalone'for OpenNext- File tracing for Sharp (ARM64 binaries)
- Exclusions for unnecessary files
Build-Time Fixes
Patches page files to prevent database calls during build:| Page | Fix Applied |
|---|---|
[slug]/page.tsx | Guard returns [] at build time |
posts/[slug]/page.tsx | Guard returns [] at build time |
page.tsx (home) | Uses force-dynamic |
posts/page.tsx | Uses force-dynamic |
search/page.tsx | Uses force-dynamic |
All patches are idempotent. Running
fjall deploy multiple times is safe.Deployment Process
First Deploy
- Installs
@fjall/payloadand@payloadcms/storage-s3 - Patches configuration files
- Generates OpenNext config
- Builds with
next build - Deploys infrastructure (~10-15 minutes)
Subsequent Deploys
Post-Deployment
Access Your Site
After deployment, you’ll see:- Frontend:
https://d1234567890.cloudfront.net - Admin Panel:
https://d1234567890.cloudfront.net/admin
Create First Admin User
- Navigate to
/admin - The first-run screen prompts you to create the initial user
- Enter an email and password
- Sign in to the admin panel
Verify Everything Works
- Admin panel loads at
/admin - Can create first admin user
- Can upload media (stored in S3)
- Can create/publish content
- Frontend displays published content
- Images load correctly
Database Migrations
Payload uses migrations to manage database schema changes.Generate Migrations
When you change your collections:src/migrations/.
Deploy Migrations
Migrations run automatically on Lambda cold start viaprodMigrations:
Environment Variables
Fjall automatically configures these Lambda environment variables:Database
OpenNext Cache
Media Storage
Custom Domain
To use a custom domain:The certificate must be in
us-east-1 for CloudFront.Pattern Parameters
The Payload pattern accepts configuration options for each component:Full Configuration Example
Root Options
| Option | Type | Default | Description |
|---|---|---|---|
type | "payload" | Required | Pattern type |
name | string | Required | Application name |
domain | string | - | Custom domain (auto-creates certificate and DNS) |
environment | object | - | Additional environment variables for server Lambda |
Database Options
| Option | Type | Default | Description |
|---|---|---|---|
type | "Instance" | "Aurora" | "Instance" | Database engine variant |
databaseName | string | App name | Name of the database |
backupRetention | number | 7 | Days to retain automated backups |
deletionProtection | boolean | true | Prevent accidental deletion |
databaseInsights | object | - | Database Insights configuration |
databaseInsights.retentionPeriod | number | 7 | Days to retain database insights data |
See the DatabaseFactory documentation for the full list of available database parameters.
CDN Options
| Option | Type | Default | Description |
|---|---|---|---|
domainNames | string[] | - | Custom domain names |
certificateArn | string | - | ACM certificate ARN (must be in us-east-1) |
Compute Options
| Option | Type | Default | Description |
|---|---|---|---|
server.memorySize | number | 1536 | Server Lambda memory in MB |
server.timeout | number | 30 | Server Lambda timeout in seconds |
server.ephemeralStorageSize | number | 512 | Ephemeral storage in MB |
imageOptimisation.memorySize | number | 1536 | Image Lambda memory in MB |
revalidation.memorySize | number | 768 | Revalidation Lambda memory in MB |
Messaging Options
| Option | Type | Default | Description |
|---|---|---|---|
messaging.revalidationQueue.visibilityTimeout | number | 30 | SQS visibility timeout in seconds |
messaging.revalidationQueue.messageRetentionPeriod | number | 345600 | Message retention in seconds |
Breaking Out Components
Need more control? You can break out of the pattern and use individual factories.Why Break Out?
- Add additional resources (Redis, queues, etc.)
- Customise networking (VPC peering, private subnets)
- Share resources between multiple apps
- Fine-grained IAM permissions
From Pattern to Factories
The Payload pattern can be approximated with this factory composition:This example demonstrates factory composition concepts. The actual Payload pattern includes additional configuration like environment variables, IAM policies, and CDN behaviours that are automatically configured for optimal OpenNext deployment.
Adding Extra Resources
Once broken out, easily add more resources:Sharing Resources Between Apps
Create shared infrastructure:Troubleshooting
Build Fails: “Error occurred prerendering page”
Cause: Page tries to access database at build time. Fix: The Fjall CLI handles this automatically. Update to the latest version:403 on Admin Panel Actions
Cause: CSRF configuration issue. Fix: Setcsrf: [] explicitly in payload.config.ts:
Media Uploads Disappear
Cause: Using local filesystem instead of S3. Fix: Fjall automatically configures S3 storage. If you have customisedplugins/index.ts, keep the S3 plugin in the list.
”relation does not exist”
Cause: Migrations not generated orprodMigrations not configured.
Fix:
Costs
Estimated monthly costs for a low-traffic site:| Resource | Cost |
|---|---|
| RDS PostgreSQL | ~$12-25 (db.t4g.micro, always on) |
| Lambda | ~$0-5 (pay per request) |
| S3 | ~$0.50-2 |
| CloudFront | ~$1-5 |
| Total | ~$15-40/month |
Next Steps
Add Resources
Extend your app with additional AWS services
Compute Factory
Learn about Lambda and ECS options
Storage Factory
Configure databases and S3 buckets
CI/CD
Automate deployments with Buildkite
Related Documentation
Fjall:- Deploy Application - General deployment guide
- Compute Factory - Lambda and ECS configuration
- Storage Factory - Database and S3 options
- Network Factory - VPC and networking
- Payload CMS Docs - Official Payload documentation
- OpenNext - Next.js to AWS Lambda
- Aurora Serverless v2 - AWS Aurora documentation