Skip to main content

Cloud Setup

What has to exist in your account before a cluster will start

DevitoHorizon runs a Dask cluster on Azure VMs (azure_vm_cluster) or AWS EC2 (ec2_cluster). Both need the same four things in place, and neither will tell you which one is missing if you skip it — a node that cannot pull its image just shuts itself down, and the client waits on a scheduler that never arrives.

Azure AWS
Storage Blob container S3 bucket
Networking vnet + network security group VPC + subnet + security group
Registry ACR, with a password ECR, with an IAM instance profile
Worker image dask:azure dask:aws

Everything below is generated by two scripts per cloud. Run them in this order.

1. Credentials file

The one file that both storage and the cluster read.

scripts/make_aws_creds.sh -o demos/aws_creds.json

Inside the worker image there is no AWS CLI, only boto3, so use the Python script next to it instead. Run on an EC2 instance it takes the region, VPC, subnet and security group from that instance’s own placement, and the registry from the account:

scripts/make_aws_creds.py -b my-bucket

Only the bucket and the cluster’s instance profile are arguments, because neither is a fact about the machine: an account has many buckets, and which role the cluster assumes is a choice. Off an instance there is nothing to read and every field has to be passed; the error names the missing ones.

Fills in region, bucket, VPC, subnet, security group, instance profile and the ECR host from your configured aws CLI. It prompts only where several resources match; pass the flag instead (--vpc, --subnet, --sg, --profile-name) when there is no terminal to prompt on.

{
  "provider": "s3",
  "container_name": "<bucket>",
  "region": "us-east-2",
  "vpc": "vpc-…", "subnet": "subnet-…", "security_group": "sg-…",
  "instance_profile": "<iam instance profile>",
  "docker_registry": "<account>.dkr.ecr.<region>.amazonaws.com"
}

No access keys by default. "provider": "s3" says the paths are on S3 and the credentials are already here — from your own AWS configuration on the client, and from the instance profile on each worker. This matters: an empty credentials mapping means the local filesystem, so a run configured that way writes to whichever machine drove it. --embed-keys writes the keys in, for nodes that carry no instance profile.

scripts/make_azure_creds.sh -o demos/azure_creds.json

Needs az login. Fills in subscription, resource group, location, storage account, account key, container, vnet and NSG.

{
  "account_name": "<storage account>",
  "account_key": "<key>",
  "container_name": "<container>",
  "subscription_id": "…", "resource_group": "…", "location": "…",
  "vnet": "…", "security_group": "<nsg name>"
}

The account key needs Blob Data Reader (and Contributor, to write results).

Workers receive only the keys that open the store — scoped_storage_creds narrows the mapping before it is pickled, so the subscription, NSG, VPC, instance profile and registry password stay on the client.

2. Registry, and the worker image

The nodes run a Docker image carrying devitohorizon and its pinned dask stack. It is built by .github/workflows/build-dask-images.yml, one image per cloud from the same layer, and pushed to your registry.

scripts/setup_ecr.sh --region <region> --role <arn>     # or --embed-keys

Creates the ECR repository, writes docker_registry into the credentials file, and registers the GitHub Actions secrets the build needs: ECR_REGISTRY, AWS_REGION, and one identity — AWS_ROLE_TO_ASSUME (OIDC, nothing long-lived stored) or AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY. Without an identity the AWS half of the build skips rather than fails.

There is no public AWS image. ECR is per-account, so the default image is <docker_registry>/devitohorizon/dask:aws — taken from the credentials. Credentials naming no registry raise before anything is provisioned, rather than pulling a name that resolves to nothing.

That tag covers both architectures. It is a manifest list over :aws-amd64 and :aws-arm64, each built natively on a runner of its own architecture, so a Graviton node pulling dask:aws gets the arm64 image and an x86 node gets the x86 one. Neither has to be told which it wants.

The two legs run in different places. amd64 builds on the self-hosted x86 runner; arm64 builds on a GitHub-hosted ubuntu-24.04-arm runner, which is native arm64 rather than emulated and needs no fleet of our own. That matters because a matrix leg asking for a [self-hosted, ARM64] runner that does not exist never fails, it queues indefinitely, holding the run open and stopping the manifest job from publishing anything. Emulating arm64 on the x86 runner is the other option and is much worse: this chain compiles devitopro from source, which under QEMU costs hours.

How a node authenticates is the part that differs from Azure. ECR has no password to put in a file; it issues a token that expires in twelve hours, so the node fetches its own at boot with aws ecr get-login-password. That needs the AWS CLI, which the stock Ubuntu AMI does not have — the bootstrap installs it — and an instance profile with ECR rights (see below).

scripts/setup_acr.sh -n <registry name> -g <resource group>

Creates the ACR, enables the admin user, writes docker_registry, docker_username and docker_password into the credentials file, and registers ACR_REGISTRY, ACR_USERNAME, ACR_PASSWORD as GitHub secrets.

A node logs in with that password, fed through stdin so it is not in the machine’s process list. devitocodes/dask:azure also exists publicly, which is the default when no private registry is configured.

A pull request publishes its own tag — :aws-pr<N> / :azure-pr<N> — so a branch can be tried on a real cluster before it merges. Only a merge to main writes the bare :aws / :azure tags that the helpers pull by default. To run a branch’s image, pass it:

cluster = ec2_cluster(creds, docker_image=f"{registry}/devitohorizon/dask:aws-pr57")

3. Permissions

The worker nodes act as the IAM instance profile named in the credentials. It needs to pull the image and reach the bucket:

{
  "Version": "2012-10-17",
  "Statement": [
    {"Effect": "Allow", "Action": "ecr:GetAuthorizationToken", "Resource": "*"},
    {"Effect": "Allow",
     "Action": ["ecr:BatchCheckLayerAvailability", "ecr:BatchGetImage",
                "ecr:GetDownloadUrlForLayer"],
     "Resource": "arn:aws:ecr:<region>:<account>:repository/devitohorizon/dask"},
    {"Effect": "Allow",
     "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
     "Resource": "arn:aws:s3:::<bucket>/*"},
    {"Effect": "Allow",
     "Action": ["s3:ListBucket", "s3:GetBucketLocation"],
     "Resource": "arn:aws:s3:::<bucket>"}
  ]
}

s3:DeleteObject is not optional: a dispatch stages the template model on the store and removes it afterwards.

Check it without launching anything:

aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::<account>:role/<role> \
  --action-names ecr:GetAuthorizationToken

The client needs whatever your own credentials already give you, plus ec2:RunInstances, ec2:TerminateInstances, ec2:Describe* and iam:PassRole for the instance profile.

The client authenticates to ARM with DefaultAzureCredential, which picks up az login. It needs rights to write an inbound rule on the NSG.

Workers reach blob storage with the account key from the credentials file — there is no managed-identity path here — so nothing further to grant.

4. Networking

Both helpers open the scheduler and dashboard ports (8786, 8787) to the client’s current public IP, so a laptop that moves network does not lock itself out. Neither opens them to the internet.

  • AWS — ensure_scheduler_ingress replaces the rules a previous run left, finding them by the dask-client description, then authorises the new address as a /32. The subnet must route 0.0.0.0/0 to an internet gateway and assign public IPs, or the node cannot reach the registry at all.
  • Azure — ensure_scheduler_ingress creates or updates one NSG rule named dask-client.

Credentials naming no security group are left alone on AWS: dask-cloudprovider then creates its own, and there is nothing here to open.

AWS: how the scheduler is addressed

dask-cloudprovider gives the client and the workers the same single scheduler address — configure_vm returns (ip, None), so external_address is never set — and use_private_ip only chooses which IP that is. Neither IP works for a client outside the VPC, which is worth knowing because both fail silently:

  • The public IP is unreachable from inside the VPC. Traffic to a sibling’s public address does not arrive at all, whatever the security group allows. Every worker times out, exits, and its instance shuts down, while the client sits on Waiting for N worker(s) to register:

    OSError: Timed out trying to connect to tls://<public ip>:8786 after 60 s
    RuntimeError: Nanny failed to start.
  • The private IP is unreachable from the client — and wait_for_scheduler polls it from there, so cluster creation never returns.

The instance’s public DNS name is what AWS provides for exactly this: it resolves to the private IP inside the VPC and the public IP outside. Measured from a probe instance in the same subnet and security group:

PROBE public-ip  (3.23.129.88:8786)   FAIL
PROBE private-ip (172.31.19.138:8786) OK
PROBE public-dns resolves-to 172.31.19.138

ec2_cluster therefore addresses the scheduler by name, and the log says so:

Waiting for scheduler to run at ec2-3-15-155-253.us-east-2.compute.amazonaws.com:8786

This needs DNS hostnames enabled on the VPC (the default). Without them the instance has no public DNS name; the cluster warns and falls back to the IP, which will fail as above. devitohorizon/cloud/aws/dns.py holds the two subclasses that do it, and is coupled to dask-cloudprovider’s class layout — verified against 2025.9.0.

Passing use_private_ip=True opts out and uses dask-cloudprovider’s own behaviour, for a client that really is inside the VPC.

5. A client that matches the image

The client and the workers exchange pickled objects over a versioned protocol. pyproject.toml pins dask, distributed, cloudpickle, msgpack, toolz and tornado exactly, and the worker image is built from those same pins. Both cluster helpers check this before provisioning, so a mismatch costs a traceback rather than a booted cluster you cannot talk to.

from devitohorizon.cloud import check_local_versions
check_local_versions()

If it raises, your environment predates a pin bump. Either pip install -e ., or build an environment matching the image exactly — the image runs Python 3.10, and a differing minor is reported but not fatal (it only breaks a task that pickles a closure by value):

/opt/homebrew/bin/python3.10 -m venv ~/venv-horizon-py310
~/venv-horizon-py310/bin/pip install -e ./devito -e ./devitopro -e ./pysegy \
                                   -e ./recipes -e ./schismpro
~/venv-horizon-py310/bin/pip install -e ./devitohorizon[aws]     # or [azure]
~/venv-horizon-py310/bin/python -m ipykernel install --user --name horizon-py310

From the command line

devitohorizon-fwi provisions the cluster itself when the dask section names a cloud, so nothing above has to be driven from Python:

"dask": {"cloud": "aws", "creds": "aws_creds.json", "n_workers": 8}
devitohorizon-fwi config.json

The run brings the cluster up, uses it, and closes it at the end. See FWI configuration for the rest of the section.

Starting the cluster

import json
from dask.distributed import Client
from devitohorizon.cloud import ec2_cluster        # or azure_vm_cluster
from devitohorizon.scheduler import DaskScheduler

creds = json.load(open("aws_creds.json"))
cluster = ec2_cluster(creds, instance_type="m5.large", n_workers=4)
client = Client(cluster)
scheduler = DaskScheduler(client)

Running the scheduler here

A cluster of N workers costs N+1 instances: dask-cloudprovider boots a VM for the scheduler too. The scheduler runs no Devito, so on a machine that is already up and already talking to the cluster, that instance is overhead.

cluster = ec2_cluster(creds, n_workers=4, local_scheduler=True)

The scheduler then runs in this process and the workers dial back to it, so four workers cost four instances.

The condition is that the workers can reach this machine on the scheduler port, and that is not a given:

  • From an instance inside the VPC it holds, as long as the security group admits the worker traffic. If this machine is in the same group, the group’s self-reference already does that.
  • From a laptop behind NAT it does not hold at all without a forwarded port or a tunnel, and the run fails the way an unreachable scheduler always fails: workers time out, shut themselves down, and the client waits.

Where this machine is reached by an address it cannot see on an interface of its own, name it:

cluster = ec2_cluster(creds, n_workers=4, local_scheduler=True,
                      scheduler_contact_address="tls://<reachable host>:8786")

Graviton

A Graviton instance type is recognised by name and the cluster is booted from an arm64 Ubuntu AMI. Nothing else changes:

cluster = ec2_cluster(creds, instance_type="c7g.4xlarge", n_workers=4)

The AMI matters because dask-cloudprovider’s default lookup spells the architecture amd64 outright, so a Graviton cluster left to it boots an x86 image on arm64 hardware and never comes up. Passing ami= yourself still wins, for a custom image.

The worker image needs no thought: dask:aws is a manifest list, so the Graviton node pulls the arm64 image out of the same tag an x86 node pulls the x86 one from.

The instance types in one cluster have to share an architecture — a cluster boots one AMI — so mixing c7g workers with an m5 scheduler raises before anything is provisioned rather than half the nodes failing to start.

Give the model its credentials too, inside the specification rather than beside it — that is what tells a run it has storage every node can reach:

physics = DevitoPhysics(..., model={'model': {'vp': 'vp.segy'},
                                    'container_name': bucket,
                                    'creds': creds})

Without it the staged model, the compiled operators and the immersed-boundary index maps go to a local directory: correct on a shared filesystem, invisible to a cloud worker.

When it hangs at “Waiting for scheduler to run”

The node booted and the container never started. It will shut itself down (Client.InstanceInitiatedShutdown on AWS), taking the evidence with it, so the first move is to keep it alive:

cluster = ec2_cluster(creds, ..., auto_shutdown=False)

Then read /var/log/cloud-init-output.log on the instance, or aws ec2 get-console-output --instance-id <id>. In order of likelihood:

  1. The image does not exist at the reference given. Check the tag is really pushed — a PR publishes :aws-pr<N>, not :aws.
  2. The node cannot authenticate to the registry. On AWS, no GetAuthorizationToken from the instance role in CloudTrail means the call was never made; an AccessDenied means the role lacks ECR rights.
  3. The node has no route out — subnet without an internet gateway.
  4. The client cannot reach the scheduler, which looks the same from the notebook. Check the ingress rule is scoped to your current IP.

If it gets as far as Waiting for N worker(s) to register the scheduler is up and the workers are the problem — check the address it is waiting on is a DNS name, not a raw IP.

Back to top