adminUpdateUserAttributes

adminUpdateUserAttributes

本文介绍了AWS Cognito:adminUpdateUserAttributes不起作用,没有给出错误,我是否缺少某些东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让adminUpdateUserAttributes使Cognito正常工作. cli可以正常工作,我可以让用户添加/更改它们不是所希望的,但希望看到它能正常工作.

我正在对lambda函数使用AWS托管策略AmazonCognitoPowerUser,并且lambda正在触发,我是否缺少某些听起来听起来很简单的东西,但它却无法正常工作.

还有一种方法可以在不自行创建的情况下获得默认的创建日期.

const AWS = require('aws-sdk');
const cognitoidentityserviceprovider =  new AWS.CognitoIdentityServiceProvider();

exports.handler = async (event) => {
    cognitoidentityserviceprovider.adminUpdateUserAttributes(
  {
    UserAttributes: [
      {
        Name: 'custom:Date_Created',
        Value: new Date().toString() 
      }
      ....
    ],
    UserPoolId: " the correctpool id",
    Username: "dagTest"
  },
  function(err, data) { 
     if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);        
}
)};

// no errors and returns nothing as it says it should.
解决方案

我想这是因为您没有在等待结果,并且lambda在调用adminUpdateUserAttributes()之后终止了,并且dows一直等到它返回之后./p>

我建议您更改为基于Promise的呼叫并尝试/捕获

exports.handler = async (event) => {
  try{
    // no callback here
    const data = await cognitoidentityserviceprovider
      .adminUpdateUserAttributes(attributes)
      .promise()
    console.log('success', data)
  } catch(error) {
    console.error('error', error)
  }
)}

I can't get adminUpdateUserAttributes for Cognito to work. The cli works and I can have the user add/changed them not desired but wanted to see it working.

I'm using the AmazonCognitoPowerUser an AWS managed policy on the lambda function and the lambda is triggering, is there something I'm missing this sounds and looks easy but it's just not working.

also is there a way to get the default Created date without making my own.

const AWS = require('aws-sdk');
const cognitoidentityserviceprovider =  new AWS.CognitoIdentityServiceProvider();

exports.handler = async (event) => {
    cognitoidentityserviceprovider.adminUpdateUserAttributes(
  {
    UserAttributes: [
      {
        Name: 'custom:Date_Created',
        Value: new Date().toString() 
      }
      ....
    ],
    UserPoolId: " the correctpool id",
    Username: "dagTest"
  },
  function(err, data) { 
     if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);        
}
)};

// no errors and returns nothing as it says it should.
解决方案

I guess it is because you are not waiting for the result and the lambda is terminating after adminUpdateUserAttributes() is called and dows not wait until it is returning.

I would suggest that you change to promise based calling and do a try/catch

exports.handler = async (event) => {
  try{
    // no callback here
    const data = await cognitoidentityserviceprovider
      .adminUpdateUserAttributes(attributes)
      .promise()
    console.log('success', data)
  } catch(error) {
    console.error('error', error)
  }
)}

这篇关于AWS Cognito:adminUpdateUserAttributes不起作用,没有给出错误,我是否缺少某些东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 18:59