I created an AWS Lambda function to test new Cognito User Pool account creation but no account was created in user pool and no error shown in console log. I checked AWS Cloud Watch but no error was reported in cloud watch also.
START RequestId: ..... Version: $LATEST
END RequestId: .....
REPORT RequestId: ..... Duration: 80.12 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 84 MB
I changed my Lambda function to something simpler; describeUserPool. Still no error was thrown and no user pool info was printed in console. I added a console.log print within the describeUserPool callback function but that did not print.
The lambda function was created using AWS Console Lambda inline editor. Lambda function has AmazonESCognitoAccess policy attached (this policy has List/Read/Write access level to Cognito User Pools).
Can anyone shed some lights on what I've gotten wrong? Thank you very much in advance.
var aws = require('aws-sdk');
aws.config.update({
accessKeyId: 'access_key_id',
secretAccessKey: 'secret_access_key',
region: 'us-east-1',
apiVersion: '2016-04-18'
});
var cognito = new aws.CognitoIdentityServiceProvider();
var params = {
UserPoolId: 'us-region-user-pool-id'
};
exports.handler = async (event) => {
cognito.describeUserPool(params, function(err, data) {
console.log('hello from inside function');
if (err) {
console.log(err);
} else {
console.log(data);
}
});
};
If I included an incorrect params in AdminCreateUser it reported error
var aws = require('aws-sdk');
aws.config.update({
accessKeyId: 'access_key_id',
secretAccessKey: 'secret_access_key',
region: 'us-east-1',
apiVersion: '2016-04-18'
});
var cognito = new aws.CognitoIdentityServiceProvider();
var params = {
UserPoolId: 'us-region-user-pool-id'
Username: 'someone',
TemporaryPassword: '11223344',
DesiredDeliveryMediums: 'EMAIL',
MessageAction: 'SUPPRESS',
UserAttributes: [
{
Name: 'Email',
Value: '[email protected]'
},
{
Name: 'Family_Name',
Value: 'One'
},
{
Name: 'Given_Name',
Value: 'Some'
},
{
Name: 'Phone_Number_verified',
Value: 'True'
},
{
Name: 'Email_verified',
Value: 'True'
}
],
};
exports.handler = async (event) => {
cognito.adminCreateUser(params, function(err, data) {
console.log('hello from inside function');
if (err) {
console.log(err);
} else {
console.log(data);
}
});
};
I received the following error message in Lambda inline editor console:
Response:
null
Request ID:
"6e50fdb4-e437-4b84-be7b-3caaeb5b0a98"
Function Logs:
ncCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:391:24)
at Config.getCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:411:9) {
code: 'MultipleValidationErrors',
errors: [
InvalidParameterType: Expected params.DesiredDeliveryMediums to be an Array
at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
at ParamValidator.validateType (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:232:10)
at ParamValidator.validateList (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:99:14)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:90:21)
at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)
at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:126:42)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at callNextListener (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:96:12) {
code: 'InvalidParameterType',
time: 2020-05-31T21:59:35.116Z
},
InvalidParameterType: Expected params.UserAttributes[3].Value to be a string
at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
at ParamValidator.validateType (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:232:10)
at ParamValidator.validateString (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:154:32)
at ParamValidator.validateScalar (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:130:21)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:94:21)
at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validateList (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:103:14)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:90:21)
at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14) {
code: 'InvalidParameterType',
time: 2020-05-31T21:59:35.116Z
},
InvalidParameterType: Expected params.UserAttributes[4].Value to be a string
at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
at ParamValidator.validateType (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:232:10)
at ParamValidator.validateString (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:154:32)
at ParamValidator.validateScalar (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:130:21)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:94:21)
at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validateList (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:103:14)
at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:90:21)
at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:75:14) {
code: 'InvalidParameterType',
time: 2020-05-31T21:59:35.116Z
}
],
time: 2020-05-31T21:59:35.173Z
}
END RequestId: 6e50fdb4-e437-4b84-be7b-3caaeb5b0a98
REPORT RequestId: 6e50fdb4-e437-4b84-be7b-3caaeb5b0a98 Duration: 122.82 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 80 MB Init Duration: 356.12 ms
successfully. Timestamp Message There are older events to load. Load more. 2020-05-31T16:59:07.766-04:00 START RequestId: 1ea1741e-d9e7-4991-af9d-f72bf73b1133 Version: $LATEST 2020-05-31T16:59:08.202-04:00 END RequestId: 1ea1741e-d9e7-4991-af9d-f72bf73b1133 2020-05-31T16:59:08.202-04:00 REPORT RequestId: 1ea1741e-d9e7-4991-af9d-f72bf73b1133 Duration: 434.49 ms Billed Duration: 500 ms Memory Size: 128 MB Max Memory Used: 83 MB Init Duration: 337.21 ms
. However there's no CloudWatch metric for Cognito. – billyap