youtype / awscliv2

Wrapper for dockerized AWS CLI v2
https://youtype.github.io/awscliv2/
MIT License
33 stars 5 forks source link

[BUG] awscliv2 as Lambda layer - Installation failed: mkdir: cannot create directory: Read-only file system #45

Open skhelishalnev opened 3 weeks ago

skhelishalnev commented 3 weeks ago

Describe the bug Hello dear awscliv2 team!

I'm trying to use your wrapper as a python module for python lambda function (runtime version 3.12) packaged as lambda layer. However when I try to install the binaries I'm getting the awscliv2.exceptions.InstallError: Installation failed: mkdir: cannot create directory '/home/sbx_user1051': Read-only file system. I understand that lambda runtime environment is read-only, just thought maybe theres a known workaround. I would really appreciate any help with this.

To Reproduce Steps to reproduce the behavior:

  1. Install 'awscliv2' in venv and package for lambda layer
  2. Inside lambda import the module from layer and exec install_multiplatform
from awscliv2.installers import install_multiplatform

install_multiplatform()
  1. Actual behavior
488, in _call_with_frames_removed
File "/var/task/lambda_function.py", line 17, in <module>
install_multiplatform()
File "/opt/python/lib/python3.12/site-packages/awscliv2/installers.py", line 125, in install_multiplatform
return install_linux_x86_64()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/python/lib/python3.12/site-packages/awscliv2/installers.py", line 63, in install_linux_x86_64
install_linux(LINUX_X86_64_URL)
File "/opt/python/lib/python3.12/site-packages/awscliv2/installers.py", line 109, in install_linux
raise InstallError(f"Installation failed: {output.getvalue()}")
awscliv2.exceptions.InstallError: Installation failed: mkdir: cannot create directory '/home/sbx_user1051': Read-only file system
INIT_REPORT Init Duration: 3246.78 ms   Phase: init Status: error   Error Type: Runtime.ExitError
20:25:45 - awscliv2 - INFO - Installing AWS CLI v2 for Linux
[INFO]  2024-08-19T20:25:45.443Z        Installing AWS CLI v2 for Linux
20:25:45 - awscliv2 - INFO - Downloading package from https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip to /tmp/tmpk4u3wco7.zip
[INFO]  2024-08-19T20:25:45.444Z        Downloading package from https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip to /tmp/tmpk4u3wco7.zip
[INFO]  2024-08-19T20:25:48.162Z        Extracting /tmp/tmpk4u3wco7.zip to to /tmp/tmpzuix7uz5
20:25:48 - awscliv2 - INFO - Extracting /tmp/tmpk4u3wco7.zip to to /tmp/tmpzuix7uz5
[INFO]  2024-08-19T20:26:10.904Z        Installing /tmp/tmpzuix7uz5/aws/install to /home/sbx_user1051/.awscliv2
20:26:10 - awscliv2 - INFO - Installing /tmp/tmpzuix7uz5/aws/install to /home/sbx_user1051/.awscliv2
Traceback (most recent call last):
File "/var/runtime/bootstrap.py", line 63, in <module>
main()
File "/var/runtime/bootstrap.py", line 60, in main
awslambdaricmain.main([os.environ["LAMBDA_TASK_ROOT"], os.environ["_HANDLER"]])
File "/var/lang/lib/python3.12/site-packages/awslambdaric/__main__.py", line 21, in main
bootstrap.run(app_root, handler, lambda_runtime_api_addr)
File "/var/lang/lib/python3.12/site-packages/awslambdaric/bootstrap.py", line 471, in run
request_handler = _get_handler(handler)
^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/awslambdaric/bootstrap.py", line 51, in _get_handler
m = importlib.import_module(modname.replace("/", "."))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 17, in <module>
install_multiplatform()
File "/opt/python/lib/python3.12/site-packages/awscliv2/installers.py", line 125, in install_multiplatform
return install_linux_x86_64()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/python/lib/python3.12/site-packages/awscliv2/installers.py", line 63, in install_linux_x86_64
install_linux(LINUX_X86_64_URL)
File "/opt/python/lib/python3.12/site-packages/awscliv2/installers.py", line 109, in install_linux
raise InstallError(f"Installation failed: {output.getvalue()}")
awscliv2.exceptions.InstallError: Installation failed: mkdir: cannot create directory '/home/sbx_user1051': Read-only file system
INIT_REPORT Init Duration: 42274.96 ms  Phase: invoke   Status: error   Error Type: Runtime.ExitError

Expected behavior

OS binary is installed and available for aws_api.execute()

Additional context AWS Lambda python runtime 3.12 (x86_64)

skhelishalnev commented 3 weeks ago

This seems did the trick

os.environ["HOME"] = "/tmp/sbx_user1051"

But not sure if its a good solution...

vemel commented 3 weeks ago

Hello! Thank you for the report.

This is strage, install path should be /home/sbx_user1051/.awscliv2.

Could you try creating this directory manually: mkdir /home/sbx_user1051/.awscliv2. If it does not work - then try changing permissions for the current user chown -hvR sbx_user1051 /home/sbx_user1051

Let me know if this helps.