reactjs - 是否可以使用 AppSync VTL 使用 BatchPutItem (BatchWriteItem) 在 DynamoDB 上插入超过 25 个项目?
问题描述
仅针对某些情况:当前使用 AppSync + React + Apollo,我正在尝试通过 AppSync 的 Apache VTL 发送 38 - 40 个要更新的项目。
我知道 DynamoDB 将每个请求插入的项目数限制为 25,但我认为 AppSync 没有这些限制。我猜我错了,因为每当我发送超过 25 个项目(26+)时,我的请求都会失败。
这是我的 VTL 脚本:
#set($isTenantValid = false)
#foreach($tenant in $context.identity.claims["https://app.schon.io/tenants"])
#if($tenant == $ctx.args.tenantId)
#set($isTenantValid = true)
#end
#end
## Needs to verify if the employee has permission to insert students.
#if(!$isTenantValid)
$utils.unauthorized()
#end
#set($itemsToPut=[])
#set($pk="tenant:${ctx.args.tenantId}")
#set($userSK="tenant:${ctx.args.tenantId}:school-year:${ctx.args.schoolYear}")
#foreach($student in $ctx.args.students)
#set($studentId = "${util.autoId()}")
#set($sk="school-year:${ctx.args.schoolYear}:student:${studentId}")
#set($userPK="student:${studentId}")
#set($item = {
"pk": $pk,
"sk": $sk,
"id": $studentId,
"userPK": $userPK,
"userSK": $userSK,
"name": {
"firstName" : $student.name.firstName,
"lastName" : $student.name.lastName,
"fullName": "${student.name.firstName} ${student.name.lastName}"
},
"schoolYear": $ctx.args.schoolYear,
"createdAt": ${util.time.nowEpochSeconds()},
"updatedAt": ${util.time.nowEpochSeconds()},
"gender": $student.gender,
"retired": $student.retired
})
#if("${student.diseases}" != "")
$util.qr($item.add("diseases", $student.diseases))
#end
#if("${student.email}" != "")
$util.qr($item.add("email", $student.email))
#end
#if("${student.birthdate}" != "")
$util.qr($item.add("birthdate", $student.birthdate))
#end
$util.qr($itemsToPut.add($util.dynamodb.toMapValues($item)))
#end
{
"version" : "2018-05-29",
"operation" : "BatchPutItem",
"tables" : {
"SchonDB": $utils.toJson($itemsToPut)
}
}
在这种情况下,我是否需要将其卸载到 Lambda 并为每 25 个项目执行发送和重试逻辑?
解决方案
您可以尝试联系 DDB 团队为您增加服务限制吗?
推荐阅读
- c# - 在非管理员帐户下运行自托管 OWIN 网站
- c - Static 在声明字符数组时有什么用?
- java - 使用时区解析日期
- python - Docker Compose 和 Django 生成器语法错误
- javascript - 这些 JavaScript 颜色代码是什么意思?
- ios - 如何在 Swift iOS 中同时使用 UITableView 和 NSLink?
- service-worker - 手动重放由 workbox-background-sync 排队的请求
- canvas - 如何等到画布完成重新渲染?
- autodesk-forge - 有什么方法可以伪造,在pdf中放置大头针并绘制边界
- python - Python线程参数问题