AWS cognito: adminUpdateUserAttributes not working and not giving an error , am i missing something?

为君一笑 提交于 2020-08-09 09:35:12

问题


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.

回答1:


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)
  }
)}


来源:https://stackoverflow.com/questions/56046662/aws-cognito-adminupdateuserattributes-not-working-and-not-giving-an-error-am

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!