Home > Back-end >  AWS SNS or SES for password reset
AWS SNS or SES for password reset

Time:01-03

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();

CodePudding user response:

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.

CodePudding user response:

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

  • Related