RossP RossP - 1 year ago 526
Node.js Question

How do you use AWS User Pool functions in a Node.js Lambda?

I am trying to sign up a user using User Pools and have used and adapted the code from the example here in my lambda.

I reference AWS in the normal manner:

var AWS = require('aws-sdk');

and attempt to reference an existing user pool:

AWS.config.region = 'eu-east-1';

var poolData = {
UserPoolId : 'eu-west-1_xxxxxxx',
ClientId : 'xxxxxxx'

var userPool = AWS.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

but I get the following error:

TypeError: AWS.CognitoIdentityServiceProvider.CognitoUserPool is not a function

Am I using the wrong SDK? the setup page explains how aws-cognito-sdk.min.js is variant of the full SDK but references just the Cognito Identity Service, so I assume that the full SDK will also allow me to access it...
Any ideas?

Answer Source

So, I've figured it out. Firstly, yes you can use the standard aws-sdk. Here is the code:

var params = {
  ClientId: 'xxxxxxxxxxxxxx',
  Password: 'password',
  Username: 'Ross',
  UserAttributes: [
      Name: 'email',
      Value: ''
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
cognitoidentityserviceprovider.signUp(params, function(err, data) {
  if (err) {
    console.log(err, err.stack);;
  } else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download