

# Getting started with data lineage

On supported releases, Amazon EMR and AWS Glue send lineage for jobs that write data. Use this page to confirm that your jobs can send lineage and to view your first lineage graph. For a hands-on walkthrough, see [Test drive data lineage (tutorial)](catalog-lineage-tutorial.md).

## Prerequisites
<a name="prerequisites"></a>
+ An AWS account in a Region that supports AWS Glue Data Catalog Lineage.
+ A job on a supported release: Amazon EMR emr-spark-8.2.0 or later, or AWS Glue 6.1 or later.
+ A database in the AWS Glue Data Catalog that the job writes to.

## Step 1: Grant the lineage permission to your job roles
<a name="step-1-grant-the-lineage-permission-to-your-job-roles"></a>

Each lineage event is signed with the credentials of the role that runs the job. That role needs the `glue:PostLineageEvent` permission. If the role doesn't have it, the job runs normally but doesn't send lineage.

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": "*"
    }
  ]
}
```

For which role sends events on each deployment option, see [Permissions to send lineage](catalog-lineage-permissions.md#permissions-to-send-lineage).

## Step 2: Connect private subnets to AWS Glue
<a name="step-2-connect-private-subnets-to-aws-glue"></a>

Jobs in private subnets need a route to the AWS Glue endpoint. If your jobs already read tables from the Data Catalog in that subnet, the route usually exists.
+ **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 (port 443) from your job subnets. If you attach an endpoint policy, it must allow `glue:PostLineageEvent`.
+ **Amazon EMR on EC2.** Amazon EMR creates the endpoint for you when a cluster launches in a private subnet without one.
+ **AWS Glue.** AWS Glue jobs send lineage through the AWS Glue managed network path, so no change is needed.

## Step 3: Run a job
<a name="step-3-run-a-job"></a>

Run a job or query that writes to a table in the Data Catalog, for example:

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

## Step 4: View the lineage graph
<a name="step-4-view-the-lineage-graph"></a>

After lineage processing completes, open the output table in the AWS Glue console and choose the **Lineage** tab. The graph shows the job, its input tables, and the output table. For other options, see [Viewing data lineage](catalog-lineage-view.md).

You can also read the node with the AWS CLI:

```bash
aws glue get-lineage-node \
  --identifier arn:aws:glue:us-east-1:111122223333:table/analytics/daily_sales \
  --region us-east-1
```

## Step 5 (optional): Turn on the lineage system table
<a name="step-5-optional-turn-on-the-lineage-system-table"></a>

To query lineage events with SQL, turn on the lineage system table from Glue Data Catalog console settings. For details, see [Turning on the lineage system table](catalog-lineage-system-table-enable.md).

## Next steps
<a name="next-steps"></a>
+ [Permissions required for data lineage](catalog-lineage-permissions.md)
+ [Turning lineage capture on or off](catalog-lineage-opt-out.md)
+ [Publishing lineage from third-party and open-source sources](catalog-lineage-third-party.md)