How do I troubleshoot Amazon EMR connectivity issues with AWS services?
I want to troubleshoot connectivity issues between my Amazon EMR cluster and AWS services.
Short description
Amazon EMR clusters can fail to connect to AWS services because of network, security, and configuration issues. If your Amazon EMR cluster has a connection failure, then you receive one of the following error messages:
- "Connection timed out"
- "Network is unreachable"
- "AmazonS3Exception: Connection pool shut down"
Note: If you have connectivity issues between your Amazon EMR cluster and external databases, then see How do I troubleshoot Amazon EMR connectivity issues with external databases?
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Go to the resolution section that matches your issue.
Resolve the "Connection timed out" error for AWS Glue Data Catalog connections
A network path must exist between the cluster and the AWS Glue endpoint. Also, Amazon EMR clusters in private subnets require Amazon Virtual Private Cloud (Amazon VPC) endpoints to connect to AWS Glue.
If your Amazon EMR cluster in a private subnet fails to connect to AWS Glue, then you receive the "Connection timed out" error message.
To resolve this error, take the following actions.
Create VPC endpoints for AWS Glue and Amazon S3
You must attach both an AWS Glue interface endpoint and an Amazon Simple Storage Service (Amazon S3) gateway endpoint to your cluster's VPC.
Complete the following steps:
- Open the Amazon VPC console.
- In the navigation pane, choose Endpoints.
- To create the AWS Glue interface endpoint, choose Create endpoint.
- For Type, choose AWS services.
- For Service name, choose com.amazonaws.YOUR_REGION.glue.
Note: Replace YOUR_REGION with your AWS Region. - For VPC, select the VPC that your Amazon EMR cluster runs on.
- For Subnets, select the subnets that your Amazon EMR cluster runs on.
- For Security groups, select a security group that allows inbound HTTPS on port 443.
- Choose Create endpoint.
- To create the Amazon S3 gateway endpoint, choose Create endpoint.
- For Type, choose AWS services.
- For Services, add the filter Type = Gateway, and then choose com.amazonaws.YOUR_REGION.s3.
Note: Replace YOUR_REGION with your Region. - For VPC, select the same VPC as your Amazon EMR cluster.
- For Route tables, select the route tables associated with your cluster subnets.
- Choose Create endpoint.
Configure AWS Glue VPC endpoint security groups
You must associate your security group with the AWS Glue VPC endpoint to allow inbound traffic on port 443 from the Amazon EMR cluster security groups.
Complete the following steps:
- Open the Amazon VPC console.
- In the navigation pane, choose Security groups.
- Select the security group that's associated with your AWS Glue VPC endpoint.
- Choose Actions, Edit inbound rules.
- Choose Add rule.
For Type, choose HTTPS.
For Source, enter the ID of the Amazon EMR primary node security group. - Choose Add rule.
For Type, choose HTTPS.
For Source, enter the ID of the Amazon EMR core and task node security group. - Choose Save rules.
Confirm Amazon EMR security group outbound rules
Amazon EMR primary and core security groups must allow outbound traffic on port 443.
Complete the following steps:
- Open the Amazon VPC console.
- In the navigation pane, choose Security groups.
- Select the Amazon EMR primary node security group.
- Choose the Outbound rules tab.
- Confirm that an outbound rule allows HTTPS traffic on port 443 to 0.0.0.0/0 or to the AWS Glue VPC endpoint security group ID.
Note: If a rule doesn't exist, then choose Edit outbound rules. Choose Add rule, and add the rule. Choose Save rules. - Repeat steps 3-5 for the Amazon EMR core and task node security group.
Test AWS Glue endpoint connectivity
To test connectivity to the AWS Glue endpoint, run the following command:
telnet glue.YOUR-REGION.amazonaws.com 443
Note: Replace YOUR-REGION with your Region.
Confirm the Spark configuration for AWS Glue Data Catalog
To confirm that Spark connects to AWS Glue Data Catalog, run the following pyspark script:
from pyspark.sql import SparkSession spark = SparkSession.builder \ .appName("Glue_Connection") \ .config("spark.hadoop.hive.metastore.client.factory.class", "com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory") \ .enableHiveSupport() \ .getOrCreate() df = spark.sql("SELECT * FROM glue_database.glue_table")
Resolve the "Network is unreachable" error for Secrets Manager and AWS STS connections
Amazon EMR clusters in private subnets can reach only AWS service endpoints with VPC endpoints or a NAT gateway.
Your Amazon EMR cluster in a private subnet can fail to reach AWS Secrets Manager or AWS Security Token Service (AWS STS). In this scenario, you receive the "Network is unreachable" error message.
To resolve this error, complete the following steps:
- Open the Amazon VPC console.
- In the navigation pane, choose Endpoints.
- Choose Create endpoint.
- For Type, choose AWS services.
- For Service name, choose com.amazonaws.REGION.secretsmanager.
Note: Replace REGION with your Region. - For VPC, select the VPC that your Amazon EMR cluster runs on.
- For Subnets, select the subnets that your Amazon EMR cluster runs on.
- For Security groups, choose a security group that allows inbound HTTPS on port 443 from the Amazon EMR security groups.
- Choose Create endpoint.
- To create the AWS STS endpoint, repeat steps 3-9, but for step 5, for Service name, choose com.amazonaws.REGION.sts.
- Confirm that the AWS Identity and Access Management (IAM) role for the Amazon Elastic Compute Cloud (Amazon EC2) instance profile for Amazon EMR grants permissions to call the required services. For example, the default EMR_EC2_DefaultRole role must include secretsmanager:GetSecretValue for Secrets Manager and sts:AssumeRole for AWS STS.
Note: For more information, see Configure IAM service roles for Amazon EMR permissions to AWS services and resources.
Resolve the "AmazonS3Exception: Connection pool shut down" error for Amazon EMR connections to Amazon S3
If your Amazon EMR cluster fails to connect to Amazon S3, then you receive the following error message:
"AmazonS3Exception: Connection pool shut down"
To resolve this error, complete the following steps:
- Open the Amazon VPC console.
- In the navigation pane, choose Endpoints.
- Choose Create endpoint.
- For Service category, choose AWS services.
- For Services, add the filter Type = Gateway, and then choose com.amazonaws.REGION.s3.
Note: Replace REGION with your Region. - For VPC, select the VPC that your Amazon EMR cluster runs on.
- For Route tables, select the route tables that are associated with your cluster subnets.
- Choose Create endpoint.
Note: It's a best practice to use the free endpoint for all VPCs for Amazon EMR. For Amazon EMR Serverless, the Amazon S3 gateway endpoint automatically configures. - Increase the Amazon S3 connection limit if you experience connection pool exhaustion with many concurrent tasks. Add the following property to your Spark configuration in a spark-defaults configuration classification when you create the cluster, or pass --conf to your spark-submit command:
spark.hadoop.fs.s3a.connection.maximum=200
Related information
Use AWS Glue Data Catalog with Spark on Amazon EMR
- Language
- English

Relevant content
- Accepted Answer
asked 6 years ago
asked 4 years ago
AWS OFFICIALUpdated 2 years ago