No such file or directory: ‘/var/task/requirements.txt’ when using serverless-python-requirements plugin with dockerizePip

I am encountering an issue while trying to deploy my Serverless framework application using the serverless-python-requirements plugin with the following configuration:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>custom:
pythonRequirements:
dockerizePip: true
</code>
<code>custom: pythonRequirements: dockerizePip: true </code>
custom:
  pythonRequirements:
    dockerizePip: true

When I run the sls deploy command, I receive the following error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Serverless: Running docker run --rm -v /home/myuser/.cache/serverless-python-requirements/679f0c7a123e5d80212530da94d545f92ad890ecf43e8288e2b6bc243b4e138b_slspyc:/var/task:z lambci/lambda:build-python3.8 /bin/sh -c 'python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt && chown -R 0:0 /var/task && find /var/task -name *.so -exec strip {} ;'
Serverless: Stdout:
Serverless: Stderr: ERROR: Could not open requirements file: [Errno 2] No such file or directory: '/var/task/requirements.txt'
It seems like the requirements.txt file is not being found in the /var/task/ directory within the Docker container. I have verified that the requirements.txt file is present in my project directory.
</code>
<code>Serverless: Running docker run --rm -v /home/myuser/.cache/serverless-python-requirements/679f0c7a123e5d80212530da94d545f92ad890ecf43e8288e2b6bc243b4e138b_slspyc:/var/task:z lambci/lambda:build-python3.8 /bin/sh -c 'python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt && chown -R 0:0 /var/task && find /var/task -name *.so -exec strip {} ;' Serverless: Stdout: Serverless: Stderr: ERROR: Could not open requirements file: [Errno 2] No such file or directory: '/var/task/requirements.txt' It seems like the requirements.txt file is not being found in the /var/task/ directory within the Docker container. I have verified that the requirements.txt file is present in my project directory. </code>
Serverless: Running docker run --rm -v /home/myuser/.cache/serverless-python-requirements/679f0c7a123e5d80212530da94d545f92ad890ecf43e8288e2b6bc243b4e138b_slspyc:/var/task:z lambci/lambda:build-python3.8 /bin/sh -c 'python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt && chown -R 0:0 /var/task && find /var/task -name *.so -exec strip {} ;'
Serverless: Stdout:
Serverless: Stderr: ERROR: Could not open requirements file: [Errno 2] No such file or directory: '/var/task/requirements.txt'
It seems like the requirements.txt file is not being found in the /var/task/ directory within the Docker container. I have verified that the requirements.txt file is present in my project directory.

It seems like the requirements.txt file is not being found in the /var/task/ directory within the Docker container.

Has anyone faced this issue before, and how can I resolve it?

The error message indicates that the requirements.txt file is not being found in the Docker container at the expected location /var/task/. This is often due to permission issues with the default cache location.

Here are some steps to resolve this issue:

  1. Default Cache Directory: The serverless-python-requirements plugin writes dependencies to ~/.cache/serverless-python-requirements/... before mounting them in the Docker container with -v. If the user running the sls deploy command does not have the necessary permissions to access this cache directory, the /var/task directory in the container will be empty, causing the requirements.txt file to be missing. Note that Docker will not trigger an error if the volume source does not exist or lacks permissions.

  2. Change Cache Directory Permissions: Ensure that the user running the sls deploy command has the correct permissions to access the cache directory. See AWS Lambda troubleshooting documentation: https://docs.aws.amazon.com/lambda/latest/dg/troubleshooting-deployment.html

  3. Specify Custom Cache Location: If you cannot change the permissions, you can specify a different cache location where you have the necessary permissions using the cacheLocation option in your serverless.yml:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>custom:
pythonRequirements:
dockerizePip: true
cacheLocation: /path/to/mycacheLocation
</code>
<code>custom: pythonRequirements: dockerizePip: true cacheLocation: /path/to/mycacheLocation </code>
custom:
  pythonRequirements:
    dockerizePip: true
    cacheLocation: /path/to/mycacheLocation
  1. Disable Global Cache: Alternatively, you can disable the global cache using the useStaticCache option. This will make Docker bind directly to path/to/serverless/project/.serverless/requirements:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>custom:
pythonRequirements:
dockerizePip: true
useStaticCache: false
</code>
<code>custom: pythonRequirements: dockerizePip: true useStaticCache: false </code>
custom:
  pythonRequirements:
    dockerizePip: true
    useStaticCache: false
  1. CI/CD Pipeline Issues with Dind: If you are running this in a CI/CD pipeline, there might be issues related to Docker-in-Docker (DinD). For more information on resolving these issues, refer to this GitHub issue.

I hope it can help !

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật