You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过CloudFormation启用Cognito的属性验证与用户账户确认

如何用CloudFormation配置Cognito自动发送账户确认邮件

你的CloudFormation模板没开启自动验证的核心开关,所以控制台里的“Allow Cognito to automatically send messages to verify and confirm”才处于Disabled状态。要实现用户注册时自动发送带自定义模板的确认邮件,只需补充以下配置:

关键修改点

  • 添加AutoVerifiedAttributes:指定自动验证的属性(这里是email),这是触发自动发邮件的核心配置
  • 完善VerificationMessageTemplate:补充自定义的邮件内容和主题,确保邮件包含确认码

修改后的完整模板

# Create Cognito UserPool (i.e., the table with the users)
UserPool:
  Type: "AWS::Cognito::UserPool"
  Properties:
    UserPoolName: auth-template-user-pool
    UsernameAttributes:
      - email
    # 开启邮箱自动验证,对应控制台的自动发送开关
    AutoVerifiedAttributes:
      - email
    VerificationMessageTemplate:
      DefaultEmailOption: CONFIRM_WITH_CODE
      # 自定义验证邮件内容,{####}会被替换为6位确认码
      EmailVerificationMessage: "你的账户确认码是 {####},请输入完成验证。"
      # 自定义邮件主题
      EmailVerificationSubject: "请确认你的账户"
    EmailConfiguration:
      EmailSendingAccount: COGNITO_DEFAULT
    Schema:
      - Name: name
        AttributeDataType: String
        Mutable: true
        Required: true
      - Name: family_name
        AttributeDataType: String
        Mutable: true
        Required: true
      - Name: email
        AttributeDataType: String
        Mutable: false
        Required: true

配置说明

  • AutoVerifiedAttributes:这个配置让Cognito在用户注册时自动触发邮箱验证流程,直接对应控制台中你看到的那个自动发送开关。
  • EmailVerificationMessage/EmailVerificationSubject:自定义邮件的内容和主题,其中{####}是Cognito的内置占位符,会自动替换为实际的确认码。如果不填,Cognito会用默认模板,但自定义更贴合业务场景。

重新部署模板后,用户注册时就能自动收到带自定义模板的确认邮件,和你在控制台手动设置的效果完全一致。

内容的提问来源于stack exchange,提问作者Andrea Nicolai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 04:38:12