cancel
Showing results for 
Search instead for 
Did you mean: 
Technical Blog
Explore in-depth articles, tutorials, and insights on data analytics and machine learning in the Databricks Technical Blog. Stay updated on industry trends, best practices, and advanced techniques.
cancel
Showing results for 
Search instead for 
Did you mean: 
David_M
Databricks Partner

Contents

Introduction

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.

Understanding the Key Concepts

A few AWS and Databricks building blocks come up throughout this guide:

  • IAM Role: Allows Databricks to access specific AWS resources on your behalf based on the permissions granted to the role.
  • Amazon S3: the object storage where your source files land.
  • SNS (Simple Notification Service): publishes an event whenever a new file shows up in S3.
  • SQS (Simple Queue Service): the queue that holds those events until something reads them.
  • Unity Catalog Storage Credential: stores the IAM role details so Databricks can authenticate to AWS.
  • External Location: a Unity Catalog object that ties an S3 path to a storage credential, and is where file events get enabled.

Why File Notification with Managed File Events?

There are two flavors of file notification mode:

  • Classic File Notification — one SNS topic and SQS queue per Auto Loader stream.
  • File Notification with Managed File Events (recommended) — one shared queue per external location, used by every stream reading from it.

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.


Key Benefits of Managed File Events

  • Fewer quota headaches: one shared queue per external location instead of one per stream.
  • Less IAM to manage: fewer role policies to create and maintain in your AWS account.
  • No manual tuning: Databricks manages the resource tuning that you'd otherwise handle yourself with settings like cloudFiles.fetchParallelism.
  • Lower ingestion cost: fewer S3 LIST API calls than directory listing, and no per-stream queues to maintain.

Architecture Overview

At a high level, this is what happens each time a new file lands:

  1. A new file lands in S3.
  2. S3 sends an event to the shared SNS topic for that external location.
  3. SNS pushes the message to the shared SQS queue.
  4. The Databricks Managed File Events service — not your stream directly — polls the queue, caches the file metadata, and makes it available to any Auto Loader stream reading from that location.

David_M_4-1792673241401.png

For the full breakdown of how this works under the hood, see Databricks' own write-up: Auto Loader with file events overview.

Prerequisites

  • AWS Console access: Admin or IAM Admin permissions.
  • Databricks access: permission to create storage credential and external location objects in Unity Catalog.
  • An S3 bucket: the target bucket for your data.
  • Databricks Runtime 14.3 LTS or above: required for streams that use Managed File Events.

Phase 1: AWS IAM Setup

Step 1.1: Create the IAM Role with a Custom Trust Policy

  1. Log in to the AWS Console → IAM → Roles.
  2. Create role.
  3. Select Custom trust policy (bottom left).
  4. Paste the JSON below. We're using a placeholder 0000 for the External ID for now — we'll swap in the real one in Phase 2.
{
  "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"
        }
      }
    }
  ]
}
  1. Next.
  2. Role name: databricks-autoloader-role.
  3. Permissions: select Skip — we'll attach the policy in the next step.
  4. Create role.

Step 1.2: Create the IAM Policy

This policy grants the role permission to read S3 and to create and manage the SNS/SQS resources Managed File Events needs.

  1. IAM → Policies → Create policy.
  2. Open the JSON tab and clear the existing content.
  3. Paste the policy below, replacing the placeholders with your account ID and bucket name.
{
  "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:

  • csms-* is the prefix Databricks uses for the managed SNS topic and SQS queue it creates for you — leave that as-is.
  • Swap in your own AWS account ID and bucket name wherever the placeholders appear.
  1. Next → name it databricks-autoloader-policy → Create policy.

Step 1.3: Attach the Policy to the Role

  1. IAM → Roles → search for databricks-autoloader-role.
  2. Add permissions → Attach policies.
  3. Find databricks-autoloader-policy, check it, and click Add permissions.

Phase 2: Databricks Unity Catalog Setup

Now we connect Databricks to AWS using a storage credential and an external location.

David_M_5-1792673241406.png

Step 2.1: Create the Storage Credential

  1. Log in to your Databricks workspace.
  2. Catalog (left sidebar) → Connect → Credentials.
  3. Create credential → Storage credential.
  4. Name: cust-storage-cred.
  5. AWS IAM Role ARN: arn:aws:iam::<YOUR-AWS-ACCOUNT-ID>:role/databricks-autoloader-role.
  6. Create.
  7. A popup shows an External ID — copy it. You'll need it for the next step.
  8. Done.

Step 2.2: Update the AWS Trust Policy

With the real External ID in hand, update the role's trust policy so it only trusts this specific Databricks credential.

  1. AWS IAM → Roles → databricks-autoloader-role → Trust relationships tab → Edit policy.
  2. Replace "0000" with the External ID you copied.
{
  "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>"
        }
      }
    }
  ]
}
  1. Update policy.

Step 2.3: Create the External Location

This is where the S3 path gets tied to the storage credential, and where file events get switched on.

  1. Catalog → External Data → External Locations → Create external location.
  2. Name: cust-ext-loc.
  3. URL: s3://<YOUR-BUCKET-NAME>/.
  4. Storage credential: cust-storage-cred.
  5. Under Advanced options, make sure Enable file events is checked — it's on by default for new locations.
  6. Set File event type to Automatic (recommended) so Databricks provisions the SNS/SQS resources for you.
  7. Create.
  8. Click Test connection and confirm everything comes back green. If something fails, double check the IAM policy and bucket name.

David_M_6-1792673241408.png 

Phase 3: Ingesting Data with Managed File Events

With the infrastructure in place, this is what an Auto Loader stream using it looks like. The setting that matters is cloudFiles.useManagedFileEvents.

PySpark example

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.

What this looks like in practice

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:

David_M_7-1792673241408.png


A Few Configuration Notes

  • cloudFiles.useManagedFileEvents: setting this to "true" tells Auto Loader to read from the shared queue configured on the external location.
  • No queue URL needed: unlike classic mode, you don't set cloudFiles.queueUrl — Databricks handles that internally.
  • Schema evolution: the example above uses addNewColumns so new columns don't break the stream.

Best Practices

  • Use Managed File Events for any new Auto Loader workload.
  • Set schemaLocation to a stable, dedicated path per stream.
  • Always use checkpointing for streaming jobs.
  • Run your Auto Loader job at least once every 7 days, even against quiet directories (see Limitations below).
  • Avoid dumping large numbers of tiny files where possible — it affects any ingestion mode, not just this one.
  • Keep an eye on streaming metrics so you catch backlogs early.

Important Considerations & Limitations

A few things worth knowing before you rely on this in production:

  • Run your Auto Loader stream at least once every 7 days. Managed File Events keeps a cache of recent file metadata, and each stream saves its read position in its checkpoint so it can pick up where it left off. If the stream doesn't run for more than 7 days, that saved position is no longer valid, so the next run does a full directory listing to catch up with the cache. The stream still works, it's just a slower, more expensive run. This isn't a limit on how long a stream can keep running. A stream that runs continuously isn't affected. It only matters for scheduled jobs that might sit idle. Best practice: schedule the job to run at least once a week, even if you don't expect new data.
  • Other times a full directory listing happens. Auto Loader also does a full listing the first time a stream runs (including when you migrate from directory listing or classic file notification), and when a change to the external location invalidates the read position, for example turning file events off and on again, changing the location's path, or providing a different queue.

Conclusion

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:

  • Faster file discovery
  • Fewer S3 LIST calls
  • Less infrastructure to manage per stream
  • Better scalability as you add streams
  • Simpler IAM

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.

References

Databricks Documentation

AWS Documentation

2 Comments
Aravind_Reddy
Databricks Partner

Hi @David_M, 

Thanks for sharing this implementation guide! For teams migrating existing Auto Loader streams from classic file notifications to Managed File Events, what migration approach would you recommend to avoid duplicate or missed file processing?

Does the existing checkpoint preserve the stream's processing state seamlessly, or should teams plan for a full directory listing during the initial migration? It would be helpful to understand the recommended approach for large S3 directories with active production pipelines.

data_pulse
Contributor

@David_M 

Great walkthrough, thanks for sharing! Here are a few lessons learnt while enabling managed file events on existing streams. I thought I'd share them in case they’re worth adding to your article, particularly under Best Practices.

The issue:

After setting cloudFiles.useManagedFileEvents = true on several existing streams, one failed with:

[FAILED_READ_FILE.NO_HINT] Error while reading file
<checkpoint>/sources/0/rocksdb/*.zip

Reverting the option didn’t help, and the error looked like checkpoint corruption.

Root cause:

checkpointLocation was nested inside the monitored source path. Auto Loader discovered its own RocksDB artifacts (.zip, .log) and tried to read them in the configured source format (parquet), which failed. This is the file reader failing on a discovered file, not a state-store restore problem.

Fix

  • Filter discovered files by extension so checkpoint artifacts are never read:
reader_options = {
    "cloudFiles.useManagedFileEvents": "true",
    "pathGlobFilter": "*.parquet",   # *.json / *.csv etc. per format
}​
  • Keep checkpointLocation and cloudFiles.schemaLocation outside the monitored source directory.

Suggested additions to Best Practices

  • Keep checkpoint and schema locations outside the load path.
  • Set pathGlobFilter as a safety net, even when paths are separated.
  • When migrating existing streams, audit checkpoint locations first. The first run does a full directory listing of the load path, which is a likely point for nested checkpoint files to be picked up.
  • On DBR 18.1+, useManagedFileEvents defaults to if_available, so a runtime upgrade can switch existing streams to this mode without a config change. Worth auditing before upgrading.