https://serverless-stack.com/ logo
#help
Title
# help
k

Kristian Lake

04/24/2022, 7:31 PM
hey guys, is there a way to set this from email address in the code? (cognito)
f

Frank

04/27/2022, 9:49 PM
Hey @Kristian Lake, you can set i up like this in V1 construct:
Copy code
new Auth(this, "Auth", {
  cdk: {
    userPool: {
      email: cognito.UserPoolEmail.withSES({
        fromEmail: '<mailto:noreply@myawesomeapp.com|noreply@myawesomeapp.com>',
        fromName: 'Awesome App',
        replyTo: '<mailto:support@myawesomeapp.com|support@myawesomeapp.com>',
      }),
  },
});
Oh sorry.. I mis-read ur msg. The snippet above uses SES to send out the verification email.
If you want to use Cognito to send it out, there isn’t a “high-level” friendly way of doing it. You’d need to grab the CloudFormation resource and configure it directly like this:
Copy code
const auth = new Auth(this, "Auth");

// Get the CloudFormation resource of the UserPool
const cfnUserPool = auth.cdk.userPool.node.defaultChild;

// Set raw CloudFormation settings for email
cfnUserPool.emailConfiguration = {
  configurationSet,
  emailSendingAccount,
  from,
  replyToEmailAddress,
  sourceArn,
};
You can read more about what each field takes in the CloudFormation doc for User Pool https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-emailconfiguration.html
Let me know if that makes sense.
k

Kristian Lake

05/01/2022, 10:29 AM
Thank you Frank. looking at this now! 🙂
only change was this // Get the CloudFormation resource of the UserPool const cfnUserPool = authStack.auth.cognitoUserPool.node.defaultChild; but now working thank you