3
votes

Is it possible to do input validation with AWS AppSync without adding another "layer" of interaction?

I feel like adding a lambda function will defeat the purpose of it.

What I would like to accomplish is at least some regexp validation on strings.

And if not, then how do people that use AppSync or similar solutions (firebase) do so?

1

1 Answers

5
votes

If it's only regex validation without having to check the input against data in a data source, then you can prepend some validation logic inside the resolver request mapping template.

See below an example for checking if the input field matches is an email from the myvaliddomain.com. If it doesn't validate, we just abort and error the field.

#set($valid = $util.matches("^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+\.)?[a-zA-Z]+\.)?(myvaliddomain)\.com", $ctx.args.input))
#if (!$valid)
    $util.error("$ctx.args.input is not a valid email.", "ValidationError")
#end

## Rest of your request mapping template below