2017-05-22 18 views
1

我已经使用Cognito SDK完成了许多获取/设置属性工作客户端,但现在我需要能够通过Lambda函数(在一个步骤函数中)从后端修改用户的自定义属性。管理来自Lambda的cognito用户属性 - 他们必须登录吗?

但是在进程的客户端版本中,有一个步骤我必须检索当前的Cognito用户,这是因为他们之前已经通过认证。这是代码:

var poolData = this.poolData; 
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData); 
var cognitoUser = userPool.getCurrentUser(); 
if (cognitoUser != null) { 
    cognitoUser.getSession(function(err, session) { 
     var attributeList = []; 
     var attribute = { 
      Name : attr, 
      Value : value 
     }; 
     var attribute = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(attribute); 
     attributeList.push(attribute); 
     console.log("attributeList", attributeList); 

     cognitoUser.updateAttributes(attributeList, function(err, result) { 
     callback(err, result); 
     }); 
    }); 
} 

但在后端版本,我在技术上管理用户。

那么,我将如何修改lambda函数的用户属性数据?用户不一定先登录?

回答

2

因为您没有该用户的令牌,所以无法更新用户的属性。

取而代之的是使用的CognitoIdentityServiceProvider,它在参数中输入用户名并更新属性。

这将要求您对Lambda执行角色拥有正确的权限,因为这将用于SDK调用。所以你需要为你的lambda编辑coginito属性的权限。

文档召唤:adminUpdateUserAttributes

+0

辉煌,感谢 – Kristian

+0

Cognito开发这里,这是正确的答案。 –

相关问题