Unable to perform OpenSearch text queries from Gremlin using AWS Lambda written in Javascript
I am syncing my AWS Neptune nodes in an AWS OpenSearch cluster as per the documentation https://docs.aws.amazon.com/neptune/latest/userguide/full-text-search.html. The name of the OpenSearch index is amazon_neptune. The OpenSearch index type is _doc. Following is the index configuration
```
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"analysis": {
"normalizer": {
"useLowercase": {
"type": "custom",
"filter": "lowercase"
}
}
}
},
"mappings": {
"properties": {
"document_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"entity_id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"entity_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"predicates": {
"properties": {
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above" : 1000,
"normalizer": "useLowercase"
}
}
},
"visibilityType": { "type": "keyword" },
"status": { "type": "keyword" },
"type": { "type": "keyword" },
"firstName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "useLowercase"
}
}
},
"lastName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"normalizer": "useLowercase",
"ignore_above" : 1000
}
}
}
}
}
}
}
}
```
Using the npm gremlin package, I'm trying to query my documents. Following is the code:
```
'use strict';
const gremlin = require('gremlin');
exports.handler = async (event, context) => {
try {
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const Graph = gremlin.structure.Graph;
const dc = new DriverRemoteConnection(<neptune_endpoint>,{});
const graph = new Graph();
const dbClient = graph.traversal().withRemote(dc);
const res = await dbClient
.withSideEffect("Neptune#fts.endpoint",<https_opensearch_endpoint>)
.withSideEffect('Neptune#fts.queryType', 'term')
.V().has("visibilityType","Neptune#fts PUBLIC")
.toList();
console.log('res:', res);
} catch(err) {
console.error('Failed to query', err);
}
}
```
But I'm getting the following error
```
Failed to query ResponseError: Server error: {"detailedMessage":"method [POST], host [<https_opensearch_endpoint>], URI [/amazon_neptune/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=query_then_fetch&batched_reduce_size=512&ccs_minimize_roundtrips=true], status line [HTTP/1.1 403 Forbidden]\n{\"Message\":\"User: anonymous is not authorized to perform: es:ESHttpPost\"}","requestId":"23a9e7d7-7dde-465b-bf29-9c59cff12e86","code":"BadRequestException"} (500)
```
I have given the following permission to my lambda
```
Type: AWS::IAM::Policy
Properties:
PolicyName: <Policy_Name>
Roles:
- 'Ref': <lambda_role>
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- es:ESHttpGet
- es:ESHttpPost
- es:ESHttpPut
- es:ESHttpDelete
Resource: <opensearch_cluster_arn>
```
My OpenSearch cluster as well as Neptune cluster are located inside the same VPC. My lambda is hosted inside the same VPC as well.
Please help me in understanding why I'm getting the 403 error when I've given the proper reading permissions to my lambda.
Any help would be highly appreciated.