If you've run Auto Loader on AWS for a while, you've probably hit this progression yourself: you start with the default Directory Listing mode because it's the easiest to set up, and it works fine — until your source directories grow into the millions of files and the listing calls start showing up on your S3 bill. The usual fix has been File Notification mode, but that comes with its own headache: a dedicated SNS topic and SQS queue per stream, which adds up fast and starts bumping into AWS's per-bucket notification quotas.
Databricks now recommends a third option: File Notification mode with Managed File Events. Instead of a queue per stream, every stream on an external location shares one Databricks-managed queue. Less infrastructure to create, fewer IAM policies, and no more worrying about hitting quota limits as you add streams.
This post walks through setting it up end to end on AWS with Unity Catalog — the IAM side, the Databricks side, and a working Auto Loader stream at the end.
A few AWS and Databricks building blocks come up throughout this guide:
There are two flavors of file notification mode:
Here's how the three approaches compare:
|
Mode |
How it works |
Pros |
Cons |
|
Directory Listing (default) |
Periodically lists the S3 directory to find new files. |
Simple — nothing to configure in AWS. |
Gets slow and expensive as the directory grows; listing cost scales with file count, not just new files. |
|
Classic File Notification |
Creates a dedicated SNS topic and SQS queue for each stream. |
Event-driven, so new files are picked up quickly. |
Every stream needs its own queue, so you can hit AWS's per-bucket notification quota (100 configurations per S3 bucket) once you have more than a handful of streams. Your cloud team has to provision and maintain IAM permissions for each one. |
|
File Notification with Managed File Events (recommended) |
All streams on an external location share one Databricks-managed SNS/SQS pair. |
Scales to any number of streams without touching AWS quotas; Databricks handles tuning and cleanup; fewer IAM policies overall. |
Your cloud team still does the IAM/trust-policy setup below — but only once per external location, not once per stream. |
At a high level, this is what happens each time a new file lands:
For the full breakdown of how this works under the hood, see Databricks' own write-up: Auto Loader with file events overview.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<YOUR-AWS-ACCOUNT-ID>:root"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "0000"
}
}
}
]
}
This policy grants the role permission to read S3 and to create and manage the SNS/SQS resources Managed File Events needs.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ManagedFileEventsSetupStatement",
"Effect": "Allow",
"Action": [
"s3:GetBucketNotification",
"s3:PutBucketNotification",
"sns:CreateTopic",
"sns:Subscribe",
"sns:Publish",
"sqs:CreateQueue",
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:PurgeQueue"
],
"Resource": [
"arn:aws:s3:::<YOUR-BUCKET-NAME>",
"arn:aws:sqs:*:<YOUR-AWS-ACCOUNT-ID>:csms-*",
"arn:aws:sns:*:<YOUR-AWS-ACCOUNT-ID>:csms-*"
]
},
{
"Sid": "ManagedFileEventsListStatement",
"Effect": "Allow",
"Action": [
"sqs:ListQueues",
"sns:ListTopics"
],
"Resource": "*"
}
]
}
A couple of notes on that policy:
Now we connect Databricks to AWS using a storage credential and an external location.
With the real External ID in hand, update the role's trust policy so it only trusts this specific Databricks credential.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<YOUR-AWS-ACCOUNT-ID>:root"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "<YOUR-COPIED-EXTERNAL-ID>"
}
}
}
]
}
This is where the S3 path gets tied to the storage credential, and where file events get switched on.
With the infrastructure in place, this is what an Auto Loader stream using it looks like. The setting that matters is cloudFiles.useManagedFileEvents.
raw_source_stream_df = (
spark.readStream
.format("cloudFiles")
.option("cloudFiles.format", "csv")
.option("cloudFiles.schemaLocation", "/tmp/schema_location")
.option("cloudFiles.useManagedFileEvents", "true") # turns on Managed File Events
.option("cloudFiles.inferColumnTypes", "true")
.option("cloudFiles.schemaEvolutionMode", "addNewColumns")
.option("header", "true")
.load("s3://<YOUR-BUCKET-NAME>/path/to/data/")
)
(raw_source_stream_df
.writeStream
.format("delta")
.option("checkpointLocation", "/tmp/checkpoint_location")
.table("my_catalog.my_schema.my_table")
)
One thing worth knowing if you're on newer runtimes: starting with Databricks Runtime 18.1, Auto Loader picks up Managed File Events automatically when they're available on the external location (useManagedFileEvents defaults to if_available), so you may not need to set the option explicitly going forward. On 14.3 LTS through earlier 18.x runtimes, set it yourself as shown above.
This is a snapshot from one of my own pipelines after switching it over — each streaming table picks up and processes new records within seconds of them landing:
A few things worth knowing before you rely on this in production:
Managed File Events removes most of the operational overhead that came with classic file notification mode, without giving up the performance that made it worth using in the first place. Compared to directory listing and classic notifications, you get:
If you're setting up new Auto Loader pipelines on AWS today, or migrating existing ones off directory listing, this is the path Databricks recommends — and after running it in production for a while, I'd recommend it too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.