- Newest
- Most votes
- Most comments
It appears that the original exception is thrown because of an issue in the error handling code. This hid the root cause of the problem, being emoji / utf-16 constructs in the source data. I could only find this out after commenting out the erroneous code in the exception handler (which was hidden in a lambda layer, so pretty difficult to find and change).
I changed the following code in the NeptuneStreamPollerLambda to resolve this particular error.
# opensearchpy/client/actions.py line 123
cur_size += len(data.encode("utf-8")) + 1
# change to
cur_size += len(data.encode("utf-8", errors="surrogatepass")) + 1
I believe the string causing this error was "Kan Boer Ayoub tractor 🚜 pulling winnen? | Motor Maniacs", though I suspect any string with an emoji in it could cause this issue.
answered 8 months ago
This is indeed a bug in the Neptune-to-OpenSearch replication Lambda function where there's a reference to es_helper that isn't imported in the replication_handler.py file.
For a short-term workaround, you have a few options:
- Create a custom Lambda layer with the fixed code:
- Download the neptune-streams-layer.zip from the S3 bucket
- Extract it and add the missing import statement for es_helper in replication_handler.py
- Repackage the layer and upload it to your own S3 bucket
- Modify the CloudFormation template to use your custom layer instead
- Modify the Lambda function directly:
- After deployment, go to the Lambda console
- Edit the function code to add the missing import statement
- Save the changes
- Use a custom Lambda function implementation:
- When creating the CloudFormation stack, specify your own S3 bucket and key for the Lambda code artifacts
- Ensure your implementation includes the proper imports
When implementing the fix, you'll need to add an import statement for es_helper at the top of the replication_handler.py file.
For the Lambda runtime, you can choose either Python 3.9 or Java 8 when setting up the CloudFormation stack, so you might consider using Java 8 as an alternative if the Python implementation continues to cause issues.
Note that when using the Neptune-to-OpenSearch replication, there are some limitations to be aware of, such as blank nodes not being replicated, and if you have fine-grained access control on your OpenSearch cluster, you'll need to enable IAM authentication in your Neptune database as well.
Sources
Neptune exporter tool to S3 running on Windows EC2 | AWS re:Post
Lambda layer: "Unable to import module: No module named 'opensearchpy'" | AWS re:Post
Full text search in Amazon Neptune using Amazon OpenSearch Service - Amazon Neptune
Using an AWS CloudFormation template to start Neptune-to-OpenSearch replication - Amazon Neptune
answered 9 months ago
Relevant content
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago

Do you have the ability to open a support case? We would likely need to obtain more info from you regarding your deployment. This poller is widely used and this is the first time I've seen this particular error. Are you deploying this using the CFN template from our docs - https://docs.aws.amazon.com/neptune/latest/userguide/full-text-search-cfn-create.html?
I do not have the ability to open one now in this particular account until I start a trial / subscription for technical support. I can ask in my org what the options are here. I did indeed create it using that guide, I am using eu-west-1, I notice I copied the wrong S3 url as I wanted to see if there would be any difference in the us-east-1 bucket.
Something else that is strange is that I do believe that it started out fine. There are 3,087 searchable documents in the cluster. Maybe I should try to redeploy it again.
I have disabled some of the error handling in the layer which depended on ES specific code to just format an error with the ES endpoint name, which is not interesting to know anyway in my opinion. The underlying error came up and specified: [ERROR] UnicodeEncodeError: 'utf-8' codec can't encode characters in position 1999-2000: surrogates not allowed
After some more debugging, I believe the indexer is breaking on emojis. In
opensearchpy/helpers/actions.pyI have replaced line 123 withcur_size += len(data.encode("utf-8", errors="surrogatepass")) + 1I believe the sync is now working. Will update progress here.