Skip to content
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