> ## Content Index
> Fetch the complete content index at: https://scriptcrunch.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Script To Retrieve AWS EMR Master IP Address
- URL: https://scriptcrunch.com/script-retrieve-aws-emr-master-ip/
- Published: 2020-07-28T17:13:03.000Z
- Updated: 2026-06-23T08:56:08.000Z
- Author: Scriptcrunch Editorial
- Tags: DevOps, Guides, Python, #Migrated-1758801465347, #wp, #wp-post, #Import 2025-09-25 11:57

Somtimes it is required to fetch the EMR master IP dynamically for automation.

One such use case is connecting [AWS](https://scriptcrunch.com/tag/aws/) Sagemaker notebook instances to EMR with Livy. For this, you need to have the EMR master's private IP address to be configured in the Sparkmagic configurations.

### Prerequisites

1. Python3
2. Boto3 installation
3. Valid AWS CLI access to EMR Cluster services.

## Python boto3 Script To Retrieve EMR Master IP

Here is the [python](https://scriptcrunch.com/tag/python/) script that will retrieve the EMR master's private IP address using the EMR cluster id as a parameter.

> **Note:**

```
import boto3
import json

boto_client_emr = boto3.client("emr")
cluster_id = "j-DFGDSFGREWG"

def get_emr_master_pvt_ip(boto_client_emr, cluster_id):
    emr_list_instance_rep = boto_client_emr.list_instances(
        ClusterId=cluster_id,
        InstanceGroupTypes=[
            'MASTER',
        ],
        InstanceStates=[
            'RUNNING',
        ]
    )
  
    return emr_list_instance_rep["Instances"][0]["PrivateIpAddress"]

emr_master_ip = get_emr_master_pvt_ip(boto_client_emr, cluster_id)

print("EMR master IP is" + " " + emr_master_ip)
```

### Module Requirements

1. This script uses [AWS boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html?ref=scriptcrunch.com) python module.
2. JSON module

### Script Input

The only input required for this script is the EMR cluster-ID. You can get this ID from the EMR cluster dashboard as shown below.

![](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/09/emr-id-min.png)

In the script it is shown as `cluster_id = "j-DFGDSFGREWG"`. When you execute the script, replace the ID with your EMR cluster ID.

### Script Usage

The following line of code stores the master IP in `emr_master_ip` variable.

```
emr_master_ip = get_emr_master_pvt_ip(boto_client_emr, cluster_id) 
```

You can use this variable as per your requirement.

`get_emr_master_pvt_ip` is the method which accepts the cluster ID variable.

If you execute the given code, you will get an output with a message showing the Master IP address. It comes from the print statement in the script.

Use python3 to execute the script as shown below.

```
➜  python3 emr.py
EMR master IP is 10.0.0.201
```