I'm trying to create a user in a AWS User Pool from an AWS Lambda
I tried with this script took from what seems to be the official JavascriptSDK for the AWS but can't get it working. http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#adminCreateUser-property
I keep getting this error:ypeError: cognitoidentityserviceprovider.adminCreateUser is not a function
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
var params = {
UserPoolId: 'eu-west-1_XXXXXXXX', /* required */
Username: '[email protected]', /* required */
DesiredDeliveryMediums: [
'EMAIL'
],
ForceAliasCreation: false,
MessageAction: 'SUPPRESS',
TemporaryPassword: 'tempPassword1',
UserAttributes: [
{
Name: 'email', /* required */
Value: '[email protected]'
},
{
Name: 'name', /* required */
Value: 'Me'
},
{
Name: 'last_name', /* required */
Value: 'lastme'
}
/* more items */
]
};
cognitoidentityserviceprovider.adminCreateUser(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
callback(null, data);
});
The User Pool Client ID is available from the Amazon Cognito User Pools console in the App Clients section. You should create an App Client if it doesn't already exist. Make sure to uncheck the "Generate client secret" box.
First login to your aws account and go to cognito section. If you don't have an aws account yet, create a free account which will be free for an year. Then go to Cognito section and then create a user pool. Give a name for the pool.
For adminCreateUser (you basically require the aws sdk, configure credentials, instantiate the client and call the specific operation).
var aws = require('aws-sdk');
aws.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'});
var CognitoIdentityServiceProvider = aws.CognitoIdentityServiceProvider;
var client = new CognitoIdentityServiceProvider({ apiVersion: '2016-04-19 });
//your code goes here
Note that there might be different ways in which you can configure the AWS credentials to call the operation. You do need credentials as this is an authenticated operation. Other admin operations are similar, you just need to pass the appropriate parameters as JSON in the call.
According to this, the AWS SDK for JavaScript version 2.7.25 which contains the adminCreateUser operation should be available.
http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With