Summary
When running on AWS Lambda the code crashes with a "Permission denied" error when using pyomo 6.10.1 in combination with an S3 client provided via boto3 (i.e. boto3.client("s3")).
This crash happens due to the use of multiprocessing.Lock() (introduced in #3957 for #3908), this requires shared memory (/dev/shm) but that is not available on AWS Lambda.
(I have not yet attempted to run pyomo 6.10.1 on AWS Lambda without using the s3 client, if needed I could but in practice that would not be a useful scenario for us.)
Steps to reproduce the issue
import pyomo.environ as pyo
import boto3
def lambda_handler(event, context):
# boto3.client('s3') imports s3transfer, which imports multiprocessing.
# This springs Pyomo's deferred import hook, attempting to create a multiprocessing.Lock
# which AWS Lambda immediately blocks.
client = boto3.client("s3")
return "Success"
Or without using boto3:
import pyomo.environ as pyo
def lambda_handler(event, context):
import multiprocessing
return "Success"
Error Message
Using boto3:
[ERROR] PermissionError: [Errno 13] Permission denied
Traceback (most recent call last):
File "/var/lang/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/var/task/src/handler2.py", line 2, in <module>
import boto3
File "/var/task/boto3/__init__.py", line 17, in <module>
from boto3.compat import _warn_deprecated_python
File "/var/task/boto3/compat.py", line 21, in <module>
from s3transfer.manager import TransferConfig
File "/var/task/s3transfer/__init__.py", line 144, in <module>
import s3transfer.compat
File "/var/task/s3transfer/compat.py", line 94, in <module>
from multiprocessing.managers import BaseManager # noqa: F401,E402
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/var/task/pyomo/common/dependencies.py", line 483, in exec_module
deferred.resolve()
File "/var/task/pyomo/common/dependencies.py", line 358, in resolve
self._module, self._available = _perform_import(
File "/var/task/pyomo/common/dependencies.py", line 798, in _perform_import
callback(module, True)
File "/var/task/pyomo/common/dependencies.py", line 979, in _finalize_multiprocessing
capture_output_lock = module.Lock()
File "/var/lang/lib/python3.10/multiprocessing/context.py", line 68, in Lock
return Lock(ctx=self.get_context())
File "/var/lang/lib/python3.10/multiprocessing/synchronize.py", line 162, in __init__
SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
File "/var/lang/lib/python3.10/multiprocessing/synchronize.py", line 57, in __init__
sl = self._semlock = _multiprocessing.SemLock(
Direct import:
[ERROR] PermissionError: [Errno 13] Permission denied
Traceback (most recent call last):
File "/var/task/src/handler3.py", line 5, in lambda_handler
import multiprocessing
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "/var/task/pyomo/common/dependencies.py", line 483, in exec_module
deferred.resolve()
File "/var/task/pyomo/common/dependencies.py", line 358, in resolve
self._module, self._available = _perform_import(
File "/var/task/pyomo/common/dependencies.py", line 798, in _perform_import
callback(module, True)
File "/var/task/pyomo/common/dependencies.py", line 979, in _finalize_multiprocessing
capture_output_lock = module.Lock()
File "/var/lang/lib/python3.10/multiprocessing/context.py", line 68, in Lock
return Lock(ctx=self.get_context())
File "/var/lang/lib/python3.10/multiprocessing/synchronize.py", line 162, in __init__
SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
File "/var/lang/lib/python3.10/multiprocessing/synchronize.py", line 57, in __init__
sl = self._semlock = _multiprocessing.SemLock(
Information on your system
Pyomo version: 6.10.1
Python version: 3.10
Operating system: AWS Lambda
How Pyomo was installed (PyPI, conda, source): PyPi
Other packages used:
- boto3: 1.43.31
- botocore: 1.43.31
- s3transfer: 0.19.0
Additional information
Testing the same setup with pyomo 6.10.0 works as expected.
Summary
When running on AWS Lambda the code crashes with a "Permission denied" error when using pyomo 6.10.1 in combination with an S3 client provided via boto3 (i.e.
boto3.client("s3")).This crash happens due to the use of
multiprocessing.Lock()(introduced in #3957 for #3908), this requires shared memory (/dev/shm) but that is not available on AWS Lambda.(I have not yet attempted to run pyomo 6.10.1 on AWS Lambda without using the s3 client, if needed I could but in practice that would not be a useful scenario for us.)
Steps to reproduce the issue
Or without using boto3:
Error Message
Using boto3:
Direct import:
Information on your system
Pyomo version: 6.10.1
Python version: 3.10
Operating system: AWS Lambda
How Pyomo was installed (PyPI, conda, source): PyPi
Other packages used:
Additional information
Testing the same setup with pyomo 6.10.0 works as expected.