---
meta:
  title: How to create and deploy a function with the Scaleway API
  description: Deploy Serverless Functions via the Scaleway API following this instructional guide.
content:
  h1: How to create and deploy a function with the Scaleway API
  paragraph: Deploy Serverless Functions via the Scaleway API following this instructional guide.
tags: functions api deploy
dates:
  validation: 2025-03-13
  posted: 2021-08-18
categories:
  - serverless
---
import Requirements from '@macros/iam/requirements.mdx'


The Scaleway API allows you to create and manage all your Scaleway resources programmatically. Anything you can do through the [Scaleway console](https://www.console.scaleway.com)
can also be done through the API.

Refer to the [Scaleway Developers website](https://www.scaleway.com/en/developers/api/) for more information on the Scaleway API.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A valid [API key](/iam/how-to/create-api-keys/)
- Installed [curl](https://curl.se/download.html)
- [Made your first request](https://www.scaleway.com/en/developers/api/#quickstart:-first-request) using the Scaleway API

1. Run the following command in your terminal to create a functions namespace:

    ```json
    curl -X POST \
    -H "X-Auth-Token: $SCW_SECRET_KEY" \
    -H "Content-Type: application/json" \
    -d '{
        "name": "<YOUR_NAMESPACE_NAME>",
        "project_id": "YOUR_PROJECT_ID"
    }' \
    "https://api.scaleway.com/functions/v1beta1/regions/fr-par/namespaces"
    ```

    An output similar to the following displays:

    ```json
    {"id":"example-fb93-43e3-a036-7be69f1af7a1", "name":"your-namespace-name", "environment_variables":{}, "organization_id":"example-776f-4f65-a41e-6c5fc58b4076", "project_id":"example-c162-43f7-bb3e-1182e6f12342", "status":"pending", "registry_namespace_id":"", "error_message":null, "registry_endpoint":"", "description":"", "secret_environment_variables":[], "region":"fr-par"}%  
    ```

2. Run the following command to create a function:

    ```json
    curl -X POST \
    -H "X-Auth-Token: $SCW_SECRET_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "<YOUR_FUNCTION_NAME>",
      "namespace_id": "<YOUR_NAMESPACE_ID>",
      "runtime": "<RUNTIME>"
    }' \
    "https://api.scaleway.com/functions/v1beta1/regions/fr-par/functions"
    ```

    An output similar to the following displays:

    ```json
    {"id":"ef777a64-1f4e-4d43-8227-26927c7de057", "name":"your-function-name", "namespace_id":"example-fb93-43e3-a036-7be69f1af7a1", "status":"created", "environment_variables":{}, "min_scale":0, "max_scale":5, "runtime":"python310", "memory_limit":256, "cpu_limit":140, "timeout":"300s", "handler":"handler.handle", "error_message":null, "privacy":"public", "description":"", "domain_name":"namespaceg04rnwx-function-example.functions.fnc.fr-par.scw.cloud", "secret_environment_variables":[], "http_option":"enabled", "runtime_message":"", "build_message":null, "region":"fr-par"}%  
    ```

3. Create a zip file containing your function's code by following [this procedure](/serverless-functions/how-to/package-function-dependencies-in-zip/).

    <Message type="note">
      For testing purposes, you can create a zip archive with a simple Python file named `handler.py` at the root of the archive, that contains the following code:

      ```python
      def handle(event, context):
      return {
          "body": {
              "message": 'Hello, world',
          },
          "statusCode": 200,
      }
      ```
    </Message>

4. Upload your zip file [using the Scaleway console or the Scaleway API](/serverless-functions/how-to/package-function-dependencies-in-zip/#how-to-upload-your-zip-file).

5. Run the following command to deploy your function:

    ```json
    curl -X POST \
      -H "X-Auth-Token: $SCW_SECRET_KEY" \
      -H "Content-Type: application/json" \
      -d '{}' \
      "https://api.scaleway.com/functions/v1beta1/regions/fr-par/functions/<YOUR_FUNCTION_ID>/deploy"
    ```

    Your function is now being deployed.

    <Message type="tip">
      You can check the status of your function from the [Scaleway console](https://www.console/scaleway.com/) or by running the following command:

      ```json
      curl -X GET \
        -H "X-Auth-Token: $SCW_SECRET_KEY" \
        "https://api.scaleway.com/functions/v1beta1/regions/fr-par/functions/<YOUR_FUNCTION_ID>"
      ```
    </Message>

6. Run the following command to call your function once it is deployed:

    ```
    curl <YOUR_FUNCTION_ENDPOINT>
    ```
  