I’m trying to make this application communicate with my database, but it gives this error every time.
The error that is happening is this:
{
"errorMessage": "Unable to import module 'index': No module named 'mysql'",
"errorType": "Runtime.ImportModuleError",
"requestId": "e0fe9977-bd38-442f-ae20-e71284b2e1f1",
"stackTrace": []
}
I was hoping to run the JSON and send it to the database.
This is the JSON:
{
"Tensão": {
"isLosslessNumber": true,
"value": "127.5999985"
},
"Corrente": {
"isLosslessNumber": true,
"value": "0.02"
},
"Potência": {
"isLosslessNumber": true,
"value": "0"
},
"Energia Consumida": {
"isLosslessNumber": true,
"value": "0.189999998"
},
"Frequência": {
"isLosslessNumber": true,
"value": "59.90000153"
},
"Fator de Potência": {
"isLosslessNumber": true,
"value": "0"
}
}
2
Answers
Most likely all dependencies are not included in the code that is uploaded. AWS recommends
You are getting an
Unable to import module 'index'
: No module named ‘mysql’" error because the ‘mysql’ module is missing in your Lambda environment. To fix this, either include the ‘mysql’ library in your Lambda deployment package or use AWS Lambda Layers to attach the library as a separate layer.Including ‘mysql’ in the Lambda Deployment Package:
python
zip -r lambda_function.zip index.py mysql
Using AWS Lambda Layers: