Skip to content

Update Custom Message Trigger Template Documentation with AdminCreateUser Specifics #8314

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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:

<Callout>
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.
</Callout>

{/* spell-checker: disable */}
```ts title="amplify/auth/custom-message/handler.ts"
import type { CustomMessageTriggerHandler } from "aws-lambda";
Expand All @@ -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"
Expand Down