Lambda Issues
Lambda Returns HTTP 500 (CORS Error on Frontend)
Symptoms:- Frontend shows CORS error or “Network Error”
- API Gateway returns 502 Bad Gateway
- CloudWatch shows Lambda error
1. Missing Module After esbuild Bundle
Error:EXTERNALS in scripts/deploy-api.sh. Add it:
2. ESM/CJS Interop Error
Error:packages/api/tsconfig.json has:
3. Missing Environment Variables
Error:COGNITO_USER_POOL_IDCOGNITO_CLIENT_IDDATABASE_URLS3_BUCKET_NAMEWORKER_FUNCTION_NAMEENVIRONMENT
Lambda Timeout (29s for API, 15min for Worker)
Symptoms:- Request hangs then fails
- CloudWatch shows
Task timed out after 29.00 seconds
1. Event Loop Not Draining (Prisma Connections)
Symptom: Lambda hangs for full timeout even after handler completes. Solution: Verifycontext.callbackWaitsForEmptyEventLoop = false in both Lambda handlers.
API Lambda (src/lambda.ts:29):
src/worker.ts:26):
2. Slow Bedrock Calls
Symptom: Worker Lambda times out processing large documents. Solution: Check Bedrock processing time:processingTime > 600000 (10 minutes):
-
Increase Worker timeout:
- Split large documents into chunks (application logic change required).
3. Database Query Slow
Symptom: API Lambda times out on specific endpoints. Check RDS performance:- Add database indexes
- Optimize Prisma queries (avoid N+1)
- Upgrade RDS instance type
Prisma Issues
Error: PrismaClientKnownRequestError with Empty Message
Symptoms:
- CloudWatch shows
PrismaClientKnodRequestErrorbutmessageis empty - Error details missing in logs
.code and .meta instead of .message:
packages/api/CLAUDE.md:143).
Common Prisma Error Codes
| Code | Meaning | Solution |
|---|---|---|
| P2002 | Unique constraint violation | Check for duplicate slug/email |
| P2025 | Record not found | Verify ID exists before update/delete |
| P2003 | Foreign key constraint failed | Ensure referenced record exists |
| P2024 | Connection timeout | Check RDS status, security groups |
| P1001 | Can’t reach database | Verify DATABASE_URL env var |
| P1017 | Server closed connection | RDS restarted, retry query |
Database Connection Failures
Error:DATABASE_URL not set or incorrect.
Diagnosis:
-
Get DB password from Secrets Manager:
-
Get RDS endpoint:
- Update Lambda environment variable via CloudFormation or Console.
Migration Failed via Worker Lambda
Error:-
Check migration status:
- Manually mark failed migration as rolled back or completed.
-
Re-run:
Cognito Issues
Error: NotAuthorizedException
Symptoms:
- Login fails with “Invalid credentials”
- CloudWatch shows
NotAuthorizedException
| Error Name | HTTP Status | Meaning |
|---|---|---|
NotAuthorizedException | 401 | Wrong email/password |
UserNotFoundException | 404 | User doesn’t exist |
UserNotConfirmedException | 403 | Email not verified |
CodeMismatchException | 400 | Invalid verification code |
ExpiredCodeException | 400 | Verification code expired |
LimitExceededException | 429 | Too many login attempts |
packages/api/src/common/exceptions/cognito.exception.ts for full mapping.
Solutions:
-
Wrong Credentials:
- User resets password via “Forgot Password” flow
- Admin resets via:
-
User Not Confirmed:
- Admin confirms user:
- Admin confirms user:
-
Rate Limited:
- Wait 15-30 minutes
- User attempts password reset
Error: InvalidParameterException (Token Verification)
Symptoms:
- All authenticated requests fail with 401
- CloudWatch shows
InvalidParameterException: Access Token does not contain openid scope
openid scope:
Bedrock Issues
Error: ThrottlingException
Symptoms:
- Worker Lambda logs show
ThrottlingException - Jobs fail after 3 retries
- Claude 3.5 Sonnet: 400 requests/minute, 160,000 tokens/minute
-
Request Quota Increase:
- AWS Console → Service Quotas → AWS Bedrock
- Request increase for specific model
- Add Backoff: Already implemented with exponential backoff (200ms → 5s).
-
Reduce Concurrency:
Error: ValidationException: Malformed input request
Symptoms:
- Bedrock call fails immediately
- No retry attempts
- Missing
anthropic_version: bedrock-2023-05-31 - Empty
systemormessagesarray - Invalid
max_tokens(must be 1-4096)
Circuit Breaker Open
Error:Job Processing Issues
Job Stuck in PENDING Status
Symptoms:- Job created but never processed
- Polling shows
status: PENDINGindefinitely
-
Check if Worker Lambda was invoked:
-
Verify
WORKER_FUNCTION_NAMEenv var on API Lambda:
- Missing env var: Update CloudFormation template
- IAM permission denied: Add
lambda:InvokeFunctionto API Lambda role - Worker Lambda disabled: Check Lambda console
Job Fails After Max Attempts
Symptoms:- Job status transitions PENDING → PROCESSING → PENDING → FAILED
attemptsfield equalsmaxAttempts(default 3)
- Bedrock throttling (see Bedrock section)
- Document parsing timeout (increase Worker timeout)
- Invalid job input (check
inputfield)
Deployment Issues
deploy-api.sh Fails: “Could not describe stack”
Error:-
Verify stack exists:
-
If missing, deploy infrastructure first:
-
Check AWS region:
Lambda Update Fails: Package Too Large
Error:EXTERNALS list in scripts/deploy-api.sh. Possible causes:
- Dev dependencies accidentally copied
- Large files in
node_modules(docs, tests) - Multiple versions of same package
CloudFront Serves Stale Content After Deployment
Symptoms:- Web deployment succeeds
- Frontend shows old code
-
Check if invalidation was created:
-
Manually invalidate:
- Wait 2-5 minutes for propagation.
Diagnostic Checklist
When investigating an issue:- Check CloudWatch logs for both API and Worker Lambdas
- Verify all environment variables are set correctly
- Confirm RDS is running and accessible
- Check Cognito User Pool and Client configuration
- Review recent deployments (code changes, infrastructure updates)
- Check AWS Health Dashboard for service issues
- Verify IAM permissions for Lambda execution roles
- Check S3 bucket permissions and CORS configuration
Getting Help
If issues persist:-
Gather diagnostics:
-
Document:
- Steps to reproduce
- Error messages from CloudWatch
- Recent code/infrastructure changes
- Environment (dev/staging/production)
- Contact the development team with collected information.
Next Steps
- Monitoring Guide — CloudWatch metrics and alerts
- Infrastructure Setup — CloudFormation stack details