In the past few days I've been testing a certain flow using AWS Lambda functions and my lambda function that gets triggered after a pre-sign up in the Cognito User pool was working fine and returning the callback function well. But since yesterday I've been seeing the following error:-
ntime/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:690:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
2021-04-19T11:09:07.321Z b42b6dd0-b290-454c-afa9-6be666903995 INFO InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688: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:690:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
code: 'InvalidLambdaResponseException',
time: 2021-04-19T11:09:07.260Z,
requestId: 'a52a10ae-efdf-4358-b6e0-8c6bbbc10f26',
statusCode: 400,
retryable: false,
retryDelay: 45.341053308762234
}
2021-04-19T11:09:07.508Z b42b6dd0-b290-454c-afa9-6be666903995 INFO InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688: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:690:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
code: 'InvalidLambdaResponseException',
time: 2021-04-19T11:09:07.260Z,
requestId: 'a52a10ae-efdf-4358-b6e0-8c6bbbc10f26',
statusCode: 400,
retryable: false,
retryDelay: 48.61578358654741
} InvalidLambdaResponseException: Invalid lambda function output : Invalid JSON
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688: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:690:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
END RequestId: b42b6dd0-b290-454c-afa9-6be666903995
REPORT RequestId: b42b6dd0-b290-454c-afa9-6be666903995 Duration: 2564.50 ms Billed Duration: 2565 ms Memory Size: 128 MB Max Memory Used: 88 MB Init Duration: 427.70 ms
This is the lambda function:-
var AWS = require("aws-sdk");
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({
apiVersion: '2016-04-18'
});
exports.handler = async (event, context, callback) => {
console.log("Event input => ", event);
const attributes = event.arguments;
const userPoolId = process.env.USERPOOL_ID;
var params = {
UserPoolId: userPoolId,
Username: attributes.username,
DesiredDeliveryMediums: ["EMAIL"],
UserAttributes: [{
Name: "email",
Value: attributes.email,
},
{
Name: "email_verified" /* required */ ,
Value: "true",
},
{
Name: "name" /* required */ ,
Value: attributes.name,
}
]
};
try {
const data = await cognitoidentityserviceprovider
.adminCreateUser(params, function(err, data) {
if (err) {
console.log(err, err.stack);
// an error occurred
}
else {
console.log("SUCCESS", JSON.stringify(data)); // successful response
}
callback(null, data);
})
.promise();
} catch (error) {
console.log(error);
}
};
This is the test event I'm using:-
{
"arguments": {
"name": "John Smith",
"username": "jsmith",
"email": "jsmith.com@gmail.com",
}
}
I am not sure if I accidentally changed something in the code and don't remember or if something changed on AWS's side that is resulting in this. I have identified that the issue occurs when I am calling the adminCreateUser method from the try catch block. But can't figure out what specifically is resulting in the error from the error stack. Help would be appreciated!
Update:-
After spending plenty of hours trying to fix this and some of the other obscure errors while trying to build custom resolvers, I just ended up switching away from AWS AppSync and ended up building my own custom API with Django and Graphene-based GraphQL API that I hosted on Heroku. And it made a world of difference in the speed and customizability that I had in my hands. I would highly recommend looking into the Python-based FastAPI which is much more lightweight and super impressive, both in terms of performance (It's as fast as NodeJS!) and modernity. I will be using that as my GraphQL API for my upcoming projects.