Serverless runtime environment
By default, Dagster+ Serverless will package your code as PEX files and deploy them on Docker images. Using PEX files significantly reduces the time to deploy since it does not require building a new Docker image and provisioning a new container for every code change. However, you are able to customize the Serverless runtime environment in various ways:
- Add dependencies
- Use a different Python version
- Use a different base image
- Include data files
- Disable PEX deploys
- Use private Python packages
Add dependencies
You can add dependencies by including the corresponding Python libraries in your Dagster project's package configuration file.
- uv
- pip
If you are using uv
with a pyproject.toml
file, you should follow the pyproject.toml specification.
[project]
name = "quickstart_etl"
requires-python = ">=3.9,<3.14"
version = "0.1.0"
dependencies = [
"dagster",
"dagster-cloud",
"boto3",
"matplotlib",
"pandas",
"textblob",
"tweepy",
"wordcloud",
]
[project.optional-dependencies]
dev = [
"dagster-dg-cli",
"dagster-webserver",
"pytest",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.dg]
directory_type = "project"
[tool.dg.project]
root_module = "quickstart_etl"
registry_modules = [
"quickstart_etl.components.*",
]
If you are using pip
with a setup.py
file, you should follow PEP 508.
from setuptools import find_packages, setup
setup(
name="quickstart_etl",
packages=find_packages(exclude=["quickstart_etl_tests"]),
install_requires=[
"dagster",
# when possible, add additional dependencies in setup.py
"boto3",
"pandas",
"matplotlib",
],
extras_require={"dev": ["dagster-webserver", "pytest"]},
)
If you are using a setup.py
file, you will need to add a TOML configuration file to the root of your project in order to make it dg
-compatible and use Components. For more information, see Converting an existing project.
Add dependencies from tarballs
- uv
- pip
[project]
name = "quickstart_etl"
requires-python = ">=3.9,<3.14"
version = "0.1.0"
dependencies = [
"dagster",
"dagster-cloud",
"boto3",
"matplotlib",
"pandas",
"textblob",
"tweepy",
"wordcloud",
"soda @ https://pypi.cloud.soda.io/packages/soda-1.6.2.tar.gz",
"soda-snowflake @ https://pypi.cloud.soda.io/packages/soda_snowflake-1.6.2.tar.gz",
]
from setuptools import find_packages, setup
setup(
name="quickstart_etl",
packages=find_packages(exclude=["quickstart_etl_tests"]),
install_requires=[
"dagster",
"boto3",
"pandas",
"matplotlib",
"soda @ https://pypi.cloud.soda.io/packages/soda-1.6.2.tar.gz",
"soda-snowflake @ https://pypi.cloud.soda.io/packages/soda_snowflake-1.6.2.tar.gz",
],
extras_require={"dev": ["dagster-webserver", "pytest"]},
)
To add a package from a private GitHub repository, see Use private Python packages.
Use a different Python version
Python versions 3.9 through 3.13 are all supported for Serverless deployments. You can specify the Python version you want to use in your GitHub or GitLab workflow, or by using the dagster-cloud
CLI.
- GitHub
- GitLab
- CLI
In your .github/workflows/deploy.yml
file, update the PYTHON_VERSION
environment variable with your desired Python version:
env:
DAGSTER_CLOUD_URL: "http://jamie-test-1.canary.dagster.cloud"
DAGSTER_CLOUD_API_TOKEN: ${{ secrets.DAGSTER_CLOUD_API_TOKEN }}
ENABLE_FAST_DEPLOYS: 'true'
PYTHON_VERSION: '3.11'
DAGSTER_CLOUD_FILE: 'dagster_cloud.yaml'
-
Open your
.gitlab-ci.yml
file. If your.gitlab-ci.yml
contains aninclude
with a link to a Dagster provided CI/CD template:include:
remote: https://raw.githubusercontent.com/dagster-io/dagster-cloud-action/v0.1.29/gitlab/dbt/serverless-ci-dbt.ymlFollow the link and replace the contents of your
.gitlab-ci.yml
with the YAML document at the link address. Otherwise, continue to the next step. -
Update the
PYTHON_VERSION
environment variable with your desired Python version
variables:
DISABLE_FAST_DEPLOYS:
DAGSTER_CLOUD_URL: $DAGSTER_CLOUD_URL
DAGSTER_CLOUD_API_TOKEN: $DAGSTER_CLOUD_API_TOKEN
PYTHON_VERSION: '3.11'
You can specify the Python version when you deploy your code with the dagster-cloud serverless deploy-python-executable
command:
dagster-cloud serverless deploy-python-executable --python-version=3.11 --location-name=my_location
Use a different base image
Dagster+ runs your code on a Docker image that we build as follows:
- The standard Python "slim" Docker image, such as python:3.10-slim is used as the base
- The dagster-cloud[serverless] module installed in the image
You can add dependencies in your pyproject.toml
or setup.py
file, but when that is not possible, you can build and upload a custom base image that will be used to run your Python code:
Setting a custom base image isn't supported for GitLab CI/CD workflows out of the box, but you can write a custom GitLab CI/CD YAML file that implements the manual steps noted.
-
Include
dagster-cloud
anddagster-cloud[serverless]
as dependencies in your Docker image by adding the following lines to yourDockerfile
:RUN pip install "dagster-cloud"
RUN pip install "dagster-cloud[serverless]" -
Build your Docker image, using your usual Docker toolchain.
noteIf you try to deploy a Docker image to Dagster+ Serverless that was locally built on an M1/M2 Mac it will use ARM architecture and be incompatible with AWS ECS. In this case you must specify Docker builds the image using AMD architecture:
docker build -t dagster-project:latest --platform=linux/amd64 .
-
Upload your Docker image to Dagster+ using the
upload-base-image
command. This command will print out the tag used in Dagster+ to identify your image:dagster-cloud serverless upload-base-image local-image:tag
To use the uploaded image run:
dagster-cloud serverless deploy-python-executable ... --base-image-tag=sha256_518ad2f92b078c63c60e89f0310f13f19d3a1c7ea9e1976d67d59fcb7040d0d6
-
Specify this base image tag in you GitHub workflow, or using the
dagster-cloud
CLI:
- GitHub
- CLI
In your .github/workflows/deploy.yml
file, add the SERVERLESS_BASE_IMAGE_TAG
environment variable and set it to the tag printed out in the previous step:
env:
DAGSTER_CLOUD_URL: "http://jamie-test-1.canary.dagster.cloud"
DAGSTER_CLOUD_API_TOKEN: ${{ secrets.DAGSTER_CLOUD_API_TOKEN }}
SERVERLESS_BASE_IMAGE_TAG: "sha256_518ad2f92b078c63c60e89f0310f13f19d3a1c7ea9e1976d67d59fcb7040d0d6"
You can specify the base image when you deploy your code with the dagster-cloud serverless deploy-python-executable
command:
dagster-cloud serverless deploy-python-executable \
--base-image-tag=sha256_518ad2f92b078c63c60e89f0310f13f19d3a1c7ea9e1976d67d59fcb7040d0d6 \
--location-name=my_location
Include data files
- uv
- pip
To add data files to your deployment, create a data
directory under the src/{PACKAGE NAME}
directory:
quickstart-etl
├── dagster_cloud.yaml
├── pyproject.toml
├── tests
│ ├── __init__.py
│ └── test_defs.py
├── README.md
├── src
│ └── quickstart_etl
│ ├── __init__.py
│ ├── data
│ │ ├── file1.txt
│ │ └── file2.csv
│ ├── definitions.py
│ └── defs