Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for custom Lambda function email senders in Auth construct #2087

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

vigy02
Copy link

@vigy02 vigy02 commented Oct 7, 2024

Problem

This PR addresses the need for more flexible email sender configuration in the Auth construct, specifically allowing the use of custom Lambda functions for email sending capabilities.

Changes

  • Added support for using Lambda functions as email senders in the Auth construct
  • Implemented KMS key management for custom email senders
  • Updated types and interfaces to accommodate new email sender options
  • Added new test case for custom email sender functionality
  • Modified existing code to handle Lambda function email senders, including permission setup

Validation

A new test case was added in construct.test.ts to verify the behavior when a function is provided as an email sender. This test ensures that the custom email sender is properly set up when a Lambda function is provided.

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.

@vigy02 vigy02 requested review from a team as code owners October 7, 2024 21:08
Copy link

changeset-bot bot commented Oct 7, 2024

🦋 Changeset detected

Latest commit: eb24c3e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/auth-construct Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -421,7 +425,10 @@ export type AuthProps = {
* SES configurations enable the use of customized email sender addresses and names
* @see https://docs.amplify.aws/react/build-a-backend/auth/moving-to-production/#email
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will probably want to update this docs section with the parts that I left out when initially implementing senders --
this was the full docs message:
Configure Cognito to send emails from SES or a custom message trigger
SES configurations enable the use of customized email sender addresses and names
Custom message triggers enable the use of third-party email providers when sending email notifications to users
@see https://docs.amplify.aws/react/build-a-backend/auth/moving-to-production/#email
@see https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-email-sender.html

@@ -47,7 +49,7 @@ export type AuthProps = {
externalProviders?: ExternalProviderOptions;
};
senders?: {
email: Pick<UserPoolSESOptions, 'fromEmail' | 'fromName' | 'replyTo'>;
email: Pick<UserPoolSESOptions, 'fromEmail' | 'fromName' | 'replyTo'> | IFunction | AmplifyFunction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AmplifyFunction should be an input to defineAuth not to the construct.

There are couple of examples is backend-data that may be looked at.
For example, take a look how these two are handled

  1. function: ConstructFactory<AmplifyFunction>;
  2. functions?: Record<string, ConstructFactory<AmplifyFunction>>;

It should be that

const someFunction = defineFunction();
const auth = defineAuth({ senders: { email: someFunction });

under the hood. the auth construct factory should resolve the reference to IFunction (see how data does this under the hood) and pass it to auth construct as IFunction.

props.senders?.email &&
props.senders.email instanceof lambda.Function
) {
if (!this.customSenderKmsKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this have to be an instance variable?

) {
if (!this.customSenderKmsKey) {
this.customSenderKmsKey = new Key(this, 'CustomSenderKey', {
description: 'KMS key for Cognito custom sender',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please include user pool name (or some other identifier) in the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants