How do I compose a BULK request to OpenSearch via AppSync resolver mapping templates?
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?
Relevant questions
AppSync request mapping template errors not logged in CloudWatch
asked 2 months agoAppsync HTTP resolver supported content types
asked 3 years agoAppsync resolver conditional update of AWSJSON attribute
Accepted Answerasked 3 years agopipeline response resolvers
asked a month agoIST time in AWS appsync pipeline resolver function
Accepted Answerasked 4 months agoAppSync error: Communication error while executing a request to OpenSearch
asked 6 months agoHow do I compose a BULK request to OpenSearch via AppSync resolver mapping templates?
asked 3 months agoAppSync resolver size limits
Accepted Answerasked 3 years agoHow do we use build-in velocity tools inside resolvers?
asked 3 years agoAccess "aud" claim in resolver mapping for AWS AppSync
Accepted Answerasked 3 months ago