Using 2.180.0, running simply:
var AWS = require('aws-sdk');
var lambda = new AWS.Lambda();
var params = {
FunctionName: 'hello-world' /* required */,
Payload: 'STRING_VALUE' /* Strings will be Base-64 encoded on your behalf */
};
lambda.invoke(params, function(err, data){
if(err){console.log(err, err.stack);} // an error occurred
else {console.log(data);} // successful response
});
as per the SDK docs returns:
"{ InvalidRequestContentException: Could not parse request body into json: Unrecognized token 'STRING_VALUE': was expecting ('true', 'false' or 'null')}"
This seems to be a response from the Lambda server, so either the docs are wrong or Lambda is broken. I don't know where else to submit this bug, since AWS support is impossible to get a hold of in a timely fashion without paying AWS lots of money.
Setting the Payload to new Buffer('hello world') also fails.
Running it without a Payload is fine, although rather useless. I should have more than adequate permissions on my local machine to execute the function.
The full stack trace:
{ InvalidRequestContentException: Could not parse request body into json: Unrecognized token 'STRING_VALUE': was expecting ('true', 'false' or 'null')}
at [Source: [B@51e2db23; line: 1, column: 25]
at Object.extractError (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/protocol/json.js:48:27)
at Request.extractError (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)
at Request.callListeners (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:685:12)
message: 'Could not parse request body into json: Unrecognized token \'STRING_VALUE\': was expecting (\'true\', \'false\' or \'null\')\n at [Source: [B@51e2db23; line: 1, column: 25]',
code: 'InvalidRequestContentException',
time: 2018-01-12T16:57:38.437Z,
requestId: 'b1e6c1b5-f7b9-11e7-88ec-77d8712e737a',
statusCode: 400,
retryable: false,
retryDelay: 40.419110106244524 } 'InvalidRequestContentException: Could not parse request body into json: Unrecognized token \'STRING_VALUE\': was expecting (\'true\', \'false\' or \'null\')\n at [Source: [B@51e2db23; line: 1, column: 25]\n at Object.extractError (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/protocol/json.js:48:27)\n at Request.extractError (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)\n at Request.callListeners (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/sequential_executor.js:105:20)\n at Request.emit (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/sequential_executor.js:77:10)\n at Request.emit (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:683:14)\n at Request.transition (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:22:10)\n at AcceptorStateMachine.runTo (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/state_machine.js:14:12)\n at /Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/state_machine.js:26:10\n at Request.<anonymous> (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:38:9)\n at Request.<anonymous> (/Users/brettneese/Development/git/github.com/HBKEngineering/chartroom-api/node_modules/aws-sdk/lib/request.js:685:12)'
For future reference, I was able to do:
```
var object = {hello: "world"}
var params = {
FunctionName: 'hello-world' /* required /,
Payload: JSON.stringify(object)' / Strings will be Base-64 encoded on your behalf */
};
````
However, I still contend that this means the docs are wrong, because they suggest you can send a string. Technically that's correct, but the string must be JSON.
Hi @brettneese,
Unfortunately, the generated example code example referred to only knows about the data types required for each property of an operation's input and output; it is not aware of any semantic restrictions on what data those properties may contain.
Each property is documented below the example, however, which is where more thorough information about properties is communicated. The Payload property is documented as "JSON that you want to provide to your Lambda function as input."; it might be helpful to link directly to this documentation from the property name in the generated example.
Hey @jeskew, yeah, that makes sense. I read this thing many times and did not see that, and it seems there are a few others on the internets with this problem without a solution as well (hopefully they will Google and find this answer). The message coming back from Lambda is also less than helpful here, so that might be a good solution.
Thanks for your response!
I have same bug
Function Logs:
START RequestId: 99c5b8a1-1493-4207-b931-0a0a87539064 Version: $LATEST
2019-05-01T21:33:46.346Z 99c5b8a1-1493-4207-b931-0a0a87539064 { InvalidRequestContentException: Could not parse request body into json: Unrecognized token 'STRING_VALUE': was expecting ('true', 'false' or 'null')
at [Source: (byte[])"STRING_VALUE"; line: 1, column: 25]
at Object.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:48:27)
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)
message: 'Could not parse request body into json: Unrecognized token \'STRING_VALUE\': was expecting (\'true\', \'false\' or \'null\')\n at [Source: (byte[])"STRING_VALUE"; line: 1, column: 25]',
code: 'InvalidRequestContentException',
time: 2019-05-01T21:33:46.289Z,
requestId: '9782dd23-405e-4ad6-9f80-0229d548250e',
statusCode: 400,
retryable: false,
retryDelay: 22.979289126003046 } 'InvalidRequestContentException: Could not parse request body into json: Unrecognized token \'STRING_VALUE\': was expecting (\'true\', \'false\' or \'null\')\n at [Source: (byte[])"STRING_VALUE"; line: 1, column: 25]\n at Object.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:48:27)\n at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)\n at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)\n at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)\n at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)\n at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)\n at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)\n at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10\n at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)\n at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)'
END RequestId: 99c5b8a1-1493-4207-b931-0a0a87539064
//////MY CODE
// ASYNC SYNC
var params = {
FunctionName:
'arn:aws:lambda:us-west-2:*******************' /* required */,
InvokeArgs:
// new Buffer('...') || 'STRING_VALUE' || streamObject /* required */,
'STRING_VALUE',
};
lambda.invokeAsync(params, function(err, data) {
if (err) console.log(err, err.stack);
// an error occurred
else console.log(data); // successful response
});
// ASYNC SYNC
I GOT IT!
var params = {
FunctionName:
'arn:aws:lambda:us-west-2:372751*****:function:imageGen' /* required */,
InvokeArgs:
// new Buffer('...') || 'STRING_VALUE' || streamObject /* required */,
JSON.stringify('STRING_VALUE'),
// '"STRING_VALUE"', //if string needed - you can use this
};
lambda.invokeAsync(params, function(err, data) {
if (err) console.log(err, err.stack);
// an error occurred
else console.log(data); // successful response
});
// ASYNC SYNC
};
Greetings! We鈥檙e closing this issue because it has been open a long time and hasn鈥檛 been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.
Most helpful comment
For future reference, I was able to do:
```
var object = {hello: "world"}
var params = {
FunctionName: 'hello-world' /* required /,
Payload: JSON.stringify(object)' / Strings will be Base-64 encoded on your behalf */
};
````
However, I still contend that this means the docs are wrong, because they suggest you can send a string. Technically that's correct, but the string must be JSON.