I have attached an Appsync pipeline resolver to a field called paymentStatus
in my Organisation
object. The idea is that if an organisations last pay day has passed, I want to fetch the payment status from an external API using a Lambda function. If the pay day has not passed, I do not want to invoke the function but simply return a "OK".
Is there any way I can conditionally invoke a Lambda function? Something like this:
#if ($ctx.source.payday < $util.time.nowEpochSeconds())
{
"version": "2017-02-28",
"operation": "Invoke",
"payload": {
"arguments": {
"orgID": "$ctx.source.id"
}
}
}
#end
If I run this, Appsync complains about operation
attribute missing when the condition is not met. I have also noted that the condition
attribute which exists for queries is not available for Lambda datasources.
Thank you in advance <3
You can use the #return
directive inside the request mapping template to return early from the template effectively returning early from the unit resolver.
Your request mapping template can look like this:
#if ($ctx.source.payday >= $util.time.nowEpochSeconds())
#set($result = "OK")
#return($result)
#end
{
"version": "2017-02-28",
"operation": "Invoke",
"payload": {
"arguments": {
"orgID": "$ctx.source.id"
}
}
}
For more details you can read https://docs.aws.amazon.com/appsync/latest/devguide/resolver-util-reference.html#aws-appsync-directives
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With