Reputation: 8234
I have a server less API with AWS API Gateway and Lambda function. I am using custom authorization function for authorization. The header is too large and due to which I am getting this error. Normally, for an nginx server, I would have changed the nging config and this would have been fixed. I don't know how to take care of this in AWS API Gateway.
Upvotes: 26
Views: 65859
Reputation: 1127
Old question, but if you're using Express JS on the back-end with the bodyParser middleware, that might be what's stopping you. You can update the size limit by defining the limit
property in the config object passed to bodyParser:
app.use(express.json({ limit: '200kb' }));
You can change the value to whatever suits your needs, the docs are here.
Upvotes: 2
Reputation: 21
If anyone runs into this when trying to upload files, make sure your file types are defined in the Settings portion of your API (in the tree under your API name in API Gateway). We encountered this error and both 500 and 502's when troubleshooting this. First thing was an RDS setting (we were calling the reader instance, not the writer when trying to edit). Next was the missing file types in our API settings. Those two changes got us to 200's - so bear in mind that the 413 error is a bit deceptive. For context, we are using the API Gateway with lambda functions in our web app. I hope this helps someone!
Upvotes: 2
Reputation: 725
I found that gunzipping the content solves this issue (code inspired from this blog post https://techblog.commercetools.com/gzip-on-aws-lambda-and-api-gateway-5170bb02b543)
See this example with Typescript:
export async function getResponse(savedItems) {
return new Promise<APIGatewayProxyResult>((resolve, reject) => zlib.gzip(JSON.stringify(savedItems), (error, gzippedResponse) => {
if (error) {
reject(error);
console.error(error);
} else {
const response: APIGatewayProxyResult = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
'Content-Encoding': 'gzip',
},
isBase64Encoded: true,
body: gzippedResponse.toString('base64'),
};
console.info(`response statusCode: ${response.statusCode} body length: ${response.body.length}`);
resolve(response);
}
}));
}
Upvotes: 1
Reputation: 1329
The limit for payload size currently cannot be changed. From https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html:
10MB payload size, which cannot be changed currently.
If you want more customization, you should run your API on an actual server (e.g. with Amazon EC2).
Upvotes: 9
Reputation: 7344
The 10MB payload limit applies to the message body. If you're running into limits on the header size, unfortunately these cannot be configured. They are stated on the CloudFront page: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
In particular:
Custom headers: maximum length of a header name 256 characters
Custom headers: maximum length of a header value 2,048 characters
Custom headers: maximum length of all header values and names combined 10,240 characters
Upvotes: 21