I have a Lambda@Edge function that will fire when a user connects to my website to perform authentication, which is controlled by a CloudFront distribution I've setup for my website.
I want to develop this code locally so I setup a dummy HelloWorld project using AWS SAM CLI and replaced its source code with my lambda@edge function. I've also created a JSON file that represents the event that will be passed to my lambda function during sam local
invocation or when I run tests, placed under the "event" directory under my project folder.
I am able to run unit tests via npm run test
and have it both fail and pass so I know the code base is working. However, when I try to invoke it using sam local invoke -e events/sample_event.json
, I get the following error:
UnicodeEncodeError: 'latin-1' codec can't encode character '\ufeff' in position 0: Body ('\ufeff') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
The traceback shows this error was emitted from a Python 3 HTTP client:
/usr/local/Cellar/python@3.8/3.8.6_2/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py
Does anyone know why this encoding error is being emitted? I've used converters to ensure the contents of the event JSON file conform to utf-8 format. I can't understand why this is happening and what I should do to remedy it. Any suggestions are welcomed.