skip to Main Content

I am trying to run a simple program in AWS Lambda. However, it is failing with DEFAULT_CIPHERS error. When I run the following program it fails with error ...unable to import lambda function:

import json
import boto3
import os
import requests

def lambda_handler(event, context):
    file = '2011-02-12-0.json.gz'
    download_res = requests.get(f"https://data.gharchive.org/{file}")
    print(f"Files downloaded successfully - Filename: {file}")
    os.environ.setdefault('AWS_PROFILE', 'myid')
    s3 = boto3.client('s3')
    upload_res = s3.put_object(Bucket='my-demo-bucket3', Key=file, Body=download_res.content)
    print("Files Uploaded successfully")
    return upload_res

Error:

Response
{
  "errorMessage": "Unable to import module 'lambda_function': cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_' (/var/task/urllib3/util/ssl_.py)",
  "errorType": "Runtime.ImportModuleError",
  "requestId": "5d82baed-2ee6-41cd-a8e7-d24a59061dbc",
  "stackTrace": []
}

Can anyone please help me sort this out.
Thanks.

2

Answers


  1. The issue is in the versioning of the packages. The difference in these 2 codes that makes the problem is boto3. There’s an open issue on GitHub related to this.
    A solution, as several people wrote there would be to pin down the version of urllib3

    You can put something like this in your requirements.txt

    requests
    urllib3<2
    

    The second option is to pin down the requests package to 2.29.0, as 2 guys mentioned this fixed issue with their Lambda functions.

    To track the progress of this, you can check the issue in Github

    Login or Signup to reply.
  2. first try running this code locally and get it working locally.
    The error message you’re seeing indicates that there is a problem with importing the DEFAULT_CIPHERS attribute from the urllib3.util.ssl_ module in your Lambda function code. This issue could be caused by a few different factors. Here are a few steps you can take to troubleshoot and resolve the problem:

    1. Check the Python version: Ensure that you’re using a compatible Python version in your Lambda function. The DEFAULT_CIPHERS attribute might not be available in older Python versions. You can check the Python version in the Lambda runtime settings and make sure it meets the requirements of your code.

    2. Verify the module installation: Confirm that the required modules, including urllib3, are properly installed in your Lambda environment. If you’re using a deployment package, double-check that all the necessary dependencies are included.

    3. Update the module: It’s possible that the urllib3 module is outdated and doesn’t contain the DEFAULT_CIPHERS attribute. Try updating the module to the latest version or a version that is known to be compatible with your code. You can do this by including the updated module in your deployment package or by using a package manager like pip within your Lambda function.

    4. Review your code: Examine your Lambda function code to ensure that you’re importing the modules correctly. Check that the import statement is accurate, including the capitalization and spelling. It should be something like:

      from urllib3.util.ssl_ import DEFAULT_CIPHERS
      

      If you’re importing the module in a different way, make sure it is correct.

    5. Check for circular dependencies: Circular dependencies can sometimes cause import errors. Review your code and make sure there are no circular imports between your Lambda function code and the urllib3.util.ssl_ module or any other relevant modules.

    6. Consider environmental differences: If your code works locally but encounters issues in the Lambda environment, it’s possible that there are environmental differences causing the problem. Look for any discrepancies between your local development environment and the Lambda runtime environment that could be affecting the import.

    By following these steps, you should be able to identify and resolve the import error related to the DEFAULT_CIPHERS attribute in the urllib3.util.ssl_ module.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search