要发送短信到不同地区的手机号码,需要在Amazon SNS(Simple Notification Service)中创建对应的SMS通道,并将其配置为Cognito用户池的默认通知。以下是示例代码:
import boto3
sns = boto3.client('sns') response = sns.create_topic(Name='cognito-sms-topic') topic_arn = response['TopicArn']
import boto3
sns = boto3.client('sns') response = sns.create_sms_sandbox_phone_number( PhoneNumber='+1XXX5550100' # 输入要验证的电话号码 ) print(response)
import boto3 import json
client = boto3.client('cognito-idp') response = client.update_user_pool( UserPoolId='us-west-2_abcdefghi', # 输入你的用户池ID AdminCreateUserConfig={ 'AllowAdminCreateUserOnly': False, 'UnusedAccountValidityDays': 7, 'InviteMessageTemplate': { 'SMSMessage': 'Your verification code is {####}.', 'EmailSubject': 'Your verification code', 'EmailMessage': 'Your verification code is {####}.' } }, SmsConfiguration={ 'SnsCallerArn': 'arn:aws:sns:us-west-2:123456789012:cognito-sms-topic', 'ExternalId': '12345' }, MfaConfiguration='OPTIONAL', SmsConfigurationFailure='ROLLBACK_SQS_NOTIFICATIONS' ) print(response)