A Lambda function fails to send its response back, with HTTP 413
LAMBDA_RUNTIME Failed to post handler success response. Http response code: 413Short 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.
Fix it fast
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 } }"}'2Match what you see, then jump to its fix
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 10mConfirmed by docs.aws.amazon.com
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-fn2Fix
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/exportConfirmed by docs.aws.amazon.com
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:
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Servers
AWS CDK cannot find module '@aws-cdk/aws-ec2' (or another @aws-cdk/aws-* package)
Cannot find module '@aws-cdk/aws-ec2'
CDK v2 no longer ships one npm package per service.
3 causes, each with a fixServers
cdk deploy fails in a GitLab job with spawnSync docker ENOENT
code: 'ENOENT'
ENOENT means the operating system found no docker program to run.
3 causes, each with a fixServers
Node.js app says Cannot find module only when it runs under Docker Compose
The same image starts fine with docker run but fails with docker compose up
The image installed node_modules, but a Compose volume mounted over the app folder hides them.
3 causes, each with a fixServers
A native Node.js module fails on AWS Lambda with invalid ELF header
Error: /var/task/node_modules/<package>/build/Release/<name>.node: invalid ELF header
Lambda loads native addons on Linux, so a .node file built on macOS or Windows is not a valid Linux ELF file there.
3 causes, each with a fixServers
POST requests to a Node.js or Express API return 405 Not Allowed from nginx
The error page is served by nginx, and the Express logs show no request
When the 405 page comes from nginx and not from Express, nginx never handed the POST to your app.
3 causes, each with a fixServers
Status code 460 on an AWS Application Load Balancer
elb_status_code 460 in ALB access logs
A 460 is generated by the load balancer, not by your app.
3 causes, each with a fix