REST API: Request failed with status code 431
See original GitHub issueDescribe the bug
I have an aws-serverless-express
lambda function, created by Amplify, that is invoked by an Amplify created API. The API was configured to not require authorization. However, when using the Auth
module, it appears that the x-amz-security-token
is put in both multiValueHeaders
and headers
, in the lambda event
object. Example structure (notice “headers” and “multValueHeaders”):
{
"resource": <OMITTED>,
"path": <OMITTED>,
"httpMethod": "GET",
"headers": {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "br, gzip, deflate",
"Accept-Language": "en-us",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Host": <OMITTED>,
"User-Agent": "aws-amplify/1.0.25 react-native",
"Via": <OMITTED>,
"X-Amz-Cf-Id": <OMITTED>,
"x-amz-date": "20190501T155047Z",
"x-amz-security-token": <SECURITY_TOKEN>,
"X-Amzn-Trace-Id": "Root=1-5cc9c057-73b3fb6ac5775296d659372c",
"X-Forwarded-For": "24.243.147.62, 70.132.9.87",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"multiValueHeaders": {
"Accept": [
"application/json, text/plain, */*"
],
"Accept-Encoding": [
"br, gzip, deflate"
],
"Accept-Language": [
"en-us"
],
"CloudFront-Forwarded-Proto": [
"https"
],
"CloudFront-Is-Desktop-Viewer": [
"true"
],
"CloudFront-Is-Mobile-Viewer": [
"false"
],
"CloudFront-Is-SmartTV-Viewer": [
"false"
],
"CloudFront-Is-Tablet-Viewer": [
"false"
],
"CloudFront-Viewer-Country": [
"US"
],
"Host": [
<OMITTED>
],
"User-Agent": [
"aws-amplify/1.0.25 react-native"
],
"Via": [
<OMITTED>
],
"X-Amz-Cf-Id": [
<OMITTED>
],
"x-amz-date": [
"20190501T155047Z"
],
"x-amz-security-token": [
<SECURITY_TOKEN>
],
"X-Amzn-Trace-Id": [
"Root=1-5cc9c057-73b3fb6ac5775296d659372c"
],
"X-Forwarded-For": [
"24.243.147.62, 70.132.9.87"
],
"X-Forwarded-Port": [
"443"
],
"X-Forwarded-Proto": [
"https"
]
},
"queryStringParameters": null,
"multiValueQueryStringParameters": null,
"pathParameters": null,
"stageVariables": null,
"requestContext": {
"resourceId": <OMITTED>,
"resourcePath": <OMITTED>,
"httpMethod": "GET",
"extendedRequestId": <OMITTED>,
"requestTime": "01/May/2019:15:50:47 +0000",
"path": <OMITTED>,
"accountId": "<OMITTED>,
"protocol": "HTTP/1.1",
"stage": "dev",
"domainPrefix": "4xnuilt9x4",
"requestTimeEpoch": 1556725847460,
"requestId": <OMITTED>,
"identity": {
"cognitoIdentityPoolId": null,
"accountId": null,
"cognitoIdentityId": null,
"caller": null,
"sourceIp": <OMITTED>,
"accessKey": null,
"cognitoAuthenticationType": null,
"cognitoAuthenticationProvider": null,
"userArn": null,
"userAgent": "aws-amplify/1.0.25 react-native",
"user": null
},
"domainName": <OMITTED>,
"apiId": <OMITTED>
},
"body": null,
"isBase64Encoded": false
}
To Reproduce Steps to reproduce the behavior:
- amplify add auth (fine-grained multi-access IAM)
- amplify add api (create a serverless lambda function with no authentication required)
- configure the lambda function in the AWS console, to use a custom runtime (node 12).
- set a layer to ARN to arn:aws:lambda:<region>:553035198032:layer:nodejs12:1
- call the api using
API.get(<API>, "/path")
and you might get an error like the one below:
Error: Request failed with status code 431
at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:572)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
at XMLHttpRequest.js:507
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:366)
at MessageQueue.js:106
Expected behavior Just a few days ago, I was able to make these sort of API calls, and after removing and replacing the API with a slightly different config (no dynamodb dependency in the lambda function), I get 431 on all my calls.
Desktop (please complete the following information):
- OS: mac osx
- Browser: chrome
Smartphone (please complete the following information):
- Device: iOS Simulator iPhone X
- OS: iOS 12.0 (i think)
Sample Code index.js (had to be slightly altered form default, to run with node 11+)
const app = require("./app");
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => {
console.log(EVENT: ${JSON.stringify(event)}`);
console.log(Buffer.byteLength(JSON.stringify(event)));
awsServerlessExpress.proxy(server, event, context);
};```
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Aha!! I was trying to set
NODE_OPTIONS="--max-http-header-size=16000"
underprocess.env
without any luck, however setting the variable in the aws console for lambda works. You da man! Thanks!This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.