Skip to main content
Glama
Amazon EMR Log Analysis MCP Server

Amazon EMR Log Analysis MCP Server

by aws-samples
README.md
# Amazon EMR Log Analysis MCP Server

The Amazon EMR Log Analysis Model Context Protocol (MCP) server provides the capability to identify EMR issues by analyzing log files stored in Amazon Simple Storage Service (Amazon S3). It offers an integrated knowledge base of known issues and curated recommendations across Apache Spark, Hadoop YARN and HDFS, Apache Hive, Apache HBase, and Presto frameworks. It includes tools to perform ad-hoc log analysis of user provided log snippets and to query log files for existing EMR log files that are stored in Amazon S3.

## Features

- **Curated Knowledge Base**: 150+ known EMR issues across Spark, YARN, Hadoop, Hive, HBase, Presto, and EMR service components with AWS Support Knowledge Center links when available
- **EMR Cluster Analysis**: Automatically discovers logs in S3 for provided EMR Cluster ID and uses Amazon Athena for optimized SQL queries across log files to identify known issues and provided aggregrated recommendations on top findings
- **Ad-hoc Log Analysis**: Analyze user-provided log snippets directly in chat to provide recommendations

## Prerequisites

1. This MCP server runs locally on the same host as your LLM client.
2. Set up AWS Identity and Access Management (IAM) credentials with access to EMR, Athena, and S3.
3. Publish cluster-specific logs to S3.
4. Athena query editor configured.

## Available Tools

- `analyze_emr_logs` - Analyzes EMR log content that is provided directly in chat for quick issue identification
- `analyze_emr_cluster_logs` - Discovers EMR cluster logs in S3 and performs analysis using Athena

## Usage

Once configured, you can ask your AI assistant to analyze EMR logs and troubleshoot issues:

- **"Analyze the logs for EMR cluster j-XXXX"**
- **"What issues are present in this EMR log?"**

## Installation

1. Clone the repository:
   ```bash
   git clone https://github.com/aws-samples/sample-emr-log-analysis-mcp.git
   cd sample-emr-log-analysis-mcp
   ```

2. Create and activate a virtual environment using UV:
   ```bash
   uv venv
   source .venv/bin/activate  # On Windows: .venv\Scripts\activate
   ```

3. Install the package:
   ```bash
   uv pip install -e .
   ```

4. Configure the MCP server in your LLM client such as Amazon Q for command line
   * For Amazon Q CLI, update MCP Config in `~/.aws/amazonq/mcp.json`
   * For Cline, click on "Configure MCP Servers" option from MCP tab

   ```json
   {
     "mcpServers": {
       "emr-log-analysis-mcp": {
         "autoApprove": [
           "analyze_emr_logs",
           "analyze_emr_cluster_logs"
         ],
         "disabled": false,
         "timeout": 60,
         "type": "stdio",
         "command": "uv",
         "args": ["run", "--directory", "/path/to/sample-emr-log-analysis-mcp", "python", "-m", "emr_log_analysis.server"],
         "env": {
           "AWS_PROFILE": "your-aws-profile",
           "AWS_REGION": "us-east-1",
           "FASTMCP_LOG_LEVEL": "ERROR"
         }
       }
     }
   }
   ```


## Security Considerations

### Required IAM Permissions
The AWS credentials used by the user running the MCP server need the following permissions:
```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "EMRAccess",
      "Effect": "Allow",
      "Action": [
        "emr:DescribeCluster"
      ],
      "Resource": "arn:aws:emr:*:*:cluster/*"
    },
    {
      "Sid": "AthenaAccess",
      "Effect": "Allow",
      "Action": [
        "athena:StartQueryExecution",
        "athena:GetQueryExecution",
        "athena:GetQueryResults",
        "athena:StopQueryExecution"
      ],
      "Resource": [
        "arn:aws:athena:*:*:workgroup/primary",
        "arn:aws:athena:*:*:workgroup/emr-log-analysis"
      ]
    },
    {
      "Sid": "S3Access",
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetObject",
        "s3:PutObject",
        "s3:CreateBucket"
      ],
      "Resource": [
        "arn:aws:s3:::aws-logs-*",
        "arn:aws:s3:::aws-logs-*/*",
        "arn:aws:s3:::emr-log-analysis-*",
        "arn:aws:s3:::emr-log-analysis-*/*"
      ]
    },
    {
      "Sid": "GlueAccess",
      "Effect": "Allow",
      "Action": [
        "glue:CreateDatabase",
        "glue:CreateTable",
        "glue:DeleteDatabase"
      ],
      "Resource": [
        "arn:aws:glue:*:*:database/emr_analysis_*",
        "arn:aws:glue:*:*:table/emr_analysis_*/*"
      ]
    },
    {
      "Sid": "STSAccess",
      "Effect": "Allow",
      "Action": [
        "sts:GetCallerIdentity"
      ],
      "Resource": "*"
    }
  ]
}
```

### Log Data Protection
- **Enable S3 encryption** on EMR log buckets using server-side encryption (AES-256 or KMS)
- **Enable Amazon CloudTrail** to audit log access and analysis activities
- **Use VPC endpoints** for S3 and Athena to keep traffic private (recommended for sensitive data)
- **EMR logs may contain sensitive information** such as data samples, SQL queries, and configuration details

### Environment-Specific AWS Profiles
Configure seperate AWS profiles based on your environment type (for example):

```bash
# Development - broader permissions for testing
export AWS_PROFILE=emr-dev
export AWS_REGION=us-east-1

# Production - restricted access with monitoring
export AWS_PROFILE=emr-prod
export AWS_REGION=us-east-1


## Troubleshooting
- If you encounter issues, verify your IAM permissions

## License

This project is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file for details.

TDQS

A3.6/5.0

Scored across 2 tools

Disambiguation4/5

Both tools analyze EMR logs, so their names are close and an ambiguous request could cause misselection. However, the descriptions clearly separate direct log-text analysis from S3/Athena-based cluster log analysis, and each states distinct inputs and response formats.

Naming Consistency5/5

Both names follow the same snake_case verb_noun pattern: analyze_emr_logs and analyze_emr_cluster_logs. The shared prefix also makes their relationship predictable.

Tool Count4/5

Two tools is slightly thin, but the server has a narrow purpose and each tool covers a distinct analysis mode. Both are substantive and earn their place rather than appearing redundant.

Completeness4/5

The surface covers the two primary workflows: analyzing supplied logs and analyzing cluster logs stored in S3 via Athena. Minor supporting operations such as listing clusters, discovering log locations, or retrieving raw logs are absent, but agents can work around these with external AWS tooling.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues