skip to Main Content

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


  1. Most likely all dependencies are not included in the code that is uploaded. AWS recommends

    you add all of your function’s dependencies to your deployment
    package, even if versions of them are included in the Lambda runtime
    Refer: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-dependencies

    Login or Signup to reply.
  2. 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:

    • First, make sure you have the ‘mysql’ library installed locally (you can use pip install mysql-connector-python).
    • Next, create a ZIP file that includes your Lambda function code and the ‘mysql’ library by running a command similar to:
      python
      zip -r lambda_function.zip index.py mysql
    • Upload this ZIP file to AWS Lambda.

    Using AWS Lambda Layers:

    • First, create a ZIP file with the ‘mysql’ library only (e.g., mysql-layer.zip).
    • Create a new Lambda Layer by uploading the ZIP file to AWS Lambda Layers.
    • Add the created layer to your Lambda function in the AWS Lambda console.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search