本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用亚马逊的EMR示例 AWS CLI
以下代码示例向您展示了如何通过 AWS Command Line Interface 与 Amazon 一起使用来执行操作和实现常见场景EMR。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例显示了如何使用add-instance-fleet
。
- AWS CLI
-
向集群添加任务实例队列
此示例向指定的集群添加了一个新的任务实例队列。
命令:
aws emr add-instance-fleet --cluster-id '
j-12ABCDEFGHI34JK
' --instance-fleet InstanceFleetType=TASK,TargetSpotCapacity=1,LaunchSpecifications={SpotSpecification='{TimeoutDurationMinutes=20,TimeoutAction=TERMINATE_CLUSTER}'},InstanceTypeConfigs=['{InstanceType=m3.xlarge,BidPrice=0.5}']输出:
{ "ClusterId": "j-12ABCDEFGHI34JK", "InstanceFleetId": "if-23ABCDEFGHI45JJ" }
-
有关API详细信息,请参阅 “AddInstanceFleet AWS CLI
命令参考”。
-
以下代码示例显示了如何使用add-steps
。
- AWS CLI
-
1。向集群添加自定义JAR步骤
命令:
aws emr add-steps --cluster-id j-XXXXXXXX --steps Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,Jar=s3://mybucket/mytest.jar,Args=arg1,arg2,arg3 Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,Jar=s3://mybucket/mytest.jar,MainClass=mymainclass,Args=arg1,arg2,arg3
必填参数:
Jar
可选参数:
Type, Name, ActionOnFailure, Args
输出:
{ "StepIds":[ "s-XXXXXXXX", "s-YYYYYYYY" ] }
2。向集群添加流式处理步骤
命令:
aws emr add-steps --cluster-id j-XXXXXXXX --steps Type=STREAMING,Name='Streaming Program',ActionOnFailure=CONTINUE,Args=[-files,s3://elasticmapreduce/samples/wordcount/wordSplitter.py,-mapper,wordSplitter.py,-reducer,aggregate,-input,s3://elasticmapreduce/samples/wordcount/input,-output,s3://mybucket/wordcount/output]
必填参数:
Type, Args
可选参数:
Name, ActionOnFailure
JSON等效(step.json 的内容):
[ { "Name": "JSON Streaming Step", "Args": ["-files","s3://elasticmapreduce/samples/wordcount/wordSplitter.py","-mapper","wordSplitter.py","-reducer","aggregate","-input","s3://elasticmapreduce/samples/wordcount/input","-output","s3://mybucket/wordcount/output"], "ActionOnFailure": "CONTINUE", "Type": "STREAMING" } ]
NOTE: JSON 参数必须将选项和值作为它们自己的项目包含在列表中。
命令(使用 step.json):
aws emr add-steps --cluster-id j-XXXXXXXX --steps file://./step.json
输出:
{ "StepIds":[ "s-XXXXXXXX", "s-YYYYYYYY" ] }
3。向群集添加包含多个文件的流式处理步骤(JSON仅限)
JSON(multiplefiles.json):
[ { "Name": "JSON Streaming Step", "Type": "STREAMING", "ActionOnFailure": "CONTINUE", "Args": [ "-files", "s3://mybucket/mapper.py,s3://mybucket/reducer.py", "-mapper", "mapper.py", "-reducer", "reducer.py", "-input", "s3://mybucket/input", "-output", "s3://mybucket/output"] } ]
命令:
aws emr add-steps --cluster-id j-XXXXXXXX --steps file://./multiplefiles.json
必填参数:
Type, Args
可选参数:
Name, ActionOnFailure
输出:
{ "StepIds":[ "s-XXXXXXXX", ] }
4。向集群添加 Hive 步骤
命令:
aws emr add-steps --cluster-id j-XXXXXXXX --steps Type=HIVE,Name='Hive program',ActionOnFailure=CONTINUE,Args=[-f,s3://mybucket/myhivescript.q,-d,INPUT=s3://mybucket/myhiveinput,-d,OUTPUT=s3://mybucket/myhiveoutput,arg1,arg2] Type=HIVE,Name='Hive steps',ActionOnFailure=TERMINATE_CLUSTER,Args=[-f,s3://elasticmapreduce/samples/hive-ads/libs/model-build.q,-d,INPUT=s3://elasticmapreduce/samples/hive-ads/tables,-d,OUTPUT=s3://mybucket/hive-ads/output/2014-04-18/11-07-32,-d,LIBS=s3://elasticmapreduce/samples/hive-ads/libs]
必填参数:
Type, Args
可选参数:
Name, ActionOnFailure
输出:
{ "StepIds":[ "s-XXXXXXXX", "s-YYYYYYYY" ] }
5。向集群添加 Pig 步骤
命令:
aws emr add-steps --cluster-id j-XXXXXXXX --steps Type=PIG,Name='Pig program',ActionOnFailure=CONTINUE,Args=[-f,s3://mybucket/mypigscript.pig,-p,INPUT=s3://mybucket/mypiginput,-p,OUTPUT=s3://mybucket/mypigoutput,arg1,arg2] Type=PIG,Name='Pig program',Args=[-f,s3://elasticmapreduce/samples/pig-apache/do-reports2.pig,-p,INPUT=s3://elasticmapreduce/samples/pig-apache/input,-p,OUTPUT=s3://mybucket/pig-apache/output,arg1,arg2]
必填参数:
Type, Args
可选参数:
Name, ActionOnFailure
输出:
{ "StepIds":[ "s-XXXXXXXX", "s-YYYYYYYY" ] }
6。向集群添加 Impala 步骤
命令:
aws emr add-steps --cluster-id j-XXXXXXXX --steps Type=IMPALA,Name='Impala program',ActionOnFailure=CONTINUE,Args=--impala-script,s3://myimpala/input,--console-output-path,s3://myimpala/output
必填参数:
Type, Args
可选参数:
Name, ActionOnFailure
输出:
{ "StepIds":[ "s-XXXXXXXX", "s-YYYYYYYY" ] }
-
有关API详细信息,请参阅 “AddSteps AWS CLI
命令参考”。
-
以下代码示例显示了如何使用add-tags
。
- AWS CLI
-
1。向集群添加标签
命令:
aws emr add-tags --resource-id j-xxxxxxx --tags name="John Doe" age=29 sex=male address="123 East NW Seattle"
输出:
None
2。列出集群的标签
--命令:
aws emr describe-cluster --cluster-id
j-XXXXXXYY
--queryCluster.Tags
输出:
[ { "Value": "male", "Key": "sex" }, { "Value": "123 East NW Seattle", "Key": "address" }, { "Value": "John Doe", "Key": "name" }, { "Value": "29", "Key": "age" } ]
-
有关API详细信息,请参阅 “AddTags AWS CLI
命令参考”。
-
以下代码示例显示了如何使用create-cluster-examples
。
- AWS CLI
-
以下大多数示例都假设您指定了您的亚马逊EMR服务角色和亚马逊EC2实例配置文件。如果您尚未执行此操作,则必须指定每个必需的IAM角色或在创建集群时使用
--use-default-roles
参数。有关指定IAM角色的更多信息,请参阅《亚马逊EMR管理指南》中的为亚马逊 AWS 服务EMR权限配置IAM角色。示例 1:创建集群
以下
create-cluster
示例创建了一个简单的EMR集群。aws emr create-cluster \ --release-label
emr-5.14.0
\ --instance-typem4.large
\ --instance-count2
此命令不生成任何输出。
示例 2:创建具有默认 InstanceProfile 角色 ServiceRole 和角色的 Amazon EMR 集群
以下
create-cluster
示例创建了一个使用该--instance-groups
配置的 Amazon EMR 集群。aws emr create-cluster \ --release-label
emr-5.14.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
示例 3:创建使用实例队列的 Amazon EMR 集群
以下
create-cluster
示例创建了一个使用该--instance-fleets
配置的 Amazon EMR 集群,为每个队列指定两种实例类型和两个EC2子网。aws emr create-cluster \ --release-label
emr-5.14.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributes InstanceProfile=EMR_EC2_DefaultRole,SubnetIds=['subnet-ab12345c','subnet-de67890f'] \ --instance-fleets InstanceFleetType=MASTER,TargetOnDemandCapacity=1,InstanceTypeConfigs=['{InstanceType=m4.large}'] InstanceFleetType=CORE,TargetSpotCapacity=11,InstanceTypeConfigs=['{InstanceType=m4.large,BidPrice=0.5,WeightedCapacity=3}','{InstanceType=m4.2xlarge,BidPrice=0.9,WeightedCapacity=5}'],LaunchSpecifications={SpotSpecification='{TimeoutDurationMinutes=120,TimeoutAction=SWITCH_TO_ON_DEMAND}'}示例 4:创建具有默认角色的集群
以下
create-cluster
示例使用--use-default-roles
参数指定默认服务角色和实例配置文件。aws emr create-cluster \ --release-label
emr-5.9.0
\ --use-default-roles \ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 5:创建集群并指定要安装的应用程序
以下
create-cluster
示例使用--applications
参数指定 Amazon EMR 安装的应用程序。此示例安装了 Hadoop、Hive 和 Pig。aws emr create-cluster \ --applications
Name=Hadoop
Name=Hive
Name=Pig
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 6:创建包含 Spark 的集群
以下示例安装了 Spark。
aws emr create-cluster \ --release-label
emr-5.9.0
\ --applicationsName=Spark
\ --ec2-attributesKeyName=myKey
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 7:指定AMI用于集群实例的自定义
以下
create-cluster
示例基于 Amazon Linux 创建一个集群实例AMI,编号为ami-a518e6df
。aws emr create-cluster \ --name
"Cluster with My Custom AMI"
\ --custom-ami-idami-a518e6df
\ --ebs-root-volume-size20
\ --release-labelemr-5.9.0
\ --use-default-roles \ --instance-count2
\ --instance-typem4.large
示例 8:自定义应用程序配置
以下示例使用
--configurations
参数指定包含 Hadoop 应用程序自定义项的JSON配置文件。有关更多信息,请参阅 Amazon EMR 发行指南中的配置应用程序。configurations.json
的内容:[ { "Classification": "mapred-site", "Properties": { "mapred.tasktracker.map.tasks.maximum": 2 } }, { "Classification": "hadoop-env", "Properties": {}, "Configurations": [ { "Classification": "export", "Properties": { "HADOOP_DATANODE_HEAPSIZE": 2048, "HADOOP_NAMENODE_OPTS": "-XX:GCTimeRatio=19" } } ] } ]
以下示例以本地文件
configurations.json
形式引用。aws emr create-cluster \ --configurations
file://configurations.json
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate以下示例在 Amazon S3 中以文件
configurations.json
形式引用。aws emr create-cluster \ --configurations
https://s3.amazonaws.com/myBucket/configurations.json
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 9:创建包含主实例组、核心实例组和任务实例组的集群
以下
create-cluster
示例用于指定--instance-groups
用于主实例组、核心EC2实例组和任务实例组的实例类型和数量。aws emr create-cluster \ --release-label
emr-5.9.0
\ --instance-groupsName=Master,InstanceGroupType=MASTER,InstanceType=m4.large,InstanceCount=1
Name=Core,InstanceGroupType=CORE,InstanceType=m4.large,InstanceCount=2
Name=Task,InstanceGroupType=TASK,InstanceType=m4.large,InstanceCount=2
示例 10:指定集群应在完成所有步骤后终止
以下
create-cluster
示例--auto-terminate
用于指定集群应在完成所有步骤后自动关闭。aws emr create-cluster \ --release-label
emr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 11:指定集群配置详细信息,例如 Amazon EC2 key pair、网络配置和安全组
以下
create-cluster
示例使用名为 Amazon EC2 key pairmyKey
和名为的自定义实例配置文件创建集群myProfile
。密钥对用于授权与群集节点(通常是主节点)的SSH连接。有关更多信息,请参阅《亚马逊EMR管理指南》中的使用亚马逊EC2密钥对作为SSH凭证。aws emr create-cluster \ --ec2-attributes
KeyName=myKey,InstanceProfile=myProfile
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate以下示例在 Amazon VPC 子网中创建了一个集群。
aws emr create-cluster \ --ec2-attributes
SubnetId=subnet-xxxxx
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate以下示例在
us-east-1b
可用区中创建集群。aws emr create-cluster \ --ec2-attributes
AvailabilityZone=us-east-1b
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
以下示例创建了一个集群并仅指定了 Amazon EMR 托管的安全组。
aws emr create-cluster \ --release-label
emr-5.9.0
\ --service-rolemyServiceRole
\ --ec2-attributesInstanceProfile=myRole,EmrManagedMasterSecurityGroup=sg-master1,EmrManagedSlaveSecurityGroup=sg-slave1
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
以下示例创建了一个集群并仅指定了其他 Amazon EC2 安全组。
aws emr create-cluster \ --release-label
emr-5.9.0
\ --service-rolemyServiceRole
\ --ec2-attributesInstanceProfile=myRole,AdditionalMasterSecurityGroups=[sg-addMaster1,sg-addMaster2,sg-addMaster3,sg-addMaster4],AdditionalSlaveSecurityGroups=[sg-addSlave1,sg-addSlave2,sg-addSlave3,sg-addSlave4]
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
以下示例创建了一个集群并指定了EMR托管安全组以及其他安全组。
aws emr create-cluster \ --release-label
emr-5.9.0
\ --service-rolemyServiceRole
\ --ec2-attributesInstanceProfile=myRole,EmrManagedMasterSecurityGroup=sg-master1,EmrManagedSlaveSecurityGroup=sg-slave1,AdditionalMasterSecurityGroups=[sg-addMaster1,sg-addMaster2,sg-addMaster3,sg-addMaster4],AdditionalSlaveSecurityGroups=[sg-addSlave1,sg-addSlave2,sg-addSlave3,sg-addSlave4]
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
以下示例在VPC私有子网中创建集群并使用特定的 Amazon EC2 安全组启用 Amazon EMR 服务访问权限,这是私有子网中的集群所必需的。
aws emr create-cluster \ --release-label
emr-5.9.0
\ --service-rolemyServiceRole
\ --ec2-attributesInstanceProfile=myRole,ServiceAccessSecurityGroup=sg-service-access,EmrManagedMasterSecurityGroup=sg-master,EmrManagedSlaveSecurityGroup=sg-slave
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
以下示例使用存储在本地的名
ec2_attributes.json
为JSON的文件指定安全组配置参数。NOTE: JSON 参数必须将选项和值作为它们自己的项目包含在列表中。aws emr create-cluster \ --release-label
emr-5.9.0
\ --service-rolemyServiceRole
\ --ec2-attributesfile://ec2_attributes.json
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
ec2_attributes.json
的内容:[ { "SubnetId": "subnet-xxxxx", "KeyName": "myKey", "InstanceProfile":"myRole", "EmrManagedMasterSecurityGroup": "sg-master1", "EmrManagedSlaveSecurityGroup": "sg-slave1", "ServiceAccessSecurityGroup": "sg-service-access", "AdditionalMasterSecurityGroups": ["sg-addMaster1","sg-addMaster2","sg-addMaster3","sg-addMaster4"], "AdditionalSlaveSecurityGroups": ["sg-addSlave1","sg-addSlave2","sg-addSlave3","sg-addSlave4"] } ]
示例 12:启用调试并指定日志 URI
以下
create-cluster
示例使用--enable-debugging
参数,该参数允许您使用 Amazon EMR 控制台中的调试工具更轻松地查看日志文件。--log-uri
参数是必需的--enable-debugging
。aws emr create-cluster \ --enable-debugging \ --log-uri
s3://myBucket/myLog
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 13:在创建集群时添加标签
标签是键值对,可帮助您识别和管理集群。以下
create-cluster
示例使用--tags
参数为集群创建三个标签,一个带有密钥名称name
和值Shirley Rodriguez
,第二个标签包含密钥名称age
和值29
,第三个标签包含密钥名称department
和值Analytics
。aws emr create-cluster \ --tags name="Shirley Rodriguez"
age=29
department="Analytics" \ --release-labelemr-5.32.0
\ --instance-typem5.xlarge
\ --instance-count3
\ --use-default-roles以下示例列出了应用于集群的标签。
aws emr describe-cluster \ --cluster-id
j-XXXXXXYY
\ --queryCluster.Tags
示例 14:使用启用加密和其他安全功能的安全配置
以下
create-cluster
示例使用--security-configuration
参数为EMR集群指定安全配置。您可以在 Amazon 4.8.0 或EMR更高版本中使用安全配置。aws emr create-cluster \ --instance-type
m4.large
\ --release-labelemr-5.9.0
\ --security-configurationmySecurityConfiguration
示例 15:创建具有为实例组配置的额外EBS存储卷的集群
指定其他EBS卷时,需要以下参数:
VolumeType
,SizeInGB
如果EbsBlockDeviceConfigs
已指定。以下
create-cluster
示例创建了一个集群,其中的多个EBS卷连接到核心EC2实例组中的实例。aws emr create-cluster \ --release-label
emr-5.9.0
\ --use-default-roles \ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=d2.xlarge
'InstanceGroupType=CORE,InstanceCount=2,InstanceType=d2.xlarge,EbsConfiguration={EbsOptimized=true,EbsBlockDeviceConfigs=[{VolumeSpecification={VolumeType=gp2,SizeInGB=100}},{VolumeSpecification={VolumeType=io1,SizeInGB=100,Iops=100},VolumesPerInstance=4}]}
' \ --auto-terminate以下示例创建了一个集群,该集群将多个EBS卷连接到主EC2实例组中的实例。
aws emr create-cluster \ --release-label
emr-5.9.0
\ --use-default-roles \ --instance-groups 'InstanceGroupType=MASTER, InstanceCount=1, InstanceType=d2.xlarge, EbsConfiguration={EbsOptimized=true, EbsBlockDeviceConfigs=[{VolumeSpecification={VolumeType=io1, SizeInGB=100, Iops=100}},{VolumeSpecification={VolumeType=standard,SizeInGB=50},VolumesPerInstance=3}]}
'InstanceGroupType=CORE,InstanceCount=2,InstanceType=d2.xlarge
\ --auto-terminate示例 16:使用自动扩展策略创建集群
您可以使用 Amazon 4.0 及更高EMR版本将自动扩展策略附加到核心实例组和任务实例组。自动扩展策略会根据 Amazon CloudWatch 指标动态添加和删除EC2实例。有关更多信息,请参阅《亚马逊管理指南》中的 “在亚马逊使用自动扩展 EMR < https://docs.aws.amazon.com/emr/ latest/ManagementGuide/emr-automatic-scaling.html>`_”。EMR
附加自动扩展策略时,还必须使用
--auto-scaling-role EMR_AutoScaling_DefaultRole
指定自动扩展的默认角色。以下
create-cluster
示例使用带有嵌入式JSON结构的AutoScalingPolicy
参数指定CORE
实例组的自动扩展策略,该参数指定了扩展策略配置。具有嵌入式JSON结构的实例组必须将整个参数集合用单引号括起来。对于没有嵌入式JSON结构的实例组,可选择使用单引号。aws emr create-cluster --release-label
emr-5.9.0
\ --use-default-roles --auto-scaling-roleEMR_AutoScaling_DefaultRole
\ --instance-groupsInstanceGroupType=MASTER,InstanceType=d2.xlarge,InstanceCount=1
'InstanceGroupType=CORE,InstanceType=d2.xlarge,InstanceCount=2,AutoScalingPolicy={Constraints={MinCapacity=1,MaxCapacity=5},Rules=[{Name=TestRule,Description=TestDescription,Action={Market=ON_DEMAND,SimpleScalingPolicyConfiguration={AdjustmentType=EXACT_CAPACITY,ScalingAdjustment=2}},Trigger={CloudWatchAlarmDefinition={ComparisonOperator=GREATER_THAN,EvaluationPeriods=5,MetricName=TestMetric,Namespace=EMR,Period=3,Statistic=MAXIMUM,Threshold=4.5,Unit=NONE,Dimensions=[{Key=TestKey,Value=TestValue}]}}}]}
'以下示例使用JSON文件来指定集群中所有实例组的配置。
instancegroupconfig.json
该JSON文件指定了核心实例组的自动扩展策略配置。aws emr create-cluster \ --release-label
emr-5.9.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --instance-groupsfile://myfolder/instancegroupconfig.json
\ --auto-scaling-roleEMR_AutoScaling_DefaultRole
instancegroupconfig.json
的内容:[ { "InstanceCount": 1, "Name": "MyMasterIG", "InstanceGroupType": "MASTER", "InstanceType": "m4.large" }, { "InstanceCount": 2, "Name": "MyCoreIG", "InstanceGroupType": "CORE", "InstanceType": "m4.large", "AutoScalingPolicy": { "Constraints": { "MinCapacity": 2, "MaxCapacity": 10 }, "Rules": [ { "Name": "Default-scale-out", "Description": "Replicates the default scale-out rule in the console for YARN memory.", "Action": { "SimpleScalingPolicyConfiguration": { "AdjustmentType": "CHANGE_IN_CAPACITY", "ScalingAdjustment": 1, "CoolDown": 300 } }, "Trigger": { "CloudWatchAlarmDefinition": { "ComparisonOperator": "LESS_THAN", "EvaluationPeriods": 1, "MetricName": "YARNMemoryAvailablePercentage", "Namespace": "AWS/ElasticMapReduce", "Period": 300, "Threshold": 15, "Statistic": "AVERAGE", "Unit": "PERCENT", "Dimensions": [ { "Key": "JobFlowId", "Value": "${emr.clusterId}" } ] } } } ] } } ]
示例 17:在创建集群时添加自定义JAR步骤
以下
create-cluster
示例通过指定存储在 Amazon S3 中的JAR文件来添加步骤。步骤将工作提交到集群。JAR文件中定义的主函数将在配置EC2实例、执行所有引导操作以及安装应用程序之后执行。这些步骤是使用指定的Type=CUSTOM_JAR
。自定义JAR步骤需要
Jar=
参数,该参数用于指定路径和文件名JAR。可选参数有Type
Name
、ActionOnFailure
、Args
、和MainClass
。如果未指定主类,则JAR文件应在其清单文件Main-Class
中指定。aws emr create-cluster \ --steps
Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,Jar=s3://myBucket/mytest.jar,Args=arg1,arg2,arg3
Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,Jar=s3://myBucket/mytest.jar,MainClass=mymainclass,Args=arg1,arg2,arg3
\ --release-labelemr-5.3.1
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 18:在创建集群时添加直播步骤
以下
create-cluster
示例向集群添加了一个流式处理步骤,该步骤将在所有步骤运行后终止。直播步骤需要参数Type
和Args
。直播步骤可选参数为Name
和ActionOnFailure
。以下示例指定了行内步骤。
aws emr create-cluster \ --steps Type=STREAMING,Name='Streaming Program',ActionOnFailure=CONTINUE,Args=[-files,s3://elasticmapreduce/samples/wordcount/wordSplitter.py,-mapper,wordSplitter.py,-reducer,aggregate,-input,s3://elasticmapreduce/samples/wordcount/input,-output,s3://mybucket/wordcount/output] \ --release-label
emr-5.3.1
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate以下示例使用名为的本地存储的JSON配置文件
multiplefiles.json
。该JSON配置指定了多个文件。要在一个步骤中指定多个文件,必须使用JSON配置文件来指定该步骤。JSON参数必须将选项和值作为它们自己的项目包含在列表中。aws emr create-cluster \ --steps
file://./multiplefiles.json
\ --release-labelemr-5.9.0
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminatemultiplefiles.json
的内容:[ { "Name": "JSON Streaming Step", "Args": [ "-files", "s3://elasticmapreduce/samples/wordcount/wordSplitter.py", "-mapper", "wordSplitter.py", "-reducer", "aggregate", "-input", "s3://elasticmapreduce/samples/wordcount/input", "-output", "s3://mybucket/wordcount/output" ], "ActionOnFailure": "CONTINUE", "Type": "STREAMING" } ]
示例 19:在创建集群时添加 Hive 步骤
以下示例在创建集群时添加 Hive 步骤。Hive 步骤需要参数
Type
和。Args
Hive 步骤可选参数为Name
和。ActionOnFailure
aws emr create-cluster \ --steps Type=HIVE,Name='Hive program',ActionOnFailure=CONTINUE,ActionOnFailure=TERMINATE_CLUSTER,Args=[-f,s3://elasticmapreduce/samples/hive-ads/libs/model-build.q,-d,INPUT=s3://elasticmapreduce/samples/hive-ads/tables,-d,OUTPUT=s3://mybucket/hive-ads/output/2014-04-18/11-07-32,-d,LIBS=s3://elasticmapreduce/samples/hive-ads/libs] \ --applications
Name=Hive
\ --release-labelemr-5.3.1
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
示例 20:在创建集群时添加 Pig 步骤
以下示例在创建集群时添加了 Pig 步骤。Pig 步骤所需的参数是
Type
和Args
。Pig steps 可选参数是Name
和ActionOnFailure
。aws emr create-cluster \ --steps Type=PIG,Name='Pig program',ActionOnFailure=CONTINUE,Args=[-f,s3://elasticmapreduce/samples/pig-apache/do-reports2.pig,-p,INPUT=s3://elasticmapreduce/samples/pig-apache/input,-p,OUTPUT=s3://mybucket/pig-apache/output] \ --applications
Name=Pig
\ --release-labelemr-5.3.1
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
示例 21:添加引导操作
以下
create-cluster
示例运行两个定义为存储在 Amazon S3 中的脚本的引导操作。aws emr create-cluster \ --bootstrap-actions
Path=s3://mybucket/myscript1,Name=BootstrapAction1,Args=[arg1,arg2]
Path=s3://mybucket/myscript2,Name=BootstrapAction2,Args=[arg1,arg2]
\ --release-labelemr-5.3.1
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
\ --auto-terminate示例 22:启用EMRFS一致视图并自定义 RetryCount 和 RetryPeriod 设置
以下
create-cluster
示例指定了视图EMRFS一致性的重试次数和重试周期。Consistent=true
是必需参数。aws emr create-cluster \ --instance-type
m4.large
\ --release-labelemr-5.9.0
\ --emrfsConsistent=true,RetryCount=6,RetryPeriod=30
以下示例使用本地存储的名为的EMRFS配置文件指定了与上一个示例相同的JSON配置
emrfsconfig.json
。aws emr create-cluster \ --instance-type
m4.large
\ --release-labelemr-5.9.0
\ --emrfsfile://emrfsconfig.json
emrfsconfig.json
的内容:{ "Consistent": true, "RetryCount": 6, "RetryPeriod": 30 }
示例 23:创建配置了 Kerberos 的集群
以下
create-cluster
示例使用启用了 Kerberos 的安全配置创建集群,并使用为集群建立 Kerberos 参数。--kerberos-attributes
以下命令以内联方式指定集群的 Kerberos 属性。
aws emr create-cluster \ --instance-type
m3.xlarge
\ --release-labelemr-5.10.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --security-configurationmySecurityConfiguration
\ --kerberos-attributesRealm=EC2.INTERNAL,KdcAdminPassword=123,CrossRealmTrustPrincipalPassword=123
以下命令指定了相同的属性,但引用了名为的本地存储的JSON文件
kerberos_attributes.json
。在此示例中,文件保存在您运行命令的同一目录中。您也可以参考保存在 Amazon S3 中的配置文件。aws emr create-cluster \ --instance-type
m3.xlarge
\ --release-labelemr-5.10.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --security-configurationmySecurityConfiguration
\ --kerberos-attributesfile://kerberos_attributes.json
kerberos_attributes.json
的内容:{ "Realm": "EC2.INTERNAL", "KdcAdminPassword": "123", "CrossRealmTrustPrincipalPassword": "123", }
以下
create-cluster
示例创建了一个使用该--instance-groups
配置并具有托管扩展策略的 Amazon EMR 集群。aws emr create-cluster \ --release-label
emr-5.30.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
--managed-scaling-policy ComputeLimits='{MinimumCapacityUnits=2,MaximumCapacityUnits=4,UnitType=Instances}'以下
create-cluster
示例创建了一个 Amazon EMR 集群,该集群使用 “--log-encryption-kms-key-id” 来定义用于日志加密的KMS密钥 ID。aws emr create-cluster \ --release-label
emr-5.30.0
\ --log-uris3://myBucket/myLog
\ --log-encryption-kms-key-idarn:aws:kms:us-east-1:110302272565:key/dd559181-283e-45d7-99d1-66da348c4d33
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.large
以下
create-cluster
示例创建了一个 Amazon EMR 集群,该集群使用 “--placement-group-configs” 配置使用SPREAD
置放策略将主节点放置在EC2置放群组内的高可用性 (HA) 集群中。aws emr create-cluster \ --release-label
emr-5.30.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=3,InstanceType=m4.largeInstanceGroupType=CORE,InstanceCount=1,InstanceType=m4.large
\ --placement-group-configsInstanceRole=MASTER
以下
create-cluster
示例创建了一个 Amazon EMR 集群,该集群使用 “--auto-termination-policy” 配置为集群设置自动空闲终止阈值。aws emr create-cluster \ --release-label
emr-5.34.0
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=1,InstanceType=m4.large
\ --auto-termination-policyIdleTimeout=100
以下
create-cluster
示例创建了一个使用 “--os-release-label” 来定义用于EMR集群启动的 Amazon Linux 版本的 Amazon 集群aws emr create-cluster \ --release-label
emr-6.6.0
\ --os-release-label2.0.20220406.1
\ --service-roleEMR_DefaultRole
\ --ec2-attributesInstanceProfile=EMR_EC2_DefaultRole
\ --instance-groupsInstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.large
InstanceGroupType=CORE,InstanceCount=1,InstanceType=m4.large
示例 24:指定EBS根卷属性:使用 6.15.0 及更高EMR版本创建的集群实例的大小、IOPS 和吞吐量
以下
create-cluster
示例创建了一个 Amazon EMR 集群,该集群使用根卷属性为EC2实例配置根卷规格。aws emr create-cluster \ --name
"Cluster with My Custom AMI"
\ --custom-ami-idami-a518e6df
\ --ebs-root-volume-size20
\ --ebs-root-volume-iops3000
\ --ebs-root-volume-throughput125
\ --release-labelemr-6.15.0
\ --use-default-roles \ --instance-count2
\ --instance-typem4.large
-
有关API详细信息,请参阅 “CreateClusterExamples AWS CLI
命令参考”。
-
以下代码示例显示了如何使用create-default-roles
。
- AWS CLI
-
1。为创建默认IAM角色 EC2
命令:
aws emr create-default-roles
输出:
If the role already exists then the command returns nothing. If the role does not exist then the output will be: [ { "RolePolicy": { "Version": "2012-10-17", "Statement": [ { "Action": [ "cloudwatch:*", "dynamodb:*", "ec2:Describe*", "elasticmapreduce:Describe*", "elasticmapreduce:ListBootstrapActions", "elasticmapreduce:ListClusters", "elasticmapreduce:ListInstanceGroups", "elasticmapreduce:ListInstances", "elasticmapreduce:ListSteps", "kinesis:CreateStream", "kinesis:DeleteStream", "kinesis:DescribeStream", "kinesis:GetRecords", "kinesis:GetShardIterator", "kinesis:MergeShards", "kinesis:PutRecord", "kinesis:SplitShard", "rds:Describe*", "s3:*", "sdb:*", "sns:*", "sqs:*" ], "Resource": "*", "Effect": "Allow" } ] }, "Role": { "AssumeRolePolicyDocument": { "Version": "2008-10-17", "Statement": [ { "Action": "sts:AssumeRole", "Sid": "", "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" } } ] }, "RoleId": "AROAIQ5SIQUGL5KMYBJX6", "CreateDate": "2015-06-09T17:09:04.602Z", "RoleName": "EMR_EC2_DefaultRole", "Path": "/", "Arn": "arn:aws:iam::176430881729:role/EMR_EC2_DefaultRole" } }, { "RolePolicy": { "Version": "2012-10-17", "Statement": [ { "Action": [ "ec2:AuthorizeSecurityGroupIngress", "ec2:CancelSpotInstanceRequests", "ec2:CreateSecurityGroup", "ec2:CreateTags", "ec2:DeleteTags", "ec2:DescribeAvailabilityZones", "ec2:DescribeAccountAttributes", "ec2:DescribeInstances", "ec2:DescribeInstanceStatus", "ec2:DescribeKeyPairs", "ec2:DescribePrefixLists", "ec2:DescribeRouteTables", "ec2:DescribeSecurityGroups", "ec2:DescribeSpotInstanceRequests", "ec2:DescribeSpotPriceHistory", "ec2:DescribeSubnets", "ec2:DescribeVpcAttribute", "ec2:DescribeVpcEndpoints", "ec2:DescribeVpcEndpointServices", "ec2:DescribeVpcs", "ec2:ModifyImageAttribute", "ec2:ModifyInstanceAttribute", "ec2:RequestSpotInstances", "ec2:RunInstances", "ec2:TerminateInstances", "iam:GetRole", "iam:GetRolePolicy", "iam:ListInstanceProfiles", "iam:ListRolePolicies", "iam:PassRole", "s3:CreateBucket", "s3:Get*", "s3:List*", "sdb:BatchPutAttributes", "sdb:Select", "sqs:CreateQueue", "sqs:Delete*", "sqs:GetQueue*", "sqs:ReceiveMessage" ], "Resource": "*", "Effect": "Allow" } ] }, "Role": { "AssumeRolePolicyDocument": { "Version": "2008-10-17", "Statement": [ { "Action": "sts:AssumeRole", "Sid": "", "Effect": "Allow", "Principal": { "Service": "elasticmapreduce.amazonaws.com" } } ] }, "RoleId": "AROAI3SRVPPVSRDLARBPY", "CreateDate": "2015-06-09T17:09:10.401Z", "RoleName": "EMR_DefaultRole", "Path": "/", "Arn": "arn:aws:iam::176430881729:role/EMR_DefaultRole" } } ]
-
有关API详细信息,请参阅 “CreateDefaultRoles AWS CLI
命令参考”。
-
以下代码示例显示了如何使用create-security-configuration
。
- AWS CLI
-
1。创建安全配置,PEM为证书提供者启用传输中加密,对于 SSE S3 加密,使用-S3 启用静态加密,对本地磁盘密钥提供者使用-S3 启用静态加密 AWS KMS
命令:
aws emr create-security-configuration --name MySecurityConfig --security-configuration '{ "EncryptionConfiguration": { "EnableInTransitEncryption" : true, "EnableAtRestEncryption" : true, "InTransitEncryptionConfiguration" : { "TLSCertificateConfiguration" : { "CertificateProviderType" : "PEM", "S3Object" : "s3://mycertstore/artifacts/MyCerts.zip" } }, "AtRestEncryptionConfiguration" : { "S3EncryptionConfiguration" : { "EncryptionMode" : "SSE-S3" }, "LocalDiskEncryptionConfiguration" : { "EncryptionKeyProviderType" : "AwsKms", "AwsKmsKey" : "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012" } } } }'
输出:
{ "CreationDateTime": 1474070889.129, "Name": "MySecurityConfig" }
JSON等效(security_configuration.json 的内容):
{ "EncryptionConfiguration": { "EnableInTransitEncryption": true, "EnableAtRestEncryption": true, "InTransitEncryptionConfiguration": { "TLSCertificateConfiguration": { "CertificateProviderType": "PEM", "S3Object": "s3://mycertstore/artifacts/MyCerts.zip" } }, "AtRestEncryptionConfiguration": { "S3EncryptionConfiguration": { "EncryptionMode": "SSE-S3" }, "LocalDiskEncryptionConfiguration": { "EncryptionKeyProviderType": "AwsKms", "AwsKmsKey": "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012" } } } }
命令(使用 security_configuration.json):
aws emr create-security-configuration --name "MySecurityConfig" --security-configuration file://./security_configuration.json
输出:
{ "CreationDateTime": 1474070889.129, "Name": "MySecurityConfig" }
2。使用集群KDC专用和跨领域信任创建启用 Kerberos 的安全配置
命令:
aws emr create-security-configuration --name MySecurityConfig --security-configuration '{ "AuthenticationConfiguration": { "KerberosConfiguration": { "Provider": "ClusterDedicatedKdc", "ClusterDedicatedKdcConfiguration": { "TicketLifetimeInHours": 24, "CrossRealmTrustConfiguration": { "Realm": "AD.DOMAIN.COM", "Domain": "ad.domain.com", "AdminServer": "ad.domain.com", "KdcServer": "ad.domain.com" } } } } }'
输出:
{ "CreationDateTime": 1490225558.982, "Name": "MySecurityConfig" }
JSON等效(security_configuration.json 的内容):
{ "AuthenticationConfiguration": { "KerberosConfiguration": { "Provider": "ClusterDedicatedKdc", "ClusterDedicatedKdcConfiguration": { "TicketLifetimeInHours": 24, "CrossRealmTrustConfiguration": { "Realm": "AD.DOMAIN.COM", "Domain": "ad.domain.com", "AdminServer": "ad.domain.com", "KdcServer": "ad.domain.com" } } } } }
命令(使用 security_configuration.json):
aws emr create-security-configuration --name "MySecurityConfig" --security-configuration file://./security_configuration.json
输出:
{ "CreationDateTime": 1490225558.982, "Name": "MySecurityConfig" }
-
有关API详细信息,请参阅 “CreateSecurityConfiguration AWS CLI
命令参考”。
-
以下代码示例显示了如何使用delete-security-configuration
。
- AWS CLI
-
删除当前区域中的安全配置
命令:
aws emr delete-security-configuration --name MySecurityConfig
输出:
None
-
有关API详细信息,请参阅 “DeleteSecurityConfiguration AWS CLI
命令参考”。
-
以下代码示例显示了如何使用describe-cluster
。
- AWS CLI
-
命令:
aws emr describe-cluster --cluster-id j-XXXXXXXX
输出:
For release-label based uniform instance groups cluster: { "Cluster": { "Status": { "Timeline": { "ReadyDateTime": 1436475075.199, "CreationDateTime": 1436474656.563, }, "State": "WAITING", "StateChangeReason": { "Message": "Waiting for steps to run" } }, "Ec2InstanceAttributes": { "ServiceAccessSecurityGroup": "sg-xxxxxxxx", "EmrManagedMasterSecurityGroup": "sg-xxxxxxxx", "IamInstanceProfile": "EMR_EC2_DefaultRole", "Ec2KeyName": "myKey", "Ec2AvailabilityZone": "us-east-1c", "EmrManagedSlaveSecurityGroup": "sg-yyyyyyyyy" }, "Name": "My Cluster", "ServiceRole": "EMR_DefaultRole", "Tags": [], "TerminationProtected": true, "UnhealthyNodeReplacement": true, "ReleaseLabel": "emr-4.0.0", "NormalizedInstanceHours": 96, "InstanceGroups": [ { "RequestedInstanceCount": 2, "Status": { "Timeline": { "ReadyDateTime": 1436475074.245, "CreationDateTime": 1436474656.564, "EndDateTime": 1436638158.387 }, "State": "RUNNING", "StateChangeReason": { "Message": "", } }, "Name": "CORE", "InstanceGroupType": "CORE", "Id": "ig-YYYYYYY", "Configurations": [], "InstanceType": "m3.large", "Market": "ON_DEMAND", "RunningInstanceCount": 2 }, { "RequestedInstanceCount": 1, "Status": { "Timeline": { "ReadyDateTime": 1436475074.245, "CreationDateTime": 1436474656.564, "EndDateTime": 1436638158.387 }, "State": "RUNNING", "StateChangeReason": { "Message": "", } }, "Name": "MASTER", "InstanceGroupType": "MASTER", "Id": "ig-XXXXXXXXX", "Configurations": [], "InstanceType": "m3.large", "Market": "ON_DEMAND", "RunningInstanceCount": 1 } ], "Applications": [ { "Name": "Hadoop" } ], "VisibleToAllUsers": true, "BootstrapActions": [], "MasterPublicDnsName": "ec2-54-147-144-78.compute-1.amazonaws.com", "AutoTerminate": false, "Id": "j-XXXXXXXX", "Configurations": [ { "Properties": { "fs.s3.consistent.retryPeriodSeconds": "20", "fs.s3.enableServerSideEncryption": "true", "fs.s3.consistent": "false", "fs.s3.consistent.retryCount": "2" }, "Classification": "emrfs-site" } ] } } For release-label based instance fleet cluster: { "Cluster": { "Status": { "Timeline": { "ReadyDateTime": 1487897289.705, "CreationDateTime": 1487896933.942 }, "State": "WAITING", "StateChangeReason": { "Message": "Waiting for steps to run" } }, "Ec2InstanceAttributes": { "EmrManagedMasterSecurityGroup": "sg-xxxxx", "RequestedEc2AvailabilityZones": [], "RequestedEc2SubnetIds": [], "IamInstanceProfile": "EMR_EC2_DefaultRole", "Ec2AvailabilityZone": "us-east-1a", "EmrManagedSlaveSecurityGroup": "sg-xxxxx" }, "Name": "My Cluster", "ServiceRole": "EMR_DefaultRole", "Tags": [], "TerminationProtected": false, "UnhealthyNodeReplacement": false, "ReleaseLabel": "emr-5.2.0", "NormalizedInstanceHours": 472, "InstanceCollectionType": "INSTANCE_FLEET", "InstanceFleets": [ { "Status": { "Timeline": { "ReadyDateTime": 1487897212.74, "CreationDateTime": 1487896933.948 }, "State": "RUNNING", "StateChangeReason": { "Message": "" } }, "ProvisionedSpotCapacity": 1, "Name": "MASTER", "InstanceFleetType": "MASTER", "LaunchSpecifications": { "SpotSpecification": { "TimeoutDurationMinutes": 60, "TimeoutAction": "TERMINATE_CLUSTER" } }, "TargetSpotCapacity": 1, "ProvisionedOnDemandCapacity": 0, "InstanceTypeSpecifications": [ { "BidPrice": "0.5", "InstanceType": "m3.xlarge", "WeightedCapacity": 1 } ], "Id": "if-xxxxxxx", "TargetOnDemandCapacity": 0 } ], "Applications": [ { "Version": "2.7.3", "Name": "Hadoop" } ], "ScaleDownBehavior": "TERMINATE_AT_INSTANCE_HOUR", "VisibleToAllUsers": true, "BootstrapActions": [], "MasterPublicDnsName": "ec2-xxx-xx-xxx-xx.compute-1.amazonaws.com", "AutoTerminate": false, "Id": "j-xxxxx", "Configurations": [] } } For ami based uniform instance group cluster: { "Cluster": { "Status": { "Timeline": { "ReadyDateTime": 1399400564.432, "CreationDateTime": 1399400268.62 }, "State": "WAITING", "StateChangeReason": { "Message": "Waiting for steps to run" } }, "Ec2InstanceAttributes": { "IamInstanceProfile": "EMR_EC2_DefaultRole", "Ec2AvailabilityZone": "us-east-1c" }, "Name": "My Cluster", "Tags": [], "TerminationProtected": true, "UnhealthyNodeReplacement": true, "RunningAmiVersion": "2.5.4", "InstanceGroups": [ { "RequestedInstanceCount": 1, "Status": { "Timeline": { "ReadyDateTime": 1399400558.848, "CreationDateTime": 1399400268.621 }, "State": "RUNNING", "StateChangeReason": { "Message": "" } }, "Name": "Master instance group", "InstanceGroupType": "MASTER", "InstanceType": "m1.small", "Id": "ig-ABCD", "Market": "ON_DEMAND", "RunningInstanceCount": 1 }, { "RequestedInstanceCount": 2, "Status": { "Timeline": { "ReadyDateTime": 1399400564.439, "CreationDateTime": 1399400268.621 }, "State": "RUNNING", "StateChangeReason": { "Message": "" } }, "Name": "Core instance group", "InstanceGroupType": "CORE", "InstanceType": "m1.small", "Id": "ig-DEF", "Market": "ON_DEMAND", "RunningInstanceCount": 2 } ], "Applications": [ { "Version": "1.0.3", "Name": "hadoop" } ], "BootstrapActions": [], "VisibleToAllUsers": false, "RequestedAmiVersion": "2.4.2", "LogUri": "s3://myLogUri/", "AutoTerminate": false, "Id": "j-XXXXXXXX" } }
-
有关API详细信息,请参阅 “DescribeCluster AWS CLI
命令参考”。
-
以下代码示例显示了如何使用describe-step
。
- AWS CLI
-
以下命令描述集群中步骤 ID 为
s-3LZC0QUT43AM
和集群 ID 为j-3SD91U2E1L2QX
的步骤:aws emr describe-step --cluster-id
j-3SD91U2E1L2QX
--step-ids-3LZC0QUT43AM
输出:
{ "Step": { "Status": { "Timeline": { "EndDateTime": 1433200470.481, "CreationDateTime": 1433199926.597, "StartDateTime": 1433200404.959 }, "State": "COMPLETED", "StateChangeReason": {} }, "Config": { "Args": [ "s3://us-west-2.elasticmapreduce/libs/hive/hive-script", "--base-path", "s3://us-west-2.elasticmapreduce/libs/hive/", "--install-hive", "--hive-versions", "0.13.1" ], "Jar": "s3://us-west-2.elasticmapreduce/libs/script-runner/script-runner.jar", "Properties": {} }, "Id": "s-3LZC0QUT43AM", "ActionOnFailure": "TERMINATE_CLUSTER", "Name": "Setup hive" } }
-
有关API详细信息,请参阅 “DescribeStep AWS CLI
命令参考”。
-
以下代码示例显示了如何使用get
。
- AWS CLI
-
以下内容从集群中的主实例下载具有集群 ID 的
hadoop-examples.jar
档案j-3SD91U2E1L2QX
:aws emr get --cluster-id
j-3SD91U2E1L2QX
--key-pair-file~/.ssh/mykey.pem
--src/home/hadoop-examples.jar
--dest~
-
有关API详细信息,请参阅 Get
in AWS CLI 命令参考。
-
以下代码示例显示了如何使用list-clusters
。
- AWS CLI
-
以下命令列出了当前区域中的所有活动EMR集群:
aws emr list-clusters --active
输出:
{ "Clusters": [ { "Status": { "Timeline": { "ReadyDateTime": 1433200405.353, "CreationDateTime": 1433199926.596 }, "State": "WAITING", "StateChangeReason": { "Message": "Waiting after step completed" } }, "NormalizedInstanceHours": 6, "Id": "j-3SD91U2E1L2QX", "Name": "my-cluster" } ] }
-
有关API详细信息,请参阅 “ListClusters AWS CLI
命令参考”。
-
以下代码示例显示了如何使用list-instance-fleets
。
- AWS CLI
-
获取集群中实例队列的配置详细信息
此示例列出了指定集群中实例队列的详细信息。
命令:
list-instance-fleets --cluster-id 'j-12ABCDEFGHI34JK'
输出:
{ "InstanceFleets": [ { "Status": { "Timeline": { "ReadyDateTime": 1488759094.637, "CreationDateTime": 1488758719.817 }, "State": "RUNNING", "StateChangeReason": { "Message": "" } }, "ProvisionedSpotCapacity": 6, "Name": "CORE", "InstanceFleetType": "CORE", "LaunchSpecifications": { "SpotSpecification": { "TimeoutDurationMinutes": 60, "TimeoutAction": "TERMINATE_CLUSTER" } }, "ProvisionedOnDemandCapacity": 2, "InstanceTypeSpecifications": [ { "BidPrice": "0.5", "InstanceType": "m3.xlarge", "WeightedCapacity": 2 } ], "Id": "if-1ABC2DEFGHIJ3" }, { "Status": { "Timeline": { "ReadyDateTime": 1488759058.598, "CreationDateTime": 1488758719.811 }, "State": "RUNNING", "StateChangeReason": { "Message": "" } }, "ProvisionedSpotCapacity": 0, "Name": "MASTER", "InstanceFleetType": "MASTER", "ProvisionedOnDemandCapacity": 1, "InstanceTypeSpecifications": [ { "BidPriceAsPercentageOfOnDemandPrice": 100.0, "InstanceType": "m3.xlarge", "WeightedCapacity": 1 } ], "Id": "if-2ABC4DEFGHIJ4" } ] }
-
有关API详细信息,请参阅 “ListInstanceFleets AWS CLI
命令参考”。
-
以下代码示例显示了如何使用list-instances
。
- AWS CLI
-
以下命令列出了集群中所有具有集群 ID 的实例
j-3C6XNQ39VR9WL
:aws emr list-instances --cluster-id
j-3C6XNQ39VR9WL
输出:
For a uniform instance group based cluster { "Instances": [ { "Status": { "Timeline": { "ReadyDateTime": 1433200400.03, "CreationDateTime": 1433199960.152 }, "State": "RUNNING", "StateChangeReason": {} }, "Ec2InstanceId": "i-f19ecfee", "PublicDnsName": "ec2-52-52-41-150.us-west-2.compute.amazonaws.com", "PrivateDnsName": "ip-172-21-11-216.us-west-2.compute.internal", "PublicIpAddress": "52.52.41.150", "Id": "ci-3NNHQUQ2TWB6Y", "PrivateIpAddress": "172.21.11.216" }, { "Status": { "Timeline": { "ReadyDateTime": 1433200400.031, "CreationDateTime": 1433199949.102 }, "State": "RUNNING", "StateChangeReason": {} }, "Ec2InstanceId": "i-1feee4c2", "PublicDnsName": "ec2-52-63-246-32.us-west-2.compute.amazonaws.com", "PrivateDnsName": "ip-172-31-24-130.us-west-2.compute.internal", "PublicIpAddress": "52.63.246.32", "Id": "ci-GAOCMKNKDCV7", "PrivateIpAddress": "172.21.11.215" }, { "Status": { "Timeline": { "ReadyDateTime": 1433200400.031, "CreationDateTime": 1433199949.102 }, "State": "RUNNING", "StateChangeReason": {} }, "Ec2InstanceId": "i-15cfeee3", "PublicDnsName": "ec2-52-25-246-63.us-west-2.compute.amazonaws.com", "PrivateDnsName": "ip-172-31-24-129.us-west-2.compute.internal", "PublicIpAddress": "52.25.246.63", "Id": "ci-2W3TDFFB47UAD", "PrivateIpAddress": "172.21.11.214" } ] } For a fleet based cluster: { "Instances": [ { "Status": { "Timeline": { "ReadyDateTime": 1487810810.878, "CreationDateTime": 1487810588.367, "EndDateTime": 1488022990.924 }, "State": "TERMINATED", "StateChangeReason": { "Message": "Instance was terminated." } }, "Ec2InstanceId": "i-xxxxx", "InstanceFleetId": "if-xxxxx", "EbsVolumes": [], "PublicDnsName": "ec2-xx-xxx-xxx-xxx.compute-1.amazonaws.com", "InstanceType": "m3.xlarge", "PrivateDnsName": "ip-xx-xx-xxx-xx.ec2.internal", "Market": "SPOT", "PublicIpAddress": "xx.xx.xxx.xxx", "Id": "ci-xxxxx", "PrivateIpAddress": "10.47.191.80" } ] }
-
有关API详细信息,请参阅 “ListInstances AWS CLI
命令参考”。
-
以下代码示例显示了如何使用list-security-configurations
。
- AWS CLI
-
列出当前区域的安全配置
命令:
aws emr list-security-configurations
输出:
{ "SecurityConfigurations": [ { "CreationDateTime": 1473889697.417, "Name": "MySecurityConfig-1" }, { "CreationDateTime": 1473889697.417, "Name": "MySecurityConfig-2" } ] }
-
有关API详细信息,请参阅 “ListSecurityConfigurations AWS CLI
命令参考”。
-
以下代码示例显示了如何使用list-steps
。
- AWS CLI
-
以下命令列出了集群 ID 为
j-3SD91U2E1L2QX
的集群的所有步骤:aws emr list-steps --cluster-id
j-3SD91U2E1L2QX
-
有关API详细信息,请参阅 “ListSteps AWS CLI
命令参考”。
-
以下代码示例显示了如何使用modify-cluster-attributes
。
- AWS CLI
-
以下命令将 ID 为的EMR集群的可见性设置
j-301CDNY0J5XM4
为所有用户:aws emr modify-cluster-attributes --cluster-id
j-301CDNY0J5XM4
--visible-to-all-users-
有关API详细信息,请参阅 “ModifyClusterAttributes AWS CLI
命令参考”。
-
以下代码示例显示了如何使用modify-instance-fleet
。
- AWS CLI
-
更改实例队列的目标容量
此示例将指定实例队列的按需和竞价目标容量更改为 1。
命令:
aws emr modify-instance-fleet --cluster-id '
j-12ABCDEFGHI34JK
' --instance-fleet InstanceFleetId='if-2ABC4DEFGHIJ4',TargetOnDemandCapacity=1,TargetSpotCapacity=1-
有关API详细信息,请参阅 “ModifyInstanceFleet AWS CLI
命令参考”。
-
以下代码示例显示了如何使用put
。
- AWS CLI
-
以下命令将名为集群的主实例上传一个名
healthcheck.sh
为集群的文件,该文件名为集群 ID:j-3SD91U2E1L2QX
aws emr put --cluster-id
j-3SD91U2E1L2QX
--key-pair-file~/.ssh/mykey.pem
--src~/scripts/healthcheck.sh
--dest/home/hadoop/bin/healthcheck.sh
-
有关API详细信息,请参阅 P AWS CLI u t
in Command 参考。
-
以下代码示例显示了如何使用remove-tags
。
- AWS CLI
-
以下命令
prod
从集群 ID 为的集群中删除带有密钥的标签j-3SD91U2E1L2QX
:aws emr remove-tags --resource-id
j-3SD91U2E1L2QX
--tag-keysprod
-
有关API详细信息,请参阅 “RemoveTags AWS CLI
命令参考”。
-
以下代码示例显示了如何使用schedule-hbase-backup
。
- AWS CLI
-
注意:此命令只能在 2.x 和 3.x AMI 版本HBase上使用
1。要安排完整HBase备份 >>>>>>> 06ab6d 6e13564b5733d75abaf3b599f93cf39a23
命令:
aws emr schedule-hbase-backup --cluster-id j-XXXXXXYY --type full --dir s3://myBucket/backup --interval 10 --unit hours --start-time 2014-04-21T05:26:10Z --consistent
输出:
None
2。安排增量HBase备份
命令:
aws emr schedule-hbase-backup --cluster-id j-XXXXXXYY --type incremental --dir s3://myBucket/backup --interval 30 --unit minutes --start-time 2014-04-21T05:26:10Z --consistent
输出:
None
-
有关API详细信息,请参阅 “ScheduleHbaseBackup AWS CLI
命令参考”。
-
以下代码示例显示了如何使用socks
。
- AWS CLI
-
以下命令使用集群 ID 打开与集群中主实例的 socks 连接
j-3SD91U2E1L2QX
:aws emr socks --cluster-id
j-3SD91U2E1L2QX
--key-pair-file~/.ssh/mykey.pem
key pair file 选项采用私钥文件的本地路径。
-
有关API详细信息,请参阅《AWS CLI 命令参考》中的 Soc
ks。
-
以下代码示例显示了如何使用ssh
。
- AWS CLI
-
以下命令使用集群 ID 打开与集群中主实例的 ssh 连接
j-3SD91U2E1L2QX
:aws emr ssh --cluster-id
j-3SD91U2E1L2QX
--key-pair-file~/.ssh/mykey.pem
key pair file 选项采用私钥文件的本地路径。
输出:
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i /home/local/user/.ssh/mykey.pem hadoop@ec2-52-52-41-150.us-west-2.compute.amazonaws.com Warning: Permanently added 'ec2-52-52-41-150.us-west-2.compute.amazonaws.com,52.52.41.150' (ECDSA) to the list of known hosts. Last login: Mon Jun 1 23:15:38 2015 __| __|_ ) _| ( / Amazon Linux AMI ___|\___|___| https://aws.amazon.com/amazon-linux-ami/2015.03-release-notes/ 26 package(s) needed for security, out of 39 available Run "sudo yum update" to apply all updates. -------------------------------------------------------------------------------- Welcome to Amazon Elastic MapReduce running Hadoop and Amazon Linux. Hadoop is installed in /home/hadoop. Log files are in /mnt/var/log/hadoop. Check /mnt/var/log/hadoop/steps for diagnosing step failures. The Hadoop UI can be accessed via the following commands: ResourceManager lynx http://ip-172-21-11-216:9026/ NameNode lynx http://ip-172-21-11-216:9101/ -------------------------------------------------------------------------------- [hadoop@ip-172-31-16-216 ~]$
-
有关API详细信息,请参阅《AWS CLI 命令参考》中的 SSH
。
-