2

I have a resolver pipeline where I check to see if an item exists. If it does not I want to start a lambda which will create the data. If the queried item exists already I want to return from the pipeline altogether without executing the lambda. It seems AWS provides the following solutions:

#return 

This only returns from the current request mapping template.

$util.error

This prevents subsequent functions from being executed by throwing an error immediately.

I want the functionality of $util.error without throwing an error but instead just returning the result from the current function. Is there a way to do this?

  • Do I understand correctly that you want to short-circuit the entire pipeline, while adding an error and specifying a result? – Zac Charles Apr 11 '22 at 16:43
  • 1
    I just want to return from the current resolver with an early result, without executing subsequent resolver functions. Effectively an early return from the entire pipeline. I don't want to throw an error but just the functionality of an error, ending the pipeline. – Martin Gressler Apr 13 '22 at 08:50
  • I don't think such functionality actually exists, but perhaps you could write something to $context.stash, and subsequent functions in the pipeline could check for that and #return early or perform a no-op in the case of a Lambda function. I don't know if this would work in every situation, though, and it's not very elegant. – Zac Charles Apr 14 '22 at 09:34
  • What I like about @MartinGressler's ask here is that it avoids having to manually override the auto-generated resolvers that Amplify gives you out of the box – gxc Dec 12 '22 at 07:25

0 Answers0