I’m attempting to deploy a serverless functions package to Digital Ocean’s functions namespace. The issue is that I can deploy it without problem when I stay within the Python 3.11 libraries. But as soon as I need another library (not within this runtime), my function fails.
Here’s the steps I’ve taken:
example-project/
├── lib
| └── common
│ └── __init__.py
| └── static.py
│ └── __init__.py
├── packages
│ └── samples
│ └── func1
│ └── __main__.py
│ └── __init__.py
│ └── .include
│ └── requirements.txt
| └── func2
│ └── __main__.py
│ └── __init__.py
│ └── .include
│ └── requirements.txt
| └── func3
│ └── __main__.py
│ └── __init__.py
│ └── .include
│ └── requirements.txt
└── project.yml
└── .env
└── .gitignore
targetNamespace: "fn-************"
environment:
ENV: production
DO_SPACES_ACCESS_KEY: "${DO_SPACES_ACCESS_KEY}"
DO_SPACES_SECRET_KEY: "${DO_SPACES_SECRET_KEY}"
DO_SPACES_REGION: "${DO_SPACES_REGION}"
DO_SPACES_ENDPOINT: "${DO_SPACES_ENDPOINT}"
DO_SPACES_BUCKET: "${DO_SPACES_BUCKET}"
packages:
- name: golf
functions:
- name: func1
runtime: python:3.11
main: main # function inside __main__.py
web: false
environment:
ENV: production
- name: func2
runtime: python:3.11
main: main
web: false
environment:
ENV: production
- name: func3
runtime: python:3.11
main: main
web: false
environment:
ENV: production
__main__.py
requirements.txt
../../../lib/common
../../../lib
doctl serverless deploy . --remote-build
I did see the functions deployed, but when I invoked them, they got an error saying that the modules (listed in requirements.txt) could not be found.
I also tried to add a build.sh with the following basic script:
#!/bin/bash
pip install -r requirements.txt -t .
This did not do anything. And I tried other variations-- all of which did not work. NOTE: I did make this executable chmod +x packages/samples/*/build.sh
I’m looking for help on adding these libraries to serverless functions. I’m new to Digital Ocean, but the documentation is lacking on how you specifically should add packages to serverless functions that aren’t in the primary runtime environment (Python 3.11). If there is no clear solution, I will have to either containerize an application or set it up on a droplet. These latter alternatives I was looking to avoid since this is a very basic job and doesn’t require that much compute.
Appreciate your help.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.