Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A Lambda function fails to send its response back, with HTTP 413

ErrorLAMBDA_RUNTIME Failed to post handler success response. Http response code: 413

Short answer

HTTP 413 means the response the function tried to return is too big. A buffered synchronous Lambda response is limited to 6 MB. Measure what you return, cut it down with paging or a smaller field list, or switch the function to response streaming, which allows up to 200 MB.

  • Applies to AWS Lambda Node.js 22, Express on Lambda, GraphQL on Lambda
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out how large the response body really is. Run the same request against the function URL or API and count the bytes.

    curl -s -o /dev/null -w '%{size_download}\n' 'https://example.com/graphql' -H 'content-type: application/json' -d '{"query":"{ items { id name } }"}'
  2. 2Match what you see, then jump to its fix

    1. 1The size from the first step is above about 6 million bytes, or the query returns a very long listA buffered response is larger than 6 MBFix
    2. 2The big response is wanted as is, for example an export or a file downloadThe result must be large, and the handler is not a streaming oneFix

What does the error look like?

  • LAMBDA_RUNTIME Failed to post handler success response. Http response code: 413

Cause 1 of 2

A buffered response is larger than 6 MB

1Check

The quota for a synchronous invocation is 6 MB each for request and response. The limit counts the whole body your handler returns, not one field.

aws lambda get-function-configuration --function-name my-fn --query '{timeout:Timeout,memory:MemorySize}'

2Fix

Return less. Page the list (a limit and a cursor), drop fields the client does not use, or put the big result in an object store and return its location instead of its content.

// GraphQL resolver: cap the page size
items: (_, { first = 50, after }) => {
  const size = Math.min(first, 200);
  return loadItems({ size, after });
},

3Verify

Repeat the request. The response is below the limit, and the logs no longer show the 413 line.

aws logs tail /aws/lambda/my-fn --since 10m

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 2

The result must be large, and the handler is not a streaming one

1Check

Response streaming functions can return up to 200 MB, compared with 6 MB for buffered responses. It works on Node.js managed runtimes, through function URLs, InvokeWithResponseStream, or the API Gateway proxy integration.

aws lambda get-function-url-config --function-name my-fn

2Fix

Wrap the handler in awslambda.streamifyResponse and write the data to the response stream, ideally with pipeline(). Invoke the function in a way that supports streaming.

import { pipeline } from 'node:stream/promises';
import { Readable } from 'node:stream';

export const handler = awslambda.streamifyResponse(async (event, responseStream) => {
  const source = Readable.from(bigExportChunks());
  await pipeline(source, responseStream);
});

3Verify

Call the function through the streaming path and confirm that the full body arrives.

curl -s -o export.bin -w '%{size_download}\n' https://example.com/export

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Set a hard maximum page size in every list endpoint and every GraphQL list field.
  • Return files from object storage, not from the function body.
  • Log the response size in the handler, so a growing payload shows up before it hits the limit.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.