NavigationContentFooter
Jump toSuggest an edit
Was this page helpful?

How to package your function to a zip file and upload it

Reviewed on 04 February 2025Published on 26 May 2021

This page explains how to upload your functions and their dependencies as a zip file using the Scaleway console.

This feature allows you to add your libraries or static files to your function.

Before you startLink to this anchor

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • A functions namespace
  • installed jq

How to package a function into zip fileLink to this anchor

There are different methods to deploy functions and some of them require the function to be packaged into a zip file.

To match the Scaleway build pipelines requirements, functions zip files must contain the content of the root folder you want to publish.

Important

Avoid compressing your function using the file explorer or finder, as this method can create an additional folder in the file structure of your function, which can lead to build errors. Refer to the troubleshooting section for more information.

How to create a zip fileLink to this anchor

Use the zip command to create an archive of your function and its dependencies:

zip -r myFunction.zip myFunction/

The example above will create a .zip archive that contains the myFunction folder and its content. You can then upload this archive to your Serverless Functions.

How to upload your zip fileLink to this anchor

  1. Package your dependencies on your local computer, as explained in the Configure your package section.
  2. Create a ZIP archive containing the files and folders you need.
  3. Go to the Functions section of the Scaleway console and click on the functions namespace you want to configure.
  4. Click + Create function. The function creation page displays.
  5. On the function creation page, choose your desired runtime.
  6. Select Upload a ZIP under Function code.
  7. Drag and drop your zip file in the reserved field or upload it.
  8. Specify your handler path.
  9. Configure your function.
  10. Click Create function to finish.
Note

Refer to our dedicated documentation for more information on how to create Serverless Functions

How to configure your packageLink to this anchor

HandlerLink to this anchor

The Handler name is a path to the handler file, suffixed with the function name to use as a handler. In the following example, we use one handler, hello.py, inside the src/handlers folder.

.
└── handlers
└── hello.py → def say_hello(event, context): ...
  1. Package your function. On Unix systems, you can use the zip utility:

    zip -r functions.zip handlers/
  2. Upload the archive in the console.

  3. Provide a custom handler name. Here, the handler is handlers/hello.say_hello.

    Note

    By default, the handler path is handler.handle (def handle in handler.py). Refer to the Functions handlers reference for more information.

DependenciesLink to this anchor

Additional dependencies must be included inside a package directory at the root of your archive.

Your directory structure should look like this:

.
├── handlers
│ ├── handler.py
│ └── second_handler.py
└── package → Your vendored Python dependencies
└── requests

To package your functions into an archive that can be uploaded to the console, you can use the zip utility:

zip -r functions.zip handlers/ package/

Python standard dependencies

In addition, you can install your dependencies in the package directory. To do so, run the following command:

pip install requests --target ./package

Or with a requirements.txt file:

pip install -r requirements.txt --target ./package

Specific libraries (with needs for specific C compiled code)

In some specific cases, you might need to install libraries that require specific C compiled code such as:

  • numpy
  • tensorflow
  • pandas
  • scikit-learn
  • psycopg2 and others.

Our Python runtimes run on top of Alpine Linux environments, for these specific dependencies, you will have to install your dependencies inside a Docker container, with a specific image, that we are providing to our users. Run the following command from the root of your project to install your dependencies before uploading your source code and deploying your function:

PYTHON_VERSION=3.10 # or 3.7, 3.8, ...
docker run --rm -v $(pwd):/home/app/function --workdir /home/app/function rg.fr-par.scw.cloud/scwfunctionsruntimes-public/python-dep:$PYTHON_VERSION pip install -r requirements.txt --target ./package

This command will run pip install with the given requirements.txt file inside a docker container compatible with our function runtimes, and pull the installed dependencies locally to your package directory. As these dependencies have been installed on top of Alpine Linux with our compatible system libraries, you will be able to upload your source code and deploy your function properly.

How to manage multiple handles in the same zip fileLink to this anchor

To enhance deployment simplicity, all runtimes support the inclusion of multiple handlers, either within a single file or across multiple files.

Example:

.
├── myFuncA.lang (contains handlerA() and handlerB())
└── myFuncB.lang (contains handlerC())

Like that, you can create 3 functions with the same zip file simply by changing the handler parameter to match the handler you want:

  • myFuncA.handlerA
  • myFuncA.handlerB
  • myFuncB.handlerC

You can also create a single Serverless Function with several handlers in the same zip file, and change the handler parameter according to your needs.

TroubleshootingLink to this anchor

If you encounter build errors after packaging your function, make sure that your archive is properly structured, as shown above. Compressing a folder from its parent directory will include this folder in the archive structure that can lead to build errors while deploying your function.

To avoid archive structure issue, make sure to zip your function from its root folder, and not the parent directory by using the following method:

cd folder_i_want_to_zip
zip -r ../function.zip .

You can then use the unzip command with the -v option to list the content of your archive to ensure it is properly structured:

unzip -v ../func.zip
See also
How to test a functionHow to manage a function
Was this page helpful?
API DocsScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCareers
© 2023-2025 – Scaleway