Amazon web services 我可以有条件地调用AWS Appsync解析器中的lambda函数吗?

Amazon web services 我可以有条件地调用AWS Appsync解析器中的lambda函数吗?,amazon-web-services,aws-lambda,aws-appsync,Amazon Web Services,Aws Lambda,Aws Appsync,我已将Appsync管道解析器附加到我的组织对象中名为paymentStatus的字段。其思想是,如果最后一个支付日已经过去,我希望使用Lambda函数从外部API获取支付状态。如果还没有过发薪日,我不想调用函数,只想返回一个“OK” 有没有什么方法可以有条件地调用Lambda函数?大概是这样的: #if ($ctx.source.payday < $util.time.nowEpochSeconds()) { "version": "2017-02-28",

我已将Appsync管道解析器附加到我的
组织
对象中名为
paymentStatus
的字段。其思想是,如果最后一个支付日已经过去,我希望使用Lambda函数从外部API获取支付状态。如果还没有过发薪日,我不想调用函数,只想返回一个“OK”

有没有什么方法可以有条件地调用Lambda函数?大概是这样的:

#if ($ctx.source.payday < $util.time.nowEpochSeconds()) 
    {
        "version": "2017-02-28",
        "operation": "Invoke",
        "payload": {
            "arguments": {
                "orgID": "$ctx.source.id"
            }
        }
    }
#end
#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"
        }
    }
}
#if($ctx.source.payday<$util.time.nowEpochSeconds())
{
“版本”:“2017-02-28”,
“操作”:“调用”,
“有效载荷”:{
“论点”:{
“orgID”:“$ctx.source.id”
}
}
}
#结束
如果我运行此操作,Appsync会在不满足条件时抱怨缺少
操作
属性。我还注意到,用于查询的
条件
属性对于Lambda数据源不可用

提前感谢您可以使用请求映射模板中的
#return
指令从模板中提前返回,从而有效地从单元解析器中提前返回

您的请求映射模板可以如下所示:

#if ($ctx.source.payday < $util.time.nowEpochSeconds()) 
    {
        "version": "2017-02-28",
        "operation": "Invoke",
        "payload": {
            "arguments": {
                "orgID": "$ctx.source.id"
            }
        }
    }
#end
#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"
        }
    }
}

有关更多详细信息,请阅读

这听起来很神奇!我今天要试试这个,谢谢你!