跳至内容

如何将 Amazon SES 与 Amazon Cognito 用户池集成?

3 分钟阅读
0

我想将 Amazon Simple Email Service (Amazon SES) 与 Amazon Cognito 用户池集成。

解决方案

**注意:**如果您在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI

先决条件:

不支持 Amazon Cognito 与 Amazon SES 的跨账户集成。您无法在一个账户中配置 Amazon Cognito 用户池,然后将其与另一个账户中的 Amazon SES 电子邮件地址集成。

查看 Amazon SES 沙盒限制

所有新的 Amazon SES 账户均会置于 Amazon SES 沙盒中,以防止欺诈和滥用行为。当您使用 Amazon SES 沙盒时,请查看限制

将您的账户移出 Amazon SES 沙盒

如果您尚未将账户从 Amazon SES 沙盒中移除,请完成以下步骤:

  1. 查看 Amazon SES 电子邮件配置中的 AWS 区域映射表。
    该映射表显示了 Amazon SES 身份可与 Amazon Cognito 用户池集成的区域。在将 Amazon SES 账户移出沙盒之前,请确保使用兼容的区域。
  2. 为您的 Amazon SES 账户申请生产访问权限。AWS Support 团队会在 24 小时内对您的请求做出初步回应。
    在您的生产访问请求获得批准后,您可以向任意收件人发送电子邮件。

**注意:**您必须切换到新的 Amazon Cognito 控制台体验,才能在同一区域中将 Amazon Cognito 与 Amazon SES 集成。

验证您的 Amazon SES 域身份

在 Amazon SES 中验证一个或多个域身份。如果您需要在验证之前创建域身份,请参阅创建域身份

验证您的 Amazon SES 电子邮件身份

在 Amazon SES 中验证一个或多个电子邮件地址。如果您需要在验证之前创建电子邮件地址身份,请参阅创建电子邮件地址身份

将您的用户池与已验证的身份集成

如果 Amazon SES 域身份已通过验证,请完成以下步骤:

  1. 登录 Amazon Cognito 控制台,然后选择 User Pools(用户池)。
  2. 选择用户池。
  3. Authentication methods(身份验证方法)菜单中,选择 Email configuration(电子邮件配置)。然后,选择 Edit(编辑)。
  4. FROM email address(发件人电子邮件地址)下,选择已通过 Amazon SES 验证的域身份。例如,example.com
  5. FROM sender name(发件人姓名)下,输入您的电子邮件地址。例如,admin@example.com

您可以为域身份添加自定义电子邮件地址。UpdateUserPool API 使用 Amazon SES 身份来配置 Amazon Cognito 用户池。

update-user-pool 命令示例:

$ aws cognito-idp update-user-pool --user-pool-id example_pool_id --email-configuration SourceArn=arn:aws:ses:example_region:example_account_number:identity/example_domain,EmailSendingAccount=DEVELOPER,From=user@example.com --region example_region

**重要事项:**UpdateUserPool API 会重置用户池的现有配置。首先,调用 DescribeUserPool API,然后将所有现有的用户池参数发送到 UpdateUserPool API。

以下是 update-user-pool 命令的描述:

  • example_pool_id 对应于 Amazon Cognito 用户池 ID。示例:ap-southeast-1_xxxxxxxx。
  • arn:aws:ses:example_region:example_account_number:identity/example_domain 是您的 Amazon SES 域身份的 Amazon 资源名称 (ARN)。
  • user@example.com 必须替换为您的电子邮件身份。
  • example_region 表示您的 Amazon Cognito 用户池所在的区域。示例:ap-southeast-1。

如果 Amazon SES 电子邮件身份已通过验证,请完成以下步骤:

  1. 登录 Amazon Cognito 控制台,然后选择 User Pools(用户池)。
  2. 选择用户池。
  3. Authentication methods(身份验证方法)菜单中,选择 Email configuration(电子邮件配置)。然后,选择 Edit(编辑)。
  4. FROM email address(发件人电子邮件地址)下,选择 Amazon SES 电子邮件域身份。例如,admin@example.com

对错误进行故障排除

解决未验证电子邮件地址错误

您可能会收到以下错误:"Email address is not verified. The following identities failed the check in region AP-SOUTHEAST-1: user@example.com."

如果您收到此错误,则表示您尝试从 Amazon SES 沙盒账户向未验证的电子邮件地址发送电子邮件。

要解决此错误,请将您的 Amazon SES 账户移出沙盒,或在 Amazon SES 中验证收件人的电子邮件地址

缺少电子邮件

如果用户没有收到来自您的 Amazon Cognito 用户池的电子邮件,请完成以下步骤:

  1. 确认您使用 Amazon Cognito 的默认电子邮件配置Amazon SES 电子邮件配置来发送电子邮件。

  2. 通过 AWS 管理控制台验证您的更新。或者,运行 DescribeUserPool API。
    describe-user-pool 命令示例:

    aws cognito-idp describe-user-pool --user-pool-id example_pool_id --region example_region --query 'UserPool.EmailConfiguration'

    您可能会收到以下输出之一:

    {  "SourceArn": "arn:aws:ses:us-east-1:123456789012:identity/admin@example.com",
      "EmailSendingAccount": "DEVELOPER",
      "From": "admin@example.com"
    }

    {  "SourceArn": "arn:aws:ses:us-east-1:123456789012:identity/admin@example.com",
      "EmailSendingAccount": "COGNITO_DEFAULT"
    }

    如果 EmailSendingAccountDEVELOPER,则表示您的用户池正在使用 Amazon SES。检查您的 Amazon SES 账户是否在沙盒中。如果在,请将其移出沙盒,以便向未验证的身份发送电子邮件。如果已不在沙盒中,请检查 Amazon SES 日志中是否存在电子邮件传送问题。
    如果 EmailSendingAccountCOGNITO_DEFAULT,则表示您的用户池正在使用 Amazon Cognito 的默认电子邮件功能。此功能对每个用户池发送的电子邮件设有配额

解决每日电子邮件配额错误

您可能会收到以下错误:"Exceeded daily email limit for the operation or account. Number of allowed operation has exceeded. If a higher limit is required, please configure your user pool to use your own Amazon SES configuration for sending email messages."

如果您收到此错误,则表示您已超出 Amazon Cognito 默认电子邮件配置配额

要解决此问题,请将您的用户池配置为使用您自己的 Amazon SES 配置来发送电子邮件。这会增加您的 Amazon SES 发送配额

相关信息

为什么 Amazon Cognito 不使用 ForgotPassword API 发送验证码电子邮件或短信?

AWS 官方已更新 5 个月前