From 7533b2b0dc0a6adf2232b0f21db3abfa8a097ce1 Mon Sep 17 00:00:00 2001 From: James Jarvis Date: Tue, 8 Apr 2025 17:09:43 -0700 Subject: [PATCH] docs: update custom message with admincreateuser specifics --- .../functions/examples/custom-message/index.mdx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/functions/examples/custom-message/index.mdx b/src/pages/[platform]/build-a-backend/functions/examples/custom-message/index.mdx index a1f562126f2..0a8f0e9227f 100644 --- a/src/pages/[platform]/build-a-backend/functions/examples/custom-message/index.mdx +++ b/src/pages/[platform]/build-a-backend/functions/examples/custom-message/index.mdx @@ -38,7 +38,7 @@ npm add --save-dev @types/aws-lambda ``` -Next, create a new directory and a resource file, `amplify/auth/custom-message/resource.ts`. Then, define the function with defineFunction: +Next, create a new directory and a resource file, `amplify/auth/custom-message/resource.ts`. Then, define the function with `defineFunction`: ```ts title="amplify/auth/custom-message/resource.ts" import { defineFunction } from '@aws-amplify/backend'; @@ -51,6 +51,10 @@ export const customMessage = defineFunction({ Next, create the corresponding handler file, `amplify/auth/custom-message/handler.ts`, file with the following contents: + +The input event for the `CustomMessage_AdminCreateUser` trigger source includes both a username and verification code. Admin-created users must receive both their username and code in order to sign in and thus you must include both the `usernameParameter` and `codeParameter` in your message template. + + {/* spell-checker: disable */} ```ts title="amplify/auth/custom-message/handler.ts" import type { CustomMessageTriggerHandler } from "aws-lambda"; @@ -67,12 +71,19 @@ export const handler: CustomMessageTriggerHandler = async (event) => { } } + if (event.triggerSource === "CustomMessage_AdminCreateUser") { + event.response.emailMessage = `Your username is ${event.request.usernameParameter} and your temporary password is ${event.request.codeParameter}`; + event.response.emailSubject = 'Welcome to Example App'; + } + return event; }; ``` {/* spellchecker: enable */} + + Lastly, set the newly created function resource on your auth resource: ```ts title="amplify/auth/resource.ts"