AWS cognito:adminUpdateUserAttributes 不工作并且没有给出错误,我错过了什么吗?
AWS cognito: adminUpdateUserAttributes not working and not giving an error , am i missing something?
我无法让 Cognito 工作的 adminUpdateUserAttributes。 cli 有效,我可以让用户 add/changed 他们不想要但希望看到它正常工作。
我在 lambda 函数上使用 AmazonCognitoPowerUser 和 AWS 托管策略,并且 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 不会等到它返回。
我建议您更改为基于承诺的调用并执行 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)
}
)}
@thopaw 该代码是正确的,但没有按预期对我起作用。即使在 Cognito AWS 控制台中成功更新了自定义属性,我仍然在前端收到 Auth Error。我必须添加 context.done(null,event);
以便 return 在执行 lambda 后对 Cognito 的控制。所以更新的可能是,
exports.handler = async (event, context) => {
try{
const data = await cognitoidentityserviceprovider
.adminUpdateUserAttributes(attributes)
.promise()
console.log('success', data)
} catch(error) {
console.error('error', error)
}
context.done(null,event);
)}
我无法让 Cognito 工作的 adminUpdateUserAttributes。 cli 有效,我可以让用户 add/changed 他们不想要但希望看到它正常工作。
我在 lambda 函数上使用 AmazonCognitoPowerUser 和 AWS 托管策略,并且 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 不会等到它返回。
我建议您更改为基于承诺的调用并执行 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)
}
)}
@thopaw 该代码是正确的,但没有按预期对我起作用。即使在 Cognito AWS 控制台中成功更新了自定义属性,我仍然在前端收到 Auth Error。我必须添加 context.done(null,event);
以便 return 在执行 lambda 后对 Cognito 的控制。所以更新的可能是,
exports.handler = async (event, context) => {
try{
const data = await cognitoidentityserviceprovider
.adminUpdateUserAttributes(attributes)
.promise()
console.log('success', data)
} catch(error) {
console.error('error', error)
}
context.done(null,event);
)}