Can I use my own function

When deploying a function in the Cloud, can I use functions that I have defined myself.
Like in this example:

form=FormFunction[{“x”->“Number”,“y”->“Number”},
(AddTwoNumbers[<|“x”->x_,“y”->y_|>]:=x+y;
AddTwoNumbers[#])&]

CloudDeploy[form]

The immediatet answer based on experience is that I cannot - but why, and what to do instead?

Yes, you can. There’s a couple of things wrong here though.

You can’t define a function like this:

AddTwoNumbers[<|"x"->x,"y"->y|>]:=x+y;

Associations are atomic, so don’t use them in pattern matching.

The values of x and y will be represented by #x and #y. Here is the code I would use:

addTwoNumbers[x_, y_] := x + y
form = FormFunction[{"x" -> "Number", "y" -> "Number"}, addTwoNumbers[#x, #y] &]
CloudDeploy[form, Permissions -> "Public"]