Celery Cloud Documentation
Celery workers without servers. Celery Cloud runs your Celery tasks on AWS Lambda. Your application keeps using the normal Celery client; instead of operating a fleet of always-on workers, a Lambda function consumes the queue, executes the task and stores the result where Celery expects it.
What is Celery Cloud?
A classic Celery deployment needs worker processes running (and being paid for, patched and scaled) around the clock, even when the queue is empty. With Celery Cloud:
No workers to manage. AWS invokes the runner only when there are messages in the queue and scales it for you.
No change in the client. Your code still calls
task.delay(...)ortask.apply_async(...)and readsAsyncResult, using Celery’s own SQS broker and DynamoDB result backend.Your tasks can live anywhere. A task can be a Python function packaged with the runner (a local task), or an existing AWS Lambda function that the runner calls for you (a remote task).
Most of what a Celery worker does. Retries with backoff,
eta/countdown, time limits, progress states,link/chain/group/chord,map/starmap/chunks, signals,revokeand MessagePack / YAML / compression (see Concepts and behaviour for what differs from a real worker).Safe by construction. Only the task names you list can run; a message cannot choose which code is executed.
graph LR
Client["Celery client<br/>(your application)"]
SQS["Amazon SQS<br/>(broker)"]
Runner["celery-cloud runner<br/>(AWS Lambda)"]
Local["Local task<br/>task://module/function"]
Remote["Remote Lambda<br/>lambda://function-arn"]
DDB["DynamoDB<br/>(result backend)"]
Client -- "1. apply_async" --> SQS
SQS -- "2. event source mapping" --> Runner
Runner -- "3a. call" --> Local
Runner -- "3b. invoke" --> Remote
Runner -- "4. STARTED / SUCCESS / FAILURE" --> DDB
Client -- "5. result.get()" --> DDB
Quick Start
Create the infrastructure: an SQS queue, a DynamoDB table, an ECR repository and a Lambda function connected to the queue. See Infrastructure for the step by step guide.
Write a task and package it with the runner. A local task receives the list of positional arguments and the dict of keyword arguments:
# my_tasks.py def add(args: list, kwargs: dict) -> int: return sum(args) + kwargs.get("extra", 0)
Tell the runner where the task runs with the
TASKSenvironment variable of the function (see Configuration):{"tasks.add": "task://my_tasks/add"}
Send the task from your application with a plain Celery client (
pip install "celery[sqs,dynamodb]"). The client does not needcelery-cloud:from celery import Celery REGION = "eu-central-1" QUEUE_NAME = "lambda-runner-queue" QUEUE_URL = "https://sqs.eu-central-1.amazonaws.com/123456789012/lambda-runner-queue" app = Celery("task_client") app.conf.update( broker_url="sqs://", result_backend=f"dynamodb://@{REGION}/lambda-runner-tasks", task_default_queue=QUEUE_NAME, broker_connection_retry_on_startup=True, broker_transport_options={ "region": REGION, "predefined_queues": {QUEUE_NAME: {"url": QUEUE_URL}}, }, ) @app.task(name="tasks.add") def add(x: int, y: int) -> int: raise NotImplementedError # declaration only: never runs on the client result = add.apply_async((10, 3)) print(result.get(timeout=60)) # 13
The User Guide walks through complete examples for both sides.
Contents
Getting Started
- Installation
- Configuration
- Concepts and behaviour
- How a message is processed
- Task states
- Celery options honoured by the runner
- Backend item format
- Result expiration
- Delayed tasks
- Retries
- Workflows
- Revoking
- Serializers and compression
- Duplicate deliveries
- Partial batch responses
- Remote Lambda tasks
- Execution time limit
- Known limitations
- Differences from a Celery worker
User Guide
Infrastructure