

# Lineage for Amazon EMR

Amazon EMR captures data lineage from Apache Spark jobs that write data and publishes it to the AWS Glue Data Catalog, so you can trace how data flows from table to table and column to column across jobs for impact analysis, debugging, and governance. Lineage capture is **enabled by default** with Amazon EMR release `emr-spark-8.2.0` and later, on Amazon EMR on EC2, Amazon EMR Serverless, and Amazon EMR on EKS, with some [Considerations and limitations](#catalog-lineage-emr-considerations-and-limitations). You don't install any additional library, change your job script, or set any job parameters.

## How it works
<a name="catalog-lineage-emr-how-it-works"></a>

When a cluster, application, or job starts, Amazon EMR adds the AWS Glue lineage library, an extended build of the OpenLineage Spark integration, to the Spark classpath and registers the OpenLineage Spark listener in the driver with the following configuration.


| Property | Value | 
| --- | --- | 
| spark.extraListeners | io.openlineage.spark.agent.OpenLineageSparkListener | 
| spark.openlineage.transport.type | amazon\_glue\_api | 
| spark.openlineage.transport.region | The Region where the job runs | 
| spark.glue.accountId | The AWS account ID that runs the job | 
| spark.openlineage.columnLineage.datasetLineageEnabled | true | 

Each time a Spark action writes data, the listener reads the query plan, builds an OpenLineage run event, and calls `PostLineageEvent` with the credentials of the role that runs the job. One Spark application sends one set of events for each write action.

The AWS Glue lineage library is built on version 1.49.0 of the open-source [OpenLineage Spark integration on the GitHub website](https://github.com/OpenLineage/OpenLineage/tree/1.49.0/integration/spark). AWS extends the library with the AWS Glue transport (`amazon_glue_api`), which sends events to the Data Catalog in requests signed with Signature Version 4. The library also supports fine-grained access control, and it adds AWS identity context that records the account and the roles that ran the job in each event. For details, see [aws\_runContext](#catalog-lineage-emr-aws-runcontext). Also, the [OpenLineage Spark documentation](https://openlineage.io/docs/integrations/spark/configuration/spark_conf/) contains additional Spark properties that you can set to further configure lineage.

Capture runs asynchronously in the Spark driver, so it doesn't change your job's results or add noticeable overhead. For details of the shared capture path, see [Automatic lineage capture from AWS services](catalog-lineage-aws-services.md).

After lineage events are published to the AWS Glue Data Catalog, you can view the lineage graphs and, optionally, persist the lineage events to S3 Tables. For instructions, see [Viewing data lineage](catalog-lineage-view.md) and [Turning on the lineage system table](catalog-lineage-system-table-enable.md).

**Note**  
AWS EMR adds `io.openlineage.spark.agent.OpenLineageSparkListener` to `spark.extraListeners` and removes duplicate entries. If your configuration already includes this listener, AWS EMR preserves your `spark.openlineage.*` settings.  
`spark.openlineage.transport.type` must be set to `amazon_glue_api`, which is the default destination. If you configure another transport type, the job doesn't publish lineage to AWS Glue Data Catalog.

## What Amazon EMR captures
<a name="catalog-lineage-emr-what-amazon-emr-captures"></a>

OpenLineage facets are structured metadata fields that add context to lineage entities and events, such as:
+ Spark SQL statements and DataFrame operations that create or change data, such as `CREATE TABLE AS SELECT`, `INSERT`, `MERGE`, `UPDATE`, `DELETE`, and DataFrame writes.
+ Data definition statements, such as `CREATE TABLE` and `ALTER TABLE`.
+ Input and output datasets. Tables in your Data Catalog resolve to their table ARN regardless of how the job refers to them, such as `orders`, `sales_db.orders`, or `awsdatacatalog.sales_db.orders`.
+ Column lineage, when Spark can derive it from the query plan.
+ Run context, including the account, Region, platform, cluster or application, Spark application ID, and the roles that run the job.

The full list can be found in the [OpenLineage Spark documentation](https://openlineage.io/docs/integrations/spark/configuration/spark_conf/).

## Prerequisites
<a name="catalog-lineage-emr-prerequisites"></a>

**Release**

Amazon EMR release `emr-spark-8.2.0` or later.

**Permission**

The role that runs the job needs `glue:PostLineageEvent`. Check that your role grants it, and add it to custom roles, including roles that you created before `emr-spark-8.2.0`.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowLineageEmission",
      "Effect": "Allow",
      "Action": "glue:PostLineageEvent",
      "Resource": "*"
    }
  ]
}
```

The role that runs the job, which sends lineage events, differs by deployment option.


| Deployment option | Role that sends lineage events | 
| --- | --- | 
| Amazon EMR on EC2 | The runtime role, for steps that use one. Otherwise, the cluster's EC2 instance profile. | 
| Amazon EMR Serverless | The job runtime role that you pass in --execution-role-arn. | 
| Amazon EMR on EKS | The job execution role. For jobs that use fine-grained access control, the query engine role in your security configuration. | 

If the role doesn't have the permission, the job runs normally, sends no lineage, and the driver log records a warning.

**Network**

Clusters and jobs in private subnets need a route to the AWS Glue endpoint. See [Connect private subnets to AWS Glue](#catalog-lineage-emr-connect-private-subnets-to-aws-glue).

## Connect private subnets to AWS Glue
<a name="catalog-lineage-emr-connect-private-subnets-to-aws-glue"></a>

Lineage uses the same AWS Glue endpoint as Data Catalog reads. If your jobs already reach Data Catalog tables from the subnet, the route exists. Check that any endpoint policy you attached also allows `glue:PostLineageEvent`.
+ **Amazon EMR on EC2.** Amazon EMR on EC2 provisions an AWS Glue interface VPC endpoint (with private DNS enabled) when a cluster launches in a private subnet that can't already reach AWS Glue, so lineage works without extra setup.
+ **Amazon EMR Serverless and Amazon EMR on EKS.** Create an interface VPC endpoint for AWS Glue with the service name `com.amazonaws.region.glue`. The endpoint's security group must allow inbound HTTPS on port 443 from your job subnets.

## View the lineage for a dataset
<a name="catalog-lineage-emr-view-the-lineage-for-a-dataset"></a>

Run a job that writes to a table in the Data Catalog.

```sql
CREATE TABLE analytics.daily_sales AS
SELECT order_date, sum(amount) AS total
FROM sales_db.orders
GROUP BY order_date;
```

**To view the lineage graph in the console**

1. Sign in to the AWS Management Console and open the AWS Glue console at [https://console.aws.amazon.com/glue/](https://console.aws.amazon.com/glue/).

1. In the navigation pane, choose **Data Catalog**, then choose **Tables**.

1. Choose the output table, `daily_sales`.

1. Choose the **Lineage** tab.

The graph shows the job, its input tables, and the output table. To retrieve the graph with the API or the AWS CLI, see [Viewing data lineage](catalog-lineage-view.md).

## Turn off lineage capture
<a name="catalog-lineage-emr-turn-off-lineage-capture"></a>

Set the Spark property `spark.openlineage.disabled` to `true` on the cluster, application, or job. The job runs normally and sends no lineage.

**Amazon EMR on EC2.** Add the property to the cluster or step configuration.

```json
[
  {
    "Classification": "spark-defaults",
    "Properties": { "spark.openlineage.disabled": "true" }
  }
]
```

**Amazon EMR Serverless.** Add the property to the job run.

```bash
aws emr-serverless start-job-run \
  --application-id 00example \
  --execution-role-arn arn:aws:iam::111122223333:role/MyJobRole \
  --job-driver '{"sparkSubmit":{"entryPoint":"s3://amzn-s3-demo-bucket/job.py","sparkSubmitParameters":"--conf spark.openlineage.disabled=true"}}'
```

**Amazon EMR on EKS.** Add the property to `sparkSubmitParameters` in the job run.

```bash
aws emr-containers start-job-run \
  --virtual-cluster-id 00example \
  --execution-role-arn arn:aws:iam::111122223333:role/MyJobRole \
  --release-label emr-spark-8.2.0 \
  --job-driver '{"sparkSubmitJobDriver":{"entryPoint":"s3://amzn-s3-demo-bucket/job.py","sparkSubmitParameters":"--conf spark.openlineage.disabled=true"}}'
```

To stop lineage for every job that uses a given role, deny `glue:PostLineageEvent` in an IAM policy or a service control policy.

### Turn off a facet
<a name="catalog-lineage-emr-turn-off-a-facet"></a>

Set `spark.openlineage.facets.facetName.disabled=true`. The job skips building that facet and keeps publishing lineage.

## Lineage facets added by Amazon EMR
<a name="catalog-lineage-emr-lineage-facets-added-by-amazon-emr"></a>

Amazon EMR extends the open-source OpenLineage Spark integration with five additional facets that record where a job ran, who ran it, what the query did, and which columns it read. They are on by default, need no configuration, and are additive: standard OpenLineage facets are unchanged. Unresolvable fields are omitted; generation is best-effort.


| Facet | Location in event | Purpose | 
| --- | --- | --- | 
| aws\_runContext | run.facets | Where the job ran and which identity ran it | 
| spark\_session | run.facets | The Spark session and SQL execution behind the event | 
| spark\_metrics | run.facets | Aggregate executor and memory metrics | 
| spark\_activityMetadata | job.facets | Functions referenced, Spark action, statement and query type | 
| columnsAccessed | inputs[].inputFacets | Columns and filters applied to each input dataset | 

### aws\_runContext
<a name="catalog-lineage-emr-aws-runcontext"></a>

Run facet recording the job's AWS location and identity. Resolved from service-set configuration and environment variables, with no network calls.


| Field | Type | Description | 
| --- | --- | --- | 
| accountId | string | Account that ran the job | 
| region | string | Region the job ran in | 
| platform | string | Required. GLUE\_ETL, EMR\_SERVERLESS, EMR\_ON\_EC2, EMR\_ON\_EKS, EMR\_MANAGED\_COMPUTE, or OTHER | 
| resourceId | string | Cluster ID (EMR on EC2), application ID (EMR Serverless), virtual cluster ID (EMR on EKS), or job name or session ID (AWS Glue) | 
| platformRunId | string | Step ID (EMR on EC2), job run ID (EMR Serverless, EMR on EKS, AWS Glue), or session or kernel ID for interactive runs | 
| identity | object | IAM and IAM Identity Center context. Omitted when no execution role resolves | 

`identity` fields:


| Field | Type | Description | 
| --- | --- | --- | 
| executionRole | string | Required. IAM role the job ran as | 
| submittedBy | string | Principal that submitted the job | 
| onBehalfOfUserId | string | IAM Identity Center user the job ran for | 
| onBehalfOfIdentityStoreArn | string | Identity store holding that user | 
| onBehalfOfSubject | string | Subject claim for that user | 
| onBehalfOfSubjectType | string | Type of the subject claim | 
| onBehalfOfIssuer | string | Identity provider that issued the claim | 
| onBehalfOfIdentityCenterInstanceArn | string | IAM Identity Center instance | 
| onBehalfOfType | string | Kind of on-behalf-of attribution | 

### spark\_session
<a name="catalog-lineage-emr-spark-session"></a>

Run facet linking the event to the session and SQL execution that produced it.


| Field | Type | Description | 
| --- | --- | --- | 
| sessionUUID | string | Required. Identifies the Spark session, distinct per session within one application | 
| executionId | long | Spark SQL execution ID, matching the Spark UI SQL tab. Omitted for non-SQL runs | 

### spark\_metrics
<a name="catalog-lineage-emr-spark-metrics"></a>

Run facet of metrics accumulated from completed tasks. Values are running totals at send time and are final on the run's last event, so compare runs using that event. Omitted when all three are zero, which means no task completed.


| Field | Type | Description | 
| --- | --- | --- | 
| distinctExecutors | integer | Distinct executors that ran tasks for the run | 
| peakTaskMemoryBytes | long | Highest peak execution memory on any single task, in bytes | 
| totalExecutorRunTimeMs | long | Executor run time summed across tasks, in milliseconds | 

### spark\_activityMetadata
<a name="catalog-lineage-emr-spark-activitymetadata"></a>

Job facet describing what the query did, derived from the query plan Spark ran. Omitted when no plan is available.


| Field | Type | Description | 
| --- | --- | --- | 
| functions | array | Required. Functions that the query referenced, for example PYTHON\_UDF or HIVE\_UDF. Empty when the query referenced none. | 
| sparkAction | string | Action that triggered execution, such as collect, count, or command. Omitted when Spark reports none | 
| statementType | string | Statement classification. Present only when sparkAction is absent | 
| queryType | string | What the query does to data, that is, READ, WRITE, READ\_WRITE, NONE, or UNKNOWN. | 

### columnsAccessed
<a name="catalog-lineage-emr-columnsaccessed"></a>

Input facet on each input dataset, scoped to that dataset alone. Derived after Spark optimizes the query, so it reports what Spark read from storage rather than what the query text named; pruned columns don't appear.


| Field | Type | Description | 
| --- | --- | --- | 
| columns | array of strings | Required. Columns the query projected, filtered, joined, grouped, or aggregated on | 
| filters | string | Predicates applied to this dataset, joined with AND. Omitted when none | 

**Considerations**
+ `filters` comes from the optimized plan, so it can differ from what you wrote. Spark folds constants and adds null checks, rendering `WHERE b > 30` as `((b > 30) AND isnotnull(b))`.
+ A filter spanning two joined tables appears on both datasets, because it constrains each read.
+ Columns used only by a filter the data source evaluates itself aren't reported. Apache Iceberg and other DataSource V2 sources apply such predicates during the scan, and Spark then drops both the filter and the column from the plan.
+ Under fine-grained access control, `columns` reports the authorized columns and `filters` still reports your predicates.
+ Streaming jobs attach the facet to every micro-batch. Turn it off on high-frequency streams if event size matters.

## Considerations and limitations
<a name="catalog-lineage-emr-considerations-and-limitations"></a>
+ **Amazon EMR on EKS operators.** Jobs that you submit with a Kubernetes operator, such as the Spark operator, don't publish lineage automatically. These jobs bypass the Amazon EMR control plane that adds the lineage configuration, so you must set the Spark properties explicitly.
+ **Fine-grained access control.** Jobs that use fine-grained access control can send lineage only with the `amazon_glue_api` transport. Other OpenLineage transports aren't supported. In FGAC mode, the system driver sends the lineage events.
+ **OpenLineage facets in FGAC mode.** Not all facets can be generated in system space because of security restrictions; namely, `spark_unknown`, `debug`, `spark.logicalPlan`, `spark.exception`, and `errorMessage`.

**Important**  
Lineage is best effort. Amazon EMR doesn't guarantee an event for every job run, for example when a role lacks permission or a request is throttled. Don't use lineage as a compliance audit log. For access auditing, use AWS CloudTrail and AWS Lake Formation audit logs.  
If your execution roles or instance profiles lack the `glue:PostLineageEvent` permission, `AccessDenied` errors for this action appear in CloudTrail and in the Spark driver's stderr logs. These errors don't fail your job; Spark simply logs them and continues. To silence these log messages, you can either [Turn off lineage capture](#catalog-lineage-emr-turn-off-lineage-capture) or grant the missing `glue:PostLineageEvent` permission.

For limitations that apply to every lineage source, including per-Region scope, see [Automatic lineage capture from AWS services](catalog-lineage-aws-services.md).

### Known issues in the OpenLineage Spark integration
<a name="catalog-lineage-emr-known-issues-in-the-openlineage-spark-integration"></a>

For known issues, see [open issues in the OpenLineage repository on the GitHub website](https://github.com/OpenLineage/OpenLineage/issues?q=is%3Aissue+is%3Aopen).

## Related documentation
<a name="catalog-lineage-emr-related-documentation"></a>
+ [What is data lineage in the AWS Glue Data Catalog?](catalog-lineage-what-is.md)
+ [Automatic lineage capture from AWS services](catalog-lineage-aws-services.md)
+ [Lineage for AWS Glue ETL jobs](catalog-lineage-glue-etl.md)
+ [Data lineage support matrix](catalog-lineage-support-matrix.md)
+ [Column-level lineage](catalog-lineage-column.md)
+ [Querying lineage with SQL using the lineage system table](catalog-lineage-system-table.md)
+ [Troubleshooting data lineage](catalog-lineage-troubleshooting.md)
+ [OpenLineage Spark integration on the GitHub website](https://github.com/OpenLineage/OpenLineage/tree/1.49.0/integration/spark)
+ [OpenLineage 1.49.0 release notes on the GitHub website](https://github.com/OpenLineage/OpenLineage/releases/tag/1.49.0)