Skip to main content
Diagnose and resolve common issues in the CGIAR Risk Intelligence Tool deployment.

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
Diagnosis: Check CloudWatch logs:
Common Causes:

1. Missing Module After esbuild Bundle

Error:
Solution: The package wasn’t included in EXTERNALS in scripts/deploy-api.sh. Add it:
Redeploy:

2. ESM/CJS Interop Error

Error:
Solution: Ensure packages/api/tsconfig.json has:
Rebuild and redeploy:

3. Missing Environment Variables

Error:
Solution: Verify Lambda environment variables:
Required variables:
  • COGNITO_USER_POOL_ID
  • COGNITO_CLIENT_ID
  • DATABASE_URL
  • S3_BUCKET_NAME
  • WORKER_FUNCTION_NAME
  • ENVIRONMENT
Update via CloudFormation or AWS Console → Lambda → Configuration → Environment variables.

Lambda Timeout (29s for API, 15min for Worker)

Symptoms:
  • Request hangs then fails
  • CloudWatch shows Task timed out after 29.00 seconds
Diagnosis: Check duration before timeout:
Common Causes:

1. Event Loop Not Draining (Prisma Connections)

Symptom: Lambda hangs for full timeout even after handler completes. Solution: Verify context.callbackWaitsForEmptyEventLoop = false in both Lambda handlers. API Lambda (src/lambda.ts:29):
Worker Lambda (src/worker.ts:26):

2. Slow Bedrock Calls

Symptom: Worker Lambda times out processing large documents. Solution: Check Bedrock processing time:
If processingTime > 600000 (10 minutes):
  1. Increase Worker timeout:
  2. Split large documents into chunks (application logic change required).

3. Database Query Slow

Symptom: API Lambda times out on specific endpoints. Check RDS performance:
Solutions:
  • Add database indexes
  • Optimize Prisma queries (avoid N+1)
  • Upgrade RDS instance type

Prisma Issues

Error: PrismaClientKnownRequestError with Empty Message

Symptoms:
  • CloudWatch shows PrismaClientKnodRequestError but message is empty
  • Error details missing in logs
Cause: esbuild bundles strip Prisma error messages. Solution: Always log .code and .meta instead of .message:
This pattern is already implemented in the codebase (see packages/api/CLAUDE.md:143).

Common Prisma Error Codes

Database Connection Failures

Error:
Cause: DATABASE_URL not set or incorrect. Diagnosis:
Expected format:
Solution:
  1. Get DB password from Secrets Manager:
  2. Get RDS endpoint:
  3. Update Lambda environment variable via CloudFormation or Console.

Migration Failed via Worker Lambda

Error:
Cause: Migration already partially applied. Solution:
  1. Check migration status:
  2. Manually mark failed migration as rolled back or completed.
  3. Re-run:

Cognito Issues

Error: NotAuthorizedException

Symptoms:
  • Login fails with “Invalid credentials”
  • CloudWatch shows NotAuthorizedException
Common Causes: See packages/api/src/common/exceptions/cognito.exception.ts for full mapping. Solutions:
  1. Wrong Credentials:
    • User resets password via “Forgot Password” flow
    • Admin resets via:
  2. User Not Confirmed:
    • Admin confirms user:
  3. 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
Cause: Cognito User Pool Client not configured for ID tokens. Solution: Verify User Pool Client has openid scope:
Update in CloudFormation template if missing.

Bedrock Issues

Error: ThrottlingException

Symptoms:
  • Worker Lambda logs show ThrottlingException
  • Jobs fail after 3 retries
Cause: Bedrock model rate limit exceeded. Current Limits (us-east-1):
  • Claude 3.5 Sonnet: 400 requests/minute, 160,000 tokens/minute
Solutions:
  1. Request Quota Increase:
    • AWS Console → Service Quotas → AWS Bedrock
    • Request increase for specific model
  2. Add Backoff: Already implemented with exponential backoff (200ms → 5s).
  3. Reduce Concurrency:

Error: ValidationException: Malformed input request

Symptoms:
  • Bedrock call fails immediately
  • No retry attempts
Cause: Invalid prompt structure or missing required fields. Diagnosis: Check CloudWatch for logged request body:
Common Issues:
  • Missing anthropic_version: bedrock-2023-05-31
  • Empty system or messages array
  • Invalid max_tokens (must be 1-4096)
Solution: Verify prompt templates in database:
Ensure templates contain valid placeholders and content.

Circuit Breaker Open

Error:
Cause: 3+ consecutive Bedrock failures triggered circuit breaker. Solution: Circuit breaker auto-resets after 60 seconds. Check Bedrock status:
If Bedrock is healthy, investigate underlying cause (throttling, invalid requests).

Job Processing Issues

Job Stuck in PENDING Status

Symptoms:
  • Job created but never processed
  • Polling shows status: PENDING indefinitely
Diagnosis:
  1. Check if Worker Lambda was invoked:
  2. Verify WORKER_FUNCTION_NAME env var on API Lambda:
Solutions:
  • Missing env var: Update CloudFormation template
  • IAM permission denied: Add lambda:InvokeFunction to API Lambda role
  • Worker Lambda disabled: Check Lambda console
Manual retry:

Job Fails After Max Attempts

Symptoms:
  • Job status transitions PENDING → PROCESSING → PENDING → FAILED
  • attempts field equals maxAttempts (default 3)
Diagnosis: Check job error message:
Common Errors:
  • Bedrock throttling (see Bedrock section)
  • Document parsing timeout (increase Worker timeout)
  • Invalid job input (check input field)
Solution: Fix underlying issue, then reset job:
Manually invoke Worker Lambda (see above).

Deployment Issues

deploy-api.sh Fails: “Could not describe stack”

Error:
Cause: CloudFormation stack doesn’t exist or wrong region. Solution:
  1. Verify stack exists:
  2. If missing, deploy infrastructure first:
  3. Check AWS region:

Lambda Update Fails: Package Too Large

Error:
Cause: Lambda deployment package exceeds 250MB unzipped limit. Solution: Review 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
Check bundle size:
Expected: ~15-20MB

CloudFront Serves Stale Content After Deployment

Symptoms:
  • Web deployment succeeds
  • Frontend shows old code
Cause: CloudFront cache not invalidated. Solution:
  1. Check if invalidation was created:
  2. Manually invalidate:
  3. 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:
  1. Gather diagnostics:
  2. Document:
    • Steps to reproduce
    • Error messages from CloudWatch
    • Recent code/infrastructure changes
    • Environment (dev/staging/production)
  3. Contact the development team with collected information.

Next Steps