Reputation: 837
I am starting with aws-cognito. I have created a UserPool and a UserPoolClient on the Amazon platform. I am implementing a lambda (as a test) that performs the registration of a user. But trying to run it with the postman returns "Internal Server Error". This is the code of my Lambda.
module.exports.register = async event => {
var AmazonCognitoIdentity = require('amazon-cognito-identity-js');
var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;
var poolData = {
UserPoolId: '...', // Here, I put my UserPoolId
ClientId: '...' // Here, I put my ClientId
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var attributeList = [];
var dataEmail = {
Name: 'email',
Value: '[email protected]'
};
var dataPhoneNumber = {
Name: 'phone_number',
Value: '+15555555555'
};
var attributeEmail = new AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);
var attributePhoneNumber = new AmazonCognitoIdentity.CognitoUserAttribute(dataPhoneNumber);
attributeList.push(attributeEmail);
attributeList.push(attributePhoneNumber);
var cognitoUser = ''
userPool.signUp('[email protected]', 'MyPassword7.com', attributeList, null, function (err, result) {
if (err) {
cognitoUser = err;
}
cognitoUser = result.user;
});
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
cognitoUser: cognitoUser
},
null,
2
),
};
Upvotes: 0
Views: 268
Reputation: 1917
I think you need to add the proper headers in your response
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
'Content-Type': 'application/json',
},
Upvotes: 1