Skip to content

Commit 6d75e21

Browse files
authored
Add monitoring configuration to emr create-cluster (#9891)
1 parent 4495555 commit 6d75e21

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

awscli/customizations/emr/argumentschema.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,47 @@
868868
}
869869
},
870870
}
871+
872+
MONITORING_CONFIGURATION_SCHEMA = {
873+
"type": "object",
874+
"properties": {
875+
"CloudWatchLogConfiguration": {
876+
"type": "object",
877+
"description": "CloudWatch log configuration settings and metadata that specify settings like log files to monitor and where to send them.",
878+
"properties": {
879+
"Enabled": {
880+
"type": "boolean",
881+
"description": "Specifies if CloudWatch logging is enabled.",
882+
"required": True
883+
},
884+
"LogGroupName": {
885+
"type": "string",
886+
"description": "The name of the CloudWatch log group where logs are published."
887+
},
888+
"LogStreamNamePrefix": {
889+
"type": "string",
890+
"description": "The prefix of the log stream name."
891+
},
892+
"EncryptionKeyArn": {
893+
"type": "string",
894+
"description": "The ARN of the encryption key used to encrypt the logs."
895+
},
896+
"LogTypes": {
897+
"type": "map",
898+
"key": {
899+
"type": "string",
900+
"description": "Log type category"
901+
},
902+
"value": {
903+
"type": "array",
904+
"items": {
905+
"type": "string"
906+
},
907+
"description": "File names (STDOUT or STDERR) for the log type"
908+
},
909+
"description": "A map of log types to file names for publishing logs to the standard output or standard error streams for CloudWatch. Valid log types include STEP_LOGS, SPARK_DRIVER, and SPARK_EXECUTOR. Valid file names for each type include STDOUT and STDERR."
910+
}
911+
}
912+
}
913+
}
914+
}

awscli/customizations/emr/createcluster.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ class CreateCluster(Command):
212212
'schema': argumentschema.AUTO_TERMINATION_POLICY_SCHEMA,
213213
'help_text': helptext.AUTO_TERMINATION_POLICY,
214214
},
215+
{
216+
'name': 'monitoring-configuration',
217+
'schema': argumentschema.MONITORING_CONFIGURATION_SCHEMA,
218+
'help_text': helptext.MONITORING_CONFIGURATION,
219+
},
215220
{
216221
'name': 'extended-support',
217222
'action': 'store_true',
@@ -553,6 +558,13 @@ def _run_main_command(self, parsed_args, parsed_globals):
553558
parsed_args.auto_termination_policy,
554559
)
555560

561+
if parsed_args.monitoring_configuration is not None:
562+
emrutils.apply_dict(
563+
params,
564+
'MonitoringConfiguration',
565+
parsed_args.monitoring_configuration,
566+
)
567+
556568
self._validate_required_applications(parsed_args)
557569

558570
run_job_flow_response = emrutils.call(

awscli/customizations/emr/helptext.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,3 +570,13 @@
570570
)
571571

572572
EXTENDED_SUPPORT = '<p>Reserved.</p> '
573+
574+
MONITORING_CONFIGURATION = (
575+
'<p>Monitoring configuration for an Amazon EMR cluster. '
576+
'The configuration specifies CloudWatch logging settings for the cluster. '
577+
'You can configure the CloudWatchLogConfiguration which includes '
578+
'the Enabled flag (required), LogGroupName, LogStreamNamePrefix, '
579+
'EncryptionKeyArn, and LogTypes. The LogTypes parameter is a map '
580+
'of log type categories (e.g., "STEP_LOGS", "SPARK_DRIVER", '
581+
'"SPARK_EXECUTOR") to a list of file names (e.g., "STDOUT", "STDERR").</p>'
582+
)

tests/unit/customizations/emr/test_create_cluster_release_label.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,39 @@ def test_create_cluster_with_auto_termination_policy(self):
18281828
}
18291829
self.assert_params_for_cmd(cmd, result)
18301830

1831+
def test_create_cluster_with_monitoring_configuration(self):
1832+
cmd = (
1833+
self.prefix
1834+
+ '--release-label emr-5.34.0 '
1835+
+ '--monitoring-configuration '
1836+
+ 'CloudWatchLogConfiguration={Enabled=true,LogGroupName=MyLogGroup,'
1837+
+ 'LogStreamNamePrefix=MyPrefix,EncryptionKeyArn=arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012,'
1838+
+ 'LogTypes={STEP_LOGS=[STDOUT,STDERR],SPARK_DRIVER=[STDOUT],SPARK_EXECUTOR=[STDERR]}} '
1839+
+ '--instance-groups '
1840+
+ DEFAULT_INSTANCE_GROUPS_ARG
1841+
)
1842+
result = {
1843+
'Name': DEFAULT_CLUSTER_NAME,
1844+
'Instances': DEFAULT_INSTANCES,
1845+
'ReleaseLabel': 'emr-5.34.0',
1846+
'VisibleToAllUsers': True,
1847+
'Tags': [],
1848+
'MonitoringConfiguration': {
1849+
'CloudWatchLogConfiguration': {
1850+
'Enabled': True,
1851+
'LogGroupName': 'MyLogGroup',
1852+
'LogStreamNamePrefix': 'MyPrefix',
1853+
'EncryptionKeyArn': 'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012',
1854+
'LogTypes': {
1855+
'STEP_LOGS': ['STDOUT', 'STDERR'],
1856+
'SPARK_DRIVER': ['STDOUT'],
1857+
'SPARK_EXECUTOR': ['STDERR'],
1858+
},
1859+
},
1860+
},
1861+
}
1862+
self.assert_params_for_cmd(cmd, result)
1863+
18311864
def test_create_cluster_with_log_encryption_kms_key_id(self):
18321865
test_log_uri = 's3://test/logs'
18331866
test_log_encryption_kms_key_id = 'valid_kms_key'

0 commit comments

Comments
 (0)