This guide provides instructions for deploying Dagster on Amazon Web Services (AWS). You can use EC2 or ECS to host the Dagster webserver and the Dagster daemon, RDS to store runs and events, and S3 as an I/O manager to store op inputs and outputs.
You provide the right connection strings for your RDS instance
The node or container hosting the webserver is able to connect to RDS
Be sure that this file is present and DAGSTER_HOME is set on the node where the webserver is running.
Note: Using RDS for run and event log storage doesn't require that the webserver be running in the cloud. If you're connecting a local webserver instance to a remote RDS storage, verify that your local node is able to connect to RDS.
The Deploying on ECS example on GitHub demonstrates how to configure the Docker Compose CLI integration with ECS to manage all of the required AWS resources that Dagster needs to run on ECS. The example includes:
A webserver container for loading and launching jobs
A dagster-daemon container for managing a run queue and submitting runs from schedules and sensors
The EcsRunLauncher launches an ECS task per run. It assumes that the rest of your Dagster deployment is also running in ECS.
By default, each run's task registers its own task definition. To simplify configuration, these task definitions inherit most of their configuration (networking, cpu, memory, environment, etc.) from the task that launches the run but overrides its container definition with a new command to launch a Dagster run.
When using the DefaultRunCoordinator, runs launched via the Dagster UI or GraphQL inherit their task definitions from the webserver task while runs launched from a sensor or schedule inherit their task definitions from the daemon task.
Alternatively, you can define your own task definition in your dagster.yaml:
Customizing CPU, memory, and ephemeral storage in ECS#
You can set the run_launcher.config.run_resources field to customize the default resources for Dagster runs. For example:
run_launcher:module:"dagster_aws.ecs"class:"EcsRunLauncher"config:run_resources:cpu:"256"memory:"512"# In MiBephemeral_storage:128# In GiB
Note: Fargate tasks only support certain combinations of CPU and memory and values of ephemeral storage between 21 and 200 GiB (the default is set to 20 GiB).
You can also use job tags to customize the CPU, memory, or ephemeral storage of every run for a particular job:
from dagster import job, op
@op()defmy_op(context):
context.log.info('running')@job(
tags ={"ecs/cpu":"256","ecs/memory":"512","ecs/ephemeral_storage":"40",})defmy_job():
my_op()
If these tags are set, they will override any defaults set on the run launcher.
The EcsRunLauncher creates a new task for each run, using the current ECS task to determine network configuration. For example, the launched run will use the same ECS cluster, subnets, security groups, and launch type (e.g. Fargate or EC2).
To adjust the configuration of the launched run's task, set the run_launcher.config.run_task_kwargs field to a dictionary with additional key-value pairs that should be passed into the run_task boto3 API call. For example, to launch new runs in EC2 from a task running in Fargate, you could apply this configuration:
You can also use the ecs/run_task_kwargs tag to customize the ECS task of every run for a particular job:
from dagster import job, op
@op()defmy_op(context):
context.log.info('running')@job(
tags ={"ecs/run_task_kwargs":{"capacityProviderStrategy":[{"capacityProvider":"FARGATE_SPOT",},],},})defmy_job():
my_op()
Refer to the boto3 docs for the full set of available arguments to run_task. Additionally, note that:
Keys are in camelCase as they correspond to arguments in boto's API
All arguments with the exception of taskDefinition and overrides can be used in run_launcher.config.run_task_kwargs. taskDefinition can be overridden by configuring the run_launcher.config.task_definition field instead.
In this example, any secret tagged with a key my-tag-name will be included as an environment variable with the name and value as that secret. The value of the tag is ignored.
In this example, any secret tagged with dagster will be included in the environment. MY_API_TOKEN and MY_PASSWORD will also be included in the environment.
To enable parallel computation (e.g., with the multiprocessing or Dagster celery executors), you'll need to configure persistent I/O managers. For example, using an S3 bucket to store data passed between ops.
from dagster_aws.s3.io_manager import s3_pickle_io_manager
from dagster_aws.s3.resources import s3_resource
from dagster import Int, Out, job, op
@op(out=Out(Int))defmy_op():return1@job(
resource_defs={"io_manager": s3_pickle_io_manager,"s3": s3_resource,})defmy_job():
my_op()
Then, add the following YAML block in your job's config:
The resource uses boto under the hood. If you're accessing your private buckets, you'll need to provide the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables or follow one of the other boto authentication methods.
With this in place, your job runs will store data passed between ops on S3 in the location s3://<bucket>/dagster/storage/<job run id>/<op name>.compute.