2016-07-31 98 views
0

我正在尝试注册一个使用用户池的用户,并在我的lambda中使用并修改了示例here中的代码。如何在Node.js Lambda中使用AWS用户池功能?

我引用AWS以正常方式:

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

,并试图引用现有的用户群:

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

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

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

,但我得到了以下错误:

TypeError: AWS.CognitoIdentityServiceProvider.CognitoUserPool is not a function

上午我使用错误的SDK? the setup page解释了aws-cognito-sdk.min.js是完整SDK的变体,但仅引用了Cognito Identity Service,因此我认为完整的SDK也将允许我访问它... 任何想法?

回答

3

所以,我理解了它。首先,是的,你可以使用标准的aws-sdk。 这里是代码:

var params = { 
    ClientId: 'xxxxxxxxxxxxxx', 
    Password: 'password', 
    Username: 'Ross', 
    UserAttributes: [ 
    { 
     Name: 'email', 
     Value: '[email protected]' 
    } 
    ] 
}; 
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(); 
cognitoidentityserviceprovider.signUp(params, function(err, data) { 
    if (err) { 
    console.log(err, err.stack); 
    context.fail(err); 
    } else { 
    console.log(data); 
    context.succeed(data); 
    } 
}); 
+0

完美的一杆解答。我正在寻找一个这样的简单例子超过3到4个小时,直到我找到这个。 – user3227262

+0

您好,我正在尝试使用JS的纯SDK来执行Cognito请求,但我看过的示例使用了认知身份SDK。你能告诉我,如果你发现任何材料,并在哪里,以得到你的答案?谢谢。 –

0

它看起来像你的代码中有语法错误。尝试改变这一点:

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

要这样:

var userPool = new AWS.CognitoIdentityServiceProvider.CognitoUserPool(poolData); 
+0

感谢您的发现 - 可能一直在转移到StackOverflow! – RossP