- Newest
- Most votes
- Most comments
Hello robbe, I think what causes the error is that Lambda cannot find the module 'charset_normalizer'. I think you can solve it by creating a layer for you Lambda. Try to follow these steps:
- Go to pypi charset-normalizer download page: https://pypi.org/project/charset-normalizer/#files
- Download whl file for desired Python version x86_64. (e.g. charset_normalizer-3.0.1-cp311-cp311-musllinux_1_1_x86_64.whl). You need to check the compatible version of the package with the runtime of your lambda function.
- Create a folder with the name "python", don't use other names different than “python” because it won't work
- Move all the extracted files from whl to "python" folder.
- zip compress this "python" folder.
Now you can upload the zip file on Lambda to create the Layer by following these steps:
- Go to Lambda
- On the left side pane go to "Additional resources" -> "Layers"
- Click on "Create Layer" on the right
- Give your layer a name
- Upload the zip file you created
- In "Compatible architectures" choose x86_64
- In "Compatible runtimes" choose the code runtime you used in your lambda function
- Click on "Create"
Now you can add the Layer to your Lambda:
- Go to you Lambda function
- Scroll down to the bottom until you see the "Layers" banner
- Click on "Add a layer"
- Choose "Custom Layer"
- In the dropdown menu select the name of the layer you previously created
- In the "Version" dropdown menu select the version of the layer
- Click on "Add"
Now try to test your function again and see if the error is solved.
I attach this medium article that explains how to create pandas and numpy layer for Lambda, maybe it can be useful in case my answer is not clear: https://medium.com/@shimo164/lambda-layer-to-use-numpy-and-pandas-in-aws-lambda-function-8a0e040faa18
Hello robbe, sorry for my late response, what I understand from the error is that Lambda sees event['queryStringParameters'] as a list and tries to access element at position 'q' that throws an error since only integers can be used as indices in a list. Could you please add a print(event)
on the line before
query = {
"size": 25,
"query": {
"multi_match": {
"query": event['queryStringParameters']['q'],
"fields": ["title", "directors"]
}
}
}
and provide me the output so I can read what Lamdba gets as input and have a better understanding of the error?
Hi Gaia, thank you for your clear instructions. Simple clear answers like yours seem to be a rare thing on these aws forums at times.
This worked a treat for me when updating our lambda from the 3.7 python runtime to 3.11.
Relevant content
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
Thanks for the answer, i think my import errors are gone. Now i have this error when i test: "list indices must be integers or slices, not str", i have copied the code from the tutorial so i dont know what the error is. my code looks like this:
def lambda_handler(event, context):
The error is on this line: "query": event['queryStringParameters']['q']