笔记本执行 Ruby 示例 - Amazon EMR
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

笔记本执行 Ruby 示例

以下是演示使用笔记本执行 API 的 Ruby 代码示例。

# prepare an EMR client emr = Aws::EMR::Client.new( region: 'us-east-1', access_key_id: 'AKIA...JKPKA', secret_access_key: 'rLMeu...vU0OLrAC1', )

启动笔记本执行并获取执行 ID

在此示例中,S3 编辑器和 EMR Notebooks 是 s3://mybucket/notebooks/e-EA8VGAA429FEQTC8HC9ZHWISK/test.ipynb

有关 EMR API NotebookExecution 操作的信息,请参阅 EMR API 操作

start_response = emr.start_notebook_execution({ editor_id: "e-EA8VGAA429FEQTC8HC9ZHWISK", relative_path: "test.ipynb", execution_engine: {id: "j-3U82I95AMALGE"}, service_role: "EMR_Notebooks_DefaultRole", }) notebook_execution_id = start_resp.notebook_execution_id

描述笔记本执行并打印详细信息

describe_resp = emr.describe_notebook_execution({ notebook_execution_id: notebook_execution_id }) puts describe_resp.notebook_execution { :notebook_execution_id=>"ex-IZX3VTVZWVWPP27KUB90BZ7V9IEDG", :editor_id=>"e-EA8VGAA429FEQTC8HC9ZHWISK", :execution_engine=>{:id=>"j-3U82I95AMALGE", :type=>"EMR", :master_instance_security_group_id=>nil}, :notebook_execution_name=>"", :notebook_params=>nil, :status=>"STARTING", :start_time=>2020-07-23 15:07:07 -0700, :end_time=>nil, :arn=>"arn:aws:elasticmapreduce:us-east-1:123456789012:notebook-execution/ex-IZX3VTVZWVWPP27KUB90BZ7V9IEDG", :output_notebook_uri=>nil, :last_state_change_reason=>"Execution is starting for cluster j-3U82I95AMALGE.", :notebook_instance_security_group_id=>nil, :tags=>[] }

列出笔记本执行

puts 'Listing executions:' list_resp = emr.list_notebook_executions({}) puts list_resp

笔记本筛选条件

"EditorId": "e-XXXX", [Optional] "From" : "1593400000.000", [Optional] "To" : "1598400000.500", [Optional] "Status": [Optional] "START_PENDING | STARTING | RUNNING | STOP_PENDING | STOPPING | FINISHING | FAILING | FINSHED | FAILED | STOPPED"

当 EMR Notebooks 处于以下状态之一时,可以停止它:START_PENDING, STARTING, RUNNING

停止笔记本执行

stop_resp = emr.stop_notebook_execution({ notebook_execution_id: notebook_execution_id })

计划笔记本执行

可以使用以下任一方式计划 EMR Notebooks:

#!/bin/bash aws emr --region us-east-1 \ start-notebook-execution \ --editor-id e-EA8VGAA429FEQTC8HC9ZHWISK \ --notebook-params '{"input_param":"my-value", "good_superhero":["superman", "batman"], "new_param":{"nest-key1":"nest-val1", "nest-key2":"nest-val2"}}' \ --relative-path test.ipynb \ --notebook-execution-name daily-job \ --execution-engine '{"Id" : "j-3U82I95AMALGE"}' \ --service-role EMR_Notebooks_DefaultRole