2017-05-22 12 views
1

私は多くのget/set属性をCognito SDKでクライアント側で動作させていますが、今ではラムダ関数(ステップ関数内)を介してバックエンドからユーザーのカスタム属性を変更できる必要があります。ラムダの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); 
     }); 
    }); 
} 

しかし、これのバックエンドバージョンでは、私は技術的にユーザーを管理しています。

したがって、ラムダ関数からユーザーの属性データを変更するにはどうすればよいですか?ユーザーは必ずしも最初にサインインする必要はありませんか?

答えて

2

そのユーザーのトークンがないため、ユーザーの属性を更新することはできません。

代わりに、CognitoIdentityServiceProvideradminUpdateUserAttributesを使用して、パラメータでユーザー名を使用し、属性を更新します。

これは、ラムダ実行ロールがSDK呼び出しに使用されるため、ラムダ実行ロールに適切な権限を持っている必要があります。 Coginitoの属性を編集するにはラムダの権限が必要です。コールの

ドキュメント:adminUpdateUserAttributes

+0

ブリリアント、ここに感謝 – Kristian

+0

Cognito devが、これが正しい答えです。 –

関連する問題