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
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:
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.