AWS SNS或SES用于密码重置。

huangapple go评论85阅读模式
英文:

AWS SNS or SES for password reset

问题

大家好!我有一个任务,需要创建AWS Lambda端点来重置用户的密码。我需要将新密码发送到用户的电子邮件。我已经阅读了很多关于SNS和SES的信息,目前不知道哪个服务更适合我的目的。很高兴听到您的建议!

以下是我的Lambda代码:

        const requestData = AdminResetPasswordDto.from(event.body);
        const errors = await AdminResetPasswordDto.validate(requestData);
        if (errors) {
            return new BadRequestError({ message: "errors.invalid-request-params", errors })
        }

        const repo = new UsersRepo();
        
        const entity = await repo.getOneByEmail(requestData.email);
        if (!entity) {
            return new BadRequestError({ message: 'errors.user-not-exists' })
        }

        // const newPass = generatePassword();
        // 通过SNS将新密码发送给用户
        // 使用SNS还是SES???
        // https://docs.aws.amazon.com/sns/latest/dg/sns-email-notifications.html

        const user = UserDto.fromEntity(entity);
        const result = await repo.updateUserPassword(user.userId, user.userRole, newPass);
        if (!result) {
            return new BadRequestError({ message: 'errors.password-not-updated' })
        }

        return new ResponseSuccessNoBody();

希望对您有帮助!

英文:

guys! I have a task to create AWS lambda endpoint for resetting user's password. I have to send a new password to user's email. I have read a lot about SNS and SES and currently have no idea what service is better for my purpose. Will be glad to hear from you advice!

Here is my lambda code

        const requestData = AdminResetPasswordDto.from(event.body);
        const errors = await AdminResetPasswordDto.validate(requestData);
        if (errors) {
            return new BadRequestError({ message: "errors.invalid-request-params", errors })
        }

        const repo = new UsersRepo();
        
        const entity = await repo.getOneByEmail(requestData.email);
        if (!entity) {
            return new BadRequestError({ message: 'errors.user-not-exists' })
        }

        // const newPass = generatePassword();
        // sending newPass to user via SNS
        // use SNS or SES ???
        // https://docs.aws.amazon.com/sns/latest/dg/sns-email-notifications.html

        const user = UserDto.fromEntity(entity);
        const result = await repo.updateUserPassword(user.userId, user.userRole, newPass);
        if (!result) {
            return new BadRequestError({ message: 'errors.password-not-updated' })
        }

        return new ResponseSuccessNoBody();

答案1

得分: 0

SNS用于“技术”通知;可以通过电子邮件进行投递,但功能相对有限。首先,您需要创建专用的订阅并在此时提供目标邮件地址。其次,您无法真正“设计”您的消息,它将只是一块文本。如果接收者在运行时确定并且您希望对消息布局具有控制权,应该使用SES。

英文:

SNS is used for “technical” notifications; delivery as e-mail is possible, but rather limited. First, you need to create dedicated subscriptions and provide the destination mail address at this point. Second, you can’t really “design” your messages, it will just be a blob of text. You should go with SES for messages where the recipient is determined at runtime and you want to have control over the message layout.

答案2

得分: 0

SES 用于高效且安全地发送大量电子邮件。一旦您验证了自己是电子邮件地址的所有者,您就可以通过SES向任何其他电子邮件地址发送电子邮件,无需收件人的同意。SES负责确保交付其电子邮件所需的工程工作。

SNS 旨在作为渠道发布者/订阅者服务。为了从SNS接收电子邮件,终端用户必须首先通过电子邮件订阅并批准该订阅,然后亚马逊才会将订阅的渠道的电子邮件传送给终端用户。终端用户可以通过电子邮件、短信、Webhook和其他方式进行订阅,与发布者无关。

在实际操作中,我们使用SES向用户发送与其内容相关的电子邮件,使用SNS在服务器出现故障或问题时向开发人员发送通知(通过短信和电子邮件)。

简而言之,

SNS

  • 电子邮件消息
  • 短信
  • 推送通知到移动设备
  • 服务/应用程序之间的消息
  • 客户必须订阅以接收上述通知

SES

  • 电子邮件消息
  • 无需订阅
英文:

SES is meant for sending high-volume e-mail efficiently and securely. Once you have verified that you are the owner of an e-mail address, you can send e-mails through SES to any other e-mail address without the recipient's consent. SES takes care of the engineering required to ensure the delivery of their e-mails.

SNS is meant as a channel publisher/subscriber service. In order to receive e-mails from SNS, the end-user must first subscribe and approve that subscription through e-mail before amazon delivers e-mails from the subscribed channel to that end-user. End-users can subscribe via e-mail, SMS, webhooks, and other means up to the user independent of the publisher.

On a practical level, we use SES to send our users e-mails about their content and we use SNS to send our developers notifications (via SMS and e-mail) when servers go down or have issues.

In short,

SNS

  • email messages

  • SMS

  • push notifications to mobile device

  • messages between services/apps

  • Clients have to subscribe, to receive above notifications

SES

  • email messages

  • No subscriptions required

huangapple
  • 本文由 发表于 2023年1月3日 16:42:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/74990896.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定