By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Lambda Init failure with "NameError: name 'long' is not defined"

0

Lamba init fails with following error:

[ERROR] NameError: name 'long' is not defined
Traceback (most recent call last):
  File "/var/lang/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/var/task/lambda_function.py", line 3, in <module>
    import boto3, os
  File "/var/lang/lib/python3.12/site-packages/boto3/__init__.py", line 17, in <module>
    from boto3.session import Session
  File "/var/lang/lib/python3.12/site-packages/boto3/session.py", line 17, in <module>
    import botocore.session
  File "/var/lang/lib/python3.12/site-packages/botocore/session.py", line 26, in <module>
    import botocore.client
  File "/var/lang/lib/python3.12/site-packages/botocore/client.py", line 16, in <module>
    from botocore.args import ClientArgsCreator
  File "/var/lang/lib/python3.12/site-packages/botocore/args.py", line 26, in <module>
    from botocore.config import Config
  File "/var/lang/lib/python3.12/site-packages/botocore/config.py", line 16, in <module>
    from botocore.endpoint import DEFAULT_TIMEOUT, MAX_POOL_CONNECTIONS
  File "/var/lang/lib/python3.12/site-packages/botocore/endpoint.py", line 20, in <module>
    import uuid
  File "/opt/python/lib/python3.12/site-packages/uuid.py", line 473, in <module>
    NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
  File "/opt/python/lib/python3.12/site-packages/uuid.py", line 128, in __init__
    int = long(hex, 16)

Portions of Lambda import are:

import requests
import json
import boto3, os
from botocore.exceptions import BotoCoreError, ClientError
<snip>

Intent is to use the SQS client, read message and delete message in Lambda function. With the init failure, am not able to read message and process it in Lambda. Help in resolving this is much appreciated

I've included a layer that has requests package needed for some functionality in lambda

asked 5 months ago395 views
1 Answer
0

Hello.

There appears to be no problem with the module import part.
The problem is probably somewhere else, so could you please share the entire code?

By the way, the error message says:
I think Python3 needs to use "int" instead of "long".
You probably have the following part in your code, so try changing long to int.
https://docs.python.org/3/whatsnew/3.0.html#integers

int = long(hex, 16)

Try changing it as below.

int = int(hex, 16)
profile picture
EXPERT
answered 5 months ago
profile picture
EXPERT
reviewed 5 months ago
  • It appears that way due to the presence of uuid.py in layers. post creating a new layer without uuid.py, which has only requests and other dependent packages, I do not see the above error. However, associating the layer with lambda function is not helping achieve the desired aspect - using requests within lambda. I get the following error:

    [ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'requests'
    Traceback (most recent call last):
    

    My intent, after reading the message from SQS is to package the message and invoke an external REST API using requests method.

  • If you just use the "requests" module, you can create it by following the steps in the document below. I created a layer for the "requests" module in my AWS account and no errors occurred. Is there any problem with the layer creation method? Please try using CloudShell etc. when creating layers. https://docs.aws.amazon.com/lambda/latest/dg/python-layers.html

    When creating a layer, it must be created using the same version of Lambda's Python.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions