Payout Retry Processor Lambda
Retries failed Stripe payouts daily. Triggered by EventBridge Scheduler at 7 AM EST.
Prerequisites
- Node.js 20.x
- PostgreSQL database with rentals data
- Stripe account with test API key (
sk_test_...)
Setup
-
Install shared dependencies:
cd lambdas/shared npm install -
Install Lambda dependencies:
cd lambdas/payoutRetryProcessor npm install
Environment Variables
| Variable | Description |
|---|---|
DATABASE_URL |
PostgreSQL connection string |
STRIPE_SECRET_KEY |
Stripe API key (use sk_test_... for testing) |
FRONTEND_URL |
For email template links |
SES_FROM_EMAIL |
Sender email address |
SES_FROM_NAME |
Sender display name |
EMAIL_ENABLED |
Set to true to send emails |
Local Testing
Run the Lambda locally using your dev environment:
cd lambdas/payoutRetryProcessor
node test-local.js
This will:
- Query your local database for failed payouts
- Attempt Stripe transfers (use test mode!)
- Send email notifications if
EMAIL_ENABLED=true
Creating Test Data
To test the retry logic, create a rental with failed payout status:
UPDATE "Rentals"
SET "payoutStatus" = 'failed'
WHERE id = '<rental-id>'
AND status = 'completed'
AND "paymentStatus" = 'paid';
Verifying Results
After running the test:
- Check console output for success/failure counts
- Query the database:
SELECT id, "payoutStatus", "stripeTransferId", "payoutProcessedAt" FROM "Rentals" WHERE id = '<rental-id>'; - Check Stripe Dashboard for new transfers
- Check email inbox if emails are enabled
AWS Deployment
When deploying to AWS:
- Create Lambda function with Node.js 20.x runtime
- Set timeout to 60 seconds (batch processing)
- Set memory to 256 MB
- Configure EventBridge Scheduler with cron:
cron(0 12 * * ? *)(7 AM EST = 12:00 UTC) - Add environment variables listed above
- Configure DLQ for failed invocations
Architecture
EventBridge Scheduler (7 AM EST daily)
|
v
Lambda Function
|
+-- Query failed payouts from PostgreSQL
|
+-- For each failed payout:
| +-- Reset status to "pending"
| +-- Create Stripe transfer
| +-- Update rental record
| +-- Send email notification
|
v
Return summary (success/failure counts)