Functions

Node.js and Python handlers behind an HTTPS URL that scale to zero (private beta).

Preview — request access from the console.

A function is a Node.js or Python handler with its own HTTPS URL. Nothing runs while nobody calls it. The first call starts an instance. An instance serves calls until it has been idle for a while (5 minutes by default), then it stops: it scales to zero. Under load, more instances start, up to a limit you set.

Every instance runs in its own gVisor sandbox, which gives it its own kernel in user space. It has a read-only root file system, no privileges and its own network namespace. Instances run on shared function hosts in the region.

Private beta. Functions are switched on per organization by an operator. Without that, the service does not appear in the console and its API answers 404.

Write one

Node.js 22 — index.mjs. A standard Fetch API Request goes in and a Response comes out:

export default async function (request) {
  const url = new URL(request.url);
  return Response.json({ hello: url.searchParams.get('name') ?? 'world' });
}

The handler may also return a string (200, text), an object (200, JSON) or nothing (204). export async function handler(request) and export default { fetch(request) {} } work too.

Python 3.12 — main.py:

def handler(request):
    if request.method == "POST":
        data = request.json()
        return 201, {"location": "/items/1"}, {"created": data}
    return {"hello": request.query.get("name", "world")}

request has method, path, query (a dict of first values), headers (lower-case keys), body (bytes), text and json(). Return any of these:

  • a dict or list (JSON, 200);
  • a str or bytes (200);
  • None (204);
  • (status, headers, body).

An exception is a 500. Its traceback goes to the logs, not to the caller.

Code outside the handler (imports, clients, caches) runs once per instance, when it starts. Later calls to the same instance reuse it.

Dependencies are installed at deploy when the bundle has a lockfile:

  • Node.js: package.json with package-lock.json (what npm install writes). Deutsche Cloud runs npm ci --omit=dev; your code imports packages as usual, from /code/node_modules.
  • Python: requirements.txt. Deutsche Cloud runs pip install -r requirements.txt into /code/.python_packages, which is on sys.path (after /code, so your own modules win).
dcloud functions functions deploy --name hello \
  --files index.mjs=@index.mjs --files package.json=@package.json \
  --files package-lock.json=@package-lock.json
# → 202 while the packages install; `dcloud functions functions get --name hello` shows build.state

How the install runs, and what it means for you:

  • Where. On a function host, in a gVisor instance of the same runtime image your function runs on (same Node.js or Python, same libc and CPU architecture), so native modules and wheels match. It runs as an unprivileged user with 1 GB of memory and 5 minutes.
  • Network. The install can reach registry.npmjs.org, or pypi.org and files.pythonhosted.org, and nothing else. Private registries, git+ URLs, --index-url, -e and -r other.txt are refused at deploy with the reason. Install scripts (postinstall) run inside that sandbox.
  • When the new code goes live. Only once its install succeeded. Until then the current version keeps serving; a failed install never goes live, and get shows its error and the log's last 64 KB (the console shows the log too). Deploy again to retry. A new function waits in state building before its first call works.
  • Reuse. The same lockfile (for the same runtime, in your organization) installs once: deploying new code with an unchanged lockfile is live at once. Installs are never shared between organizations. An install that no function uses any more (not its current version, nor one of the few older versions Deutsche Cloud keeps) is deleted a day after a deploy last asked for it, with its stored packages; the next deploy of that lockfile installs again. Deleting a function starts that day, and deleting your organization deletes them all.
  • Size. Up to 512 MB unpacked. The source limit (3 MB) does not include installed packages.

You can still vendor dependencies yourself instead: a node_modules/ directory without a lockfile, or Python packages next to main.py (/code is on sys.path). A lockfile and node_modules/ in the same bundle is refused, as is package.json with dependencies but no lockfile.

Create, call, change

# Create (the console has a form with a starter handler)
dcloud functions functions create --name hello --runtime nodejs22 --files index.mjs=@index.mjs

# Call it through the API: works whatever the function's auth mode
dcloud functions functions invoke --name hello --method GET --path '/?name=ews'

# Call its URL with an access key
curl -H "Authorization: EWS-ACCESS-KEY $EWS_ACCESS_KEY_ID:$EWS_SECRET_ACCESS_KEY" \
  "https://hello-1a2b3c4d.fn.apps.<your-domain>/?name=ews"

# New code: the next call runs it; running instances are replaced as they finish
dcloud functions functions deploy --name hello --files index.mjs=@index.mjs --files lib/util.mjs=@lib/util.mjs

# Configuration
dcloud functions functions update --name hello --memory-mb 512 --max-instances 20

MCP clients get the same operations as tools: functions.functions.create, .invoke, .deploy and the rest.

Who may call the URL

auth The URL accepts
iam (default) Authorization: EWS-ACCESS-KEY <id>:<secret> from a principal of your organization allowed functions:InvokeFunction on the function
public anyone, up to publicRateLimit requests per second. Setting it needs functions:MakeFunctionPublic

The host checks a key with the control plane and remembers the answer for a minute. Every check is written to the audit log. The function never sees the Authorization header.

Limits and scaling

Setting Default Range
memoryMb 256 128–2048
CPU 1 vCPU per GB of memory at least 0.25 vCPU
timeoutSeconds 30 1–900
concurrency 10 (Node.js), 1 (Python) 1–100
maxInstances 10 1–50
idleTimeoutSeconds 300 30–3600
Request / response 10 MB —
Source 3 MB, 200 files —
Per organization 100 functions, 50 instances —

How instances are used:

  • A call goes to an instance with a free slot (fewer than concurrency calls in flight).
  • If no instance has a free slot, a new one starts, up to maxInstances.
  • If all of them are busy, the call waits for a slot until its timeout. Then it gets a 429.
  • A call that runs past timeoutSeconds gets a 504, and that instance is replaced.

Response headers: every response carries X-DCLOUD-Request-Id and X-DCLOUD-Instance. A call that started an instance also carries X-DCLOUD-Cold-Start: <ms>. Each is also sent under its name from before the rename, X-EWS-….

An instance that dies during a call (it crashed, or exceeded its memory and was killed) answers that call with a 502 at once, and the next call starts a new instance.

Cold starts

A function that has scaled to zero starts again on its next call. Measured from the call reaching the host to the response, on a 4-vCPU host, with a small handler:

How the instance comes up Node.js 22 Python 3.12
pool: a pre-started runtime waiting on the host ~45 ms ~15 ms
restore: the runtime restored from a snapshot ~125 ms ~110 ms
boot: the runtime started from scratch ~440 ms ~1 s

Most cold starts are pool starts. The host keeps one runtime of each language and memory size in use started and waiting, with no code in it. A cold start gives it your code and env, imports your module and serves the call. Each waiting runtime is used by one function only, and never again after that function's instance stops.

What your function sees: a fresh process for each instance, as before. Your module is imported when the instance starts, never before, so top-level code runs once per instance and can read process.env / os.environ. Math.random(), Python's random, crypto and os.urandom are seeded independently in every instance.

Which way each instance started is in the function's Instances tab and in the INIT log line (start=pool|restore|boot).

Bursts. A host starts as many instances at once as it has vCPUs; further starts queue for a moment (queued= in the INIT line) instead of all slowing each other down. When cold starts of a runtime and size find no waiting runtime, the host keeps more of them waiting (up to four) for the next ten minutes.

What makes a cold start slower: the time your module takes to import, for example large dependencies or work at the top level. Every file a cold start opens costs more in the sandbox than on a laptop, so import what you use, not a package's index: measured on dev, import { formatISO } from 'date-fns' (the index, hundreds of files) made every cold start ~5 s; import { formatISO } from 'date-fns/formatISO' made it 0.4 s. The INIT log line's module= is that import time. A memory size nobody on the host has used in the last 15 minutes starts by restore, and the first call of a host's first minute may start by boot.

Init snapshots: skip the import (opt-in)

When the import is the slow part, turn on init snapshots (initSnapshot: true; CLI dcloud functions functions update --name api --init-snapshot (--no-init-snapshot turns it off), Terraform init_snapshot, console: Overview → Start from an init snapshot). The first cold start of each version then loads your module as usual and, before it serves its first call, the function host saves the instance as an image. Every later cold start of that version on that host starts from the image: your module is not imported again. The INIT line says start=init-snapshot with no module= time; the start that took the image says checkpoint=…ms (init snapshot taken). get (and the Overview) shows the image per host: its size, what taking it cost, and how many starts used it.

What to know before you turn it on:

  • The image contains your env and secrets as your code saw them at import, and whatever your module computed. It stays on the function host's disk (readable only by the host daemon), is never uploaded or backed up, and is deleted when it is no longer used.
  • A new image for every change: new code, env, memory, a rotated secret value, or a renewed execution-role session (so with a role it lives at most an hour) each take a new one on the next cold start; the old one is deleted. The host also replaces images after a day, or when the runtime changes.
  • Every instance from one image shares what your module computed at import. Deutsche Cloud reseeds Math.random, Python's random and the OpenSSL generator (crypto, ssl) in each instance, but an ID, a token or a timestamp your code made at the top level is the same in all of them. Make those per request. Libraries with their own generator seeded at import (for example numpy.random's global state) are shared too.
  • Connections opened at import are dead after a start from an image. Open database and HTTP connections lazily, on the first request, not at the top level.
  • If an image cannot be used, the instance starts the usual way; nothing fails because of it.
  • Turning it on or off does not create a new version or restart instances. Not for container image functions.

Container images

Any image of your organization's registry can run as a function if its server listens on $PORT (8080):

docker push <org>.ecr.<domain>/orders-api:1.4
dcloud functions functions create --name orders-api --runtime image --image orders-api:1.4
# new version: pinned again to the digest the tag points at now
dcloud functions functions deploy --name orders-api --image orders-api:1.5
  • Pinning. The image is pinned to its digest when you set it; moving the tag later changes nothing until you deploy again. Setting it needs ecr:PullImage on the repository, which is audited.
  • The pull. The function host pulls the image itself, with a short-lived, pull-only token for that one repository, and checks every layer against its digest. Images from other registries are refused.
  • Running. The image runs with its own ENTRYPOINT/CMD, WorkingDir and Env, as an unprivileged user on a read-only root, with a writable /tmp.
  • Env. Your env, secrets and role session are added to the image's env. The instance's spec, which holds them, lives in memory on the host, never on its disk.
  • Cold start. An image starts from scratch: no pool, no snapshot. The first call after a new pin waits for the pull (503 with Retry-After until it is done), and later cold starts are the image's own start time.

Network

network: open (the default) reaches the internet. It cannot reach:

  • private ranges (RFC 1918, CGNAT);
  • link-local addresses and the metadata service;
  • other instances or the host;
  • the Deutsche Cloud control plane directly (use DCLOUD_API_URL, below);
  • SMTP ports 25, 465 and 587.

network: none has no outbound network at all, and no Deutsche Cloud API either.

Secrets and an execution role

Secrets as environment variables. Bind a secret of the Secrets service to a variable:

dcloud functions functions update --name hello \
  --secrets '[{"name":"DATABASE_URL","secretId":"<secret id>"}]'
  • Binding needs secrets:GetSecretValue on the secret, which is audited. Binding also grants the secret to the compute consumer.
  • The value is read when an instance starts. A rotated secret reaches instances started after the rotation (at most 10 minutes later).
  • Each read is in the secret's access log, with the function's RN and the host.
  • The value is never stored on the function host's disk, and GetFunction shows only which secret a variable comes from.
  • Revoking the compute grant on the Secrets page stops new instances from starting. Their INIT log line says why.

An execution role. Give the function an IAM role and its code can call the Deutsche Cloud API as that role, with no keys in the code:

dcloud functions functions update --name hello --role-name orders-writer   # needs iam:PassRole

Each instance gets three variables, each also under its name from before the rename (EWS_…):

  • DCLOUD_ACCESS_KEY: a 60-minute session of the role. The Deutsche Cloud SDKs and the CLI read it.
  • DCLOUD_API_URL: the Deutsche Cloud API as instances reach it, a proxy on the function host.
  • DCLOUD_REGION.
import { DcloudClient } from '@dcloud/sdk'; // reads DCLOUD_ACCESS_KEY and DCLOUD_API_URL

const client = new DcloudClient();
export default async function (request) {
  return await client.queue.messages.send({ name: 'orders', body: await request.text() });
}
  • The audit log records every call as role/<role>/function-<name>.
  • An instance stops taking requests before its session runs out and is replaced, which is a pool start of a few tens of milliseconds.
  • Changing or removing the role revokes the sessions already handed out, at once.
  • A function without a role has no DCLOUD_ACCESS_KEY.

Triggers

A function runs when its URL or the invoke API is called. It can also run on these triggers:

  • A schedule. A Scheduler schedule with a function target posts its input on time, as the schedule's role.
  • An event. An event bus rule with a function target posts the matching event, as the rule's role.
  • A queue. The function consumes a queue in batches:
dcloud functions event-source-mappings create --name orders-worker --queue-name orders --batch-size 10

How a queue trigger works:

  • The call. The function is called with POST / and {"records": [{"messageId", "body", "attributes", "receiveCount", "sentAt", "queueName"}]}, with up to batchSize (1–10) messages per call. At most maxConcurrency batches (1–10, default 2) are in flight at once.
  • The role. Messages are read and deleted as the function's execution role. It needs queue:ReceiveMessage and queue:DeleteMessage on the queue. The trigger is refused if the function has no role, or the role lacks either permission.
  • A 2xx answer deletes the batch, except the messages the function returns in {"failedMessageIds": [...]} (partial batch failure).
  • Any other answer, or a timeout, deletes nothing. The messages come back after the visibility timeout: at least the function's timeout plus 30 s. After maxReceiveCount attempts the queue's redrive policy moves them to its dead-letter queue.
  • At least once. A message can arrive twice, so make the handler idempotent.
  • What you see. Every batch writes a TRIGGER queue=… batch=… status=… deleted=… retry=… line to the function's logs. The Triggers tab shows each trigger's state, last error and counters.
  • Pausing. enabled: false pauses a trigger.

Logs

Each instance writes what it prints to stdout and stderr to Monitoring → Logs, with resource type function. These lines are interleaved with the host's own lines:

INIT    instance=i-… runtime=nodejs22 version=3 memory=256MB start=pool init=18ms launch=0ms listen=0ms initcall=17ms module=6ms
START   9f2c…
REPORT  9f2c… status=200 duration=3.1ms billed=4ms memory=256MB cold=1 init=18ms wait=18.4ms
STOP    instance=i-… reason="idle for 300s (scale to zero)" requests=41 lifetime=6m2s

The console's function panel shows the logs, the instances running at the moment (on which host, with their cold start and idle time), and the last 24 hours of usage.

Metrics

Every function writes metrics to Monitoring in the namespace EWS/Functions, with the dimension FunctionName. You can chart them and set alarms on them like your own metrics:

Metric Unit What
Invocations Count Requests handled
Errors Count 5xx answers, failed starts and timeouts
ColdStarts Count Requests that started an instance
Duration Milliseconds Billed time per request
ConcurrentInstances Count Instances running; use Maximum. 0 when scaled to zero

For example, an alarm on Errors summed over 5 minutes above 0.

Pricing

During the beta, functions are metered but not charged.

SKU Unit Indicative price
functions.request request €0.15 per million
functions.gb_second GB-second €0.0000140
  • GB-seconds are billed milliseconds × memory: the time requests run, not idle instances.
  • Usage records. Every finished hour becomes usage records at these prices, charged €0. The cost explorer shows them as "preview, not charged", with what they would cost. Invoices and budgets do not include them.
  • Free tier. A free tier of 400,000 GB-s and 1 million requests a month is planned. The preview amount does not deduct it.

IAM

Action For
functions:ListFunctions, GetFunction reading functions
functions:CreateFunction creating
functions:UpdateFunctionConfiguration memory, timeout, scaling, auth, network, env
functions:UpdateFunctionCode deploying code
functions:GetFunctionCode reading the code (sensitive, audited)
functions:DeleteFunction deleting
functions:MakeFunctionPublic auth: public
functions:InvokeFunction calling: the invoke API and the URL

RN: rn:ews:de1:<org>:functions:function/<name>, so a policy can name function/api-*.

Function hosts

Your function runs on one Deutsche Cloud function host of its region at a time; get shows which (host), and every instance's host is in the Instances tab. A region grows by adding hosts: a new function goes to the host with the most free memory. A host that stops answering, or reports a problem it cannot fix itself (instance starts failing, a full disk), is replaced: its functions move to another host, and the event log of each function says when and why. The old host keeps serving a moved function for five minutes while its URL's DNS record follows, so a move drops no calls; a host that died answers nothing, so calls fail until the move (about two minutes).

Run outside Germany (Helsinki, fi1)

Functions run in Germany (de1) unless your organization decides otherwise. After an administrator turns on Allow EU locations outside Germany (Settings → Data location), create a function with the header X-EWS-Region: fi1 (CLI --region fi1, SDK/Terraform region). It then runs on Deutsche Cloud function hosts in Helsinki, Finland; its URL answers from there. Functions are named per region: manage a fi1 function with the same header. The console lists the functions of de1 only for now. Without the setting the create answers 403.

Not yet

These are on the roadmap:

  • dependencies from private registries (your Deutsche Cloud npm registry included);
  • S3 triggers;
  • snapshots taken after your module loads, for slow imports (opt-in);
  • a Terraform resource.
Did this page help you?