我是AWS的新手,我正在寻找一种方法,允许我的Android应用程序的用户在不经过验证过程的情况下更改他们的电子邮件(我已经成功为订阅做到了这一点)。
我尝试遵循this和this,并且我所做的如下。
在我的Android应用程序中:
结果是:电子邮件已经成功更新(但是没有使用lambda也可以),但是lambda会崩溃,并显示以下错误:
我尝试遵循this和this,并且我所做的如下。
在我的Android应用程序中:
public void onClickChangeEmail(View view)
{
CognitoUserAttributes attributes = new CognitoUserAttributes();
attributes.getAttributes().put("email", "second@mail.com");
CognitoSettings
.getCognitoUserPool(MainActivity.this)
.getCurrentUser()
.updateAttributesInBackground(attributes, new UpdateAttributesHandler()
{
@Override
public void onSuccess(List<CognitoUserCodeDeliveryDetails> attributesVerificationList)
{
Log.i("tag", "Email updated!");
}
@Override
public void onFailure(Exception e)
{
e.printStackTrace();
}
});
}
然后,在我的AWS控制台中,我在Cognito上添加了一个触发器,用于自定义消息,以下是我的Lambda函数,每当用户更新其电子邮件时触发:
const AWS = require('aws-sdk')
AWS.config.update({region: 'eu-central-1'});
exports.handler = (event, context, callback) => {
if (event.triggerSource === 'CustomMessage_UpdateUserAttribute')
{
const params = {
UserAttributes: [
{
Name: 'email_verified',
Value: 'true',
},
],
UserPoolId: event.userPoolId,
Username: event.userName,
};
var cognitoIdServiceProvider = new AWS.CognitoIdentityServiceProvider();
cognitoIdServiceProvider.adminUpdateUserAttributes(params, function(err, data) {
if (err) context.done(err, event); // an error occurred
else context.done(null, event); // successful response
});
}
else
{
context.done(null, event);
}
};
结果是:电子邮件已经成功更新(但是没有使用lambda也可以),但是lambda会崩溃,并显示以下错误:
autoValidationUserEmailModification is not authorized to perform: cognito-idp:AdminUpdateUserAttributes
,看起来缺少授权。我的问题是:如何修复授权部分?这种方法是否正确地禁用了更新用户电子邮件的电子邮件验证方式?感谢您的帮助。
autoValidationUserEmailModification
吗? - hoangdv