当我试图在VTL响应模板中返回一个#foreach循环时,即使我有116个条目,它也不会返回超过101个。为了进行测试,我创建了两个字段items和itemCount,并运行相同的ES查询。
items的VTL响应映射
[
#foreach($entry in $context.result)
#if( $velocityCount > 1 ) , #end
$util.toJson($entry.get("_source"))
#end
]itemCount的VTL响应映射
$context.result.size()看起来,appsync (引用:http://people.apache.org/~henning/velocity/html/ch05s04.html)对foreach循环设置了一个限制。
发布于 2018-04-10 19:14:03
我们刚刚将这个限制更新为1000,这是在AppSync限制页中更新的。
发布于 2022-02-25 05:10:47
绕过AppSync和arbitrary设置的任意速度AppSync限制的一种方法是通过在1000桶中进行分区来分解foreach循环。下面是一个有用的例子:
## Partition to get around foreach iteration limit
#set($partition_size = 1000)
#set($max_partition_index = $list.size()/$partition_size)
#foreach($partition_index in [0..$max_partition_index])
#set($start_index = $partition_index * $partition_size)
#if($partition_index == $max_partition_index)
## Last partition
#set($end_index = $list.size() - 1)
#else
#set($end_index = (($partition_index + 1) * $partition_size) - 1)
#end
#foreach($index in [$start_index..$end_index])
#if($index != 0),#end
"$list[$index].S"
#end
#endhttps://stackoverflow.com/questions/49674301
复制相似问题