Configure Amazon EMR cluster logging and debugging
One of the things to decide as you plan your cluster is how much debugging support you want to make available. When you are first developing your data processing application, we recommend testing the application on a cluster processing a small, but representative, subset of your data. When you do this, you will likely want to take advantage of all the debugging tools that Amazon EMR offers, such as archiving log files to Amazon S3.
When you've finished development and put your data processing application into full production, you may choose to scale back debugging. Doing so can save you the cost of storing log file archives in Amazon S3 and reduce processing load on the cluster as it no longer needs to write state to Amazon S3. The trade off, of course, is that if something goes wrong, you'll have fewer tools available to investigate the issue.
Default log files
By default, each cluster writes log files on the primary node. These are written
to the /mnt/var/log/
directory. You can access them by using SSH to
connect to the primary node as described in Connect to the Amazon EMR cluster primary node using
SSH.
Amazon EMR collects certain system and applications logs generated by Amazon EMR daemons and other Amazon EMR processes to
ensure effective service operations.
Note
If you use Amazon EMR release 6.8.0 or earlier, log files are saved to Amazon S3 during cluster termination, so you can't access the log files once the primary node terminates. Amazon EMR releases 6.9.0 and later archive logs to Amazon S3 during cluster scale-down, so log files generated on the cluster persist even after the node is terminated.
You do not need to enable anything to have log files written on the primary node. This is the default behavior of Amazon EMR and Hadoop.
A cluster generates several types of log files, including:
-
Step logs — These logs are generated by the Amazon EMR service and contain information about the cluster and the results of each step. The log files are stored in
/mnt/var/log/hadoop/steps/
directory on the primary node. Each step logs its results in a separate numbered subdirectory:/mnt/var/log/hadoop/steps/s-
for the first step,stepId1
//mnt/var/log/hadoop/steps/s-
, for the second step, and so on. The 13-character step identifiers (e.g. stepId1, stepId2) are unique to a cluster.stepId2
/ -
Hadoop and YARN component logs — The logs for components associated with both Apache YARN and MapReduce, for example, are contained in separate folders in
/mnt/var/log
. The log file locations for the Hadoop components under/mnt/var/log
are as follows: hadoop-hdfs, hadoop-mapreduce, hadoop-httpfs, and hadoop-yarn. The hadoop-state-pusher directory is for the output of the Hadoop state pusher process. -
Bootstrap action logs — If your job uses bootstrap actions, the results of those actions are logged. The log files are stored in /mnt/var/log/bootstrap-actions/ on the primary node. Each bootstrap action logs its results in a separate numbered subdirectory:
/mnt/var/log/bootstrap-actions/1/
for the first bootstrap action,/mnt/var/log/bootstrap-actions/2/
, for the second bootstrap action, and so on. -
Instance state logs — These logs provide information about the CPU, memory state, and garbage collector threads of the node. The log files are stored in
/mnt/var/log/instance-state/
on the primary node.
Archive log files to Amazon S3
Note
You cannot currently use log aggregation to Amazon S3 with the yarn logs
utility.
Amazon EMR releases 6.9.0 and later archive logs to Amazon S3 during cluster scale-down, so log files generated on the cluster persist even after the node is terminated. This behavior is enabled automatically, so you don't need to do anything to turn it on. For Amazon EMR releases 6.8.0 and earlier, you can configure a cluster to periodically archive the log files stored on the primary node to Amazon S3. This ensures that the log files are available after the cluster terminates, whether this is through normal shut down or due to an error. Amazon EMR archives the log files to Amazon S3 at 5 minute intervals.
To have the log files archived to Amazon S3 for Amazon EMR releases 6.8.0 and earlier, you must enable this feature when you launch the cluster. You can do this using the console, the CLI, or the API. By default, clusters launched using the console have log archiving enabled. For clusters launched using the CLI or API, logging to Amazon S3 must be manually enabled.
To encrypt log files stored in Amazon S3 with an AWS KMS customer managed key
With Amazon EMR version 5.30.0 and later (except Amazon EMR 6.0.0), you can encrypt log files stored in Amazon S3 with an AWS KMS customer managed key. To enable this option in the console, follow the steps in Archive log files to Amazon S3. Your Amazon EC2 instance profile and your Amazon EMR role must meet the following prerequisites:
-
The Amazon EC2 instance profile used for your cluster must have permission to use
kms:GenerateDataKey
. -
The Amazon EMR role used for your cluster must have permission to use
kms:DescribeKey
. -
The Amazon EC2 instance profile and Amazon EMR role must be added to the list of key users for the specified AWS KMS customer managed key, as the following steps demonstrate:
-
Open the AWS Key Management Service (AWS KMS) console at https://console.aws.amazon.com/kms
. -
To change the AWS Region, use the Region selector in the upper-right corner of the page.
-
Select the alias of the KMS key to modify.
-
On the key details page under Key Users, choose Add.
-
In the Add key users dialog box, select your Amazon EC2 instance profile and Amazon EMR role.
-
Choose Add.
-
For more information, see IAM service roles used by Amazon EMR, and Using key policies in the AWS Key Management Service developer guide.
To aggregate logs in Amazon S3 using the AWS CLI
Note
You cannot currently use log aggregation with the yarn logs
utility. You can only use aggregation supported by this procedure.
Log aggregation (Hadoop 2.x) compiles logs from all containers for an individual application into a single file. To enable log aggregation to Amazon S3 using the AWS CLI, you use a bootstrap action at cluster launch to enable log aggregation and to specify the bucket to store the logs.
-
To enable log aggregation create the following configuration file called
myConfig.json
that contains the following:[ { "Classification": "yarn-site", "Properties": { "yarn.log-aggregation-enable": "true", "yarn.log-aggregation.retain-seconds": "-1", "yarn.nodemanager.remote-app-log-dir": "s3:\/\/
DOC-EXAMPLE-BUCKET
\/logs" } } ]Type the following command and replace
with the name of your EC2 key pair. You can additionally replace any of the red text with your own configurations.myKey
aws emr create-cluster --name "
Test cluster
" \ --release-labelemr-7.5.0
\ --applications Name=Hadoop
\ --use-default-roles \ --ec2-attributes KeyName=myKey
\ --instance-typem5.xlarge
\ --instance-count3
\ --configurations file://./myConfig.jsonWhen you specify the instance count without using the
--instance-groups
parameter, a single primary node is launched, and the remaining instances are launched as core nodes. All nodes will use the instance type specified in the command.Note
If you have not previously created the default EMR service role and EC2 instance profile, run
aws emr create-default-roles
to create them before running thecreate-cluster
subcommand.
For more information on using Amazon EMR commands in the AWS CLI, see AWS CLI Command Reference.
Log locations
The following list includes all log types and their locations in Amazon S3. You can use these for troubleshooting Amazon EMR issues.
- Step logs
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/steps/<step-id>
/ - Application logs
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/containers/This location includes container
stderr
andstdout
,directory.info
,prelaunch.out
, andlaunch_container.sh
logs. - Resource manager logs
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/node/<leader-instance-id>
/applications/hadoop-yarn/ - Hadoop HDFS
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/node/<all-instance-id>
/applications/hadoop-hdfs/This location includes NameNode, DataNode, and YARN TimelineServer logs.
- Node manager logs
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/node/<all-instance-id>
/applications/hadoop-yarn/ - Instance-state logs
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/node/<all-instance-id>
/daemons/instance-state/ - Amazon EMR provisioning logs
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/node/<leader-instance-id>
/provision-node/* - Hive logs
-
s3://
DOC-EXAMPLE-LOG-BUCKET
/<cluster-id>
/node/<leader-instance-id>
/applications/hive/*-
To find Hive logs on your cluster, remove the asterisk (
*
) and append/var/log/hive/
to the above link. -
To find HiveServer2 logs, remove the asterisk (
*
) and appendvar/log/hive/hiveserver2.log
to the above link. -
To find HiveCLI logs, remove the asterisk (
*
) and append/var/log/hive/user/hadoop/hive.log
to the above link. -
To find Hive Metastore Server logs, remove the asterisk (
*
) and append/var/log/hive/user/hive/hive.log
to the above link.
If your failure is in the primary or task node of your Tez application, provide logs of the appropriate Hadoop container.
-