跳至内容

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

2 分钟阅读
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 中验证您的域身份和电子邮件地址。

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

完成以下步骤:

  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 沙盒账户向未验证的电子邮件地址发送电子邮件,则可能会收到以下错误消息:

"Email address is not verified.The following identities failed the check in region AP-SOUTHEAST-1: user@example.com."

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

缺少电子邮件

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

describe-user-pool 命令示例:

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

输出示例 1:

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

输出示例 2:

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

如果 EmailSendingAccount 为 DEVELOPER,则表示您的用户池使用 Amazon SES 发送电子邮件。您还可以查看 Amazon SES 日志,了解有关传输问题的更多信息。

如果 EmailSendingAccount 为 COGNITO_DEFAULT,则表示您的用户池使用 Amazon Cognito 的默认电子邮件功能发送电子邮件。此功能对每个用户池发送的电子邮件有配额限制,这可能会导致每日电子邮件配额错误。

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

如果您超出 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 SES 配置来发送电子邮件。此配置会增加您的 Amazon SES 发送配额。

相关信息

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

AWS 官方已更新 6 个月前