This is what worked for me. So if someone knows a better answer please point me. Sending a link selecting the "link" option didn't work for me.
So I tried adding the link manually in the body selecting the "code" option. But that didn't work at the start either as @SomnathRokade and @snehanshu.js suggested.
This is my lambda function.
exports.handler = async (event, context) => {
var welcomeMessage = `
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>Dear ${event.userName},</p>
<p>Anything</p>
<p>Any text before the link <a href="http://localhost:3000/changePassword?username=${event.userName}">here.</a> Your username is your Network Rail email address. Your temporary password is ${event.request.codeParameter}.</p>
<p>Any text</p>
<p>Any other text</p>
<p>Many Thanks </p>
</body>
</html>
`;
if (event.triggerSource === "CustomMessage_AdminCreateUser") {
event.response.emailSubject = "CAT Welcome Email";
event.response.emailMessage = welcomeMessage;
}
return context.done(null,event);
};
This DID NOT work.
I googled and found different places referring to "event.request.userName", "event.request.userAttributes.sub" etc instead of "event.userName". But they didn't work either.
Then I tried printing the event object in lambda console logs. I found the value for all of the above fields were same. Interestingly there was no "event.request.userName" field in the object. Instead there was "event.request.usernameParameter". Still, the value was the same as "event.userName". Anyway, I tried adding "event.request.usernameParameter" and surprisingly it worked.
After all, I found this doc explaining it.
So the bottom line is use "Code" option with having "event.request.usernameParameter" and "event.request.codeParameter" in the email body. It worked.
Hope I helped somebody.