DEV Community

Cover image for Solving Frontend-Lambda Timeout Issues with AppSync Asynchronous Execution
Ismail G.
Ismail G.

Posted on

Solving Frontend-Lambda Timeout Issues with AppSync Asynchronous Execution

A common issue in serverless applications: the frontend receives a timeout error while CloudWatch logs show the Lambda function completed successfully. Users see failed requests, but backend operations succeed.

When a Lambda function is called synchronously, the API waits for it to complete and return a response. For long-running tasks, this might cause considerable delays.

Critical timeout constraints:

Layer Maximum Timeout Configurable
Lambda Function 15 minutes Yes
API Gateway (REST) 29 seconds No
AppSync (GraphQL) 30 seconds No

The Solution: AppSync Asynchronous Lambda Execution

AWS AppSync provides asynchronous Lambda resolver support. Asynchronous execution lets a GraphQL mutation trigger a Lambda function without waiting for it to finish. The resolver returns immediately, bypassing the 30-second timeout limit.

With this pattern, the frontend is no longer tied to the duration of the Lambda execution. This enables long-running workflows to complete in the background.


```Before (Synchronous):
Frontend → "Start job" → Wait 30s → Timeout ❌
Lambda still running...

After (Asynchronous):
Frontend → "Start job" → Get job ID immediately ✅
Lambda runs independently → Updates result → Frontend gets notified ✅```

How It Works

When a GraphQL mutation is invoked with an async handler, AppSync invokes the Lambda function using Event invocation type (asynchronous mode). It returns a response—typically containing a job identifier—without waiting for Lambda completion.

The Lambda function then executes independently in the background. The frontend retrieves results through two methods:

Real-time updates: GraphQL subscriptions notify the client when data changes
Polling: Periodic GraphQL queries check job status at defined intervals

This architecture eliminates the 30-second AppSync resolver timeout limitation while maintaining a responsive user experience.

Implementation with AWS Amplify Gen 2

For Amplify applications using AppSync, AWS provides native support for asynchronous Lambda resolvers:

  • The frontend triggers a GraphQL mutation.
  • AppSync invokes the Lambda function in asynchronous mode and immediately returns a task reference.
  • The Lambda executes independently.
  • Results are written to a datastore.
  • The frontend retrieves results via follow-up GraphQL queries, or AppSync subscriptions (real-time updates).

AWS Documentation:

https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/#async-function-handlers

Top comments (0)