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?

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠