How do I compose a BULK request to OpenSearch via AppSync resolver mapping templates?

0

I have a pipeline resolver for an AppSync Mutation. It contains two functions, the first one is a Lambda sending updates to RDS, the second one should take the result from $ctx.prev.result and index it via OpenSearch datasource.

In the request resolver mapping template of the second one, I am composing the bulk body in NDJSON similar to the following mannar:

#set($bulk = $util.toJson({ "index": { "_id": "${$ctx.prev.result.id}" } }))
#set($bulk = "${bulk}
${util.toJson($ctx.prev.result)}")

{
  "version": "2017-02-28",
  "operation": "POST",
  "path": "/_bulk",
  "params": {
    "body": $util.toJson($bulk)
  }
}

Lacking proper debugging tools, I have been using $util.error as a logging method to get my $bulk contents. And it looks like the following format, which seems correct.

{"index":{"_id":"A8DEF210-C342-48CB-9A4A-DA7D1E4D6AF1"}}
{"foo":123,"bar":999,"baz":1234567}

But when I actually runs the mutation via AppSync, I got a MappingTemplate error Unable to transform for the body: $[params][body]. and I have no idea why.

EDIT: I took a look at [re:Post] Appsync HTTP resolver supported content types, which inspired me to take another look at Resolver Mappping Template for OpenSearch (params). It seems POST body only accepts a single JSON object, NSJSON required by the bulk request is not supported yet. Am I correct?

If so, is supporting the bulk API in the upcoming plans?

Also, what is the currently recommended way to index multiple "normalized" documents from the same resolver?

vicary
已提问 2 年前132 查看次数
没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则