在使用 AWS Cognito 创建用户时,可能会遇到以下错误:
InvalidParameterException: Invalid email address format.
这是因为 AWS Cognito 对于 email 属性有一些限制,必须包含“@”和“.”字符。因此,解决方法是确保输入的 email 属性符合这些要求。
代码示例:
import boto3
client = boto3.client('cognito-idp')
response = client.admin_create_user(
UserPoolId='your_userpool_id',
Username='test_user',
UserAttributes=[
{
'Name': 'email',
'Value': 'test_email.com'
},
],
TemporaryPassword='testpass#123',
MessageAction='SUPPRESS'
)
print(response)
在上面的示例中,我们创建了一个名为“test_user”的用户,并将 email 属性设置为“test_email.com”。但是,由于 email 属性不符合要求,会出现 InvalidParameterException 错误。因此,我们需要将 email 属性更改为正确的格式,例如“test_email@domain.com”。