Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct syntax for running a bash script as a step in EMR?

I am trying to run a bash script as a step after EMR completes bootstrapping. Following is my terraform code:

step { action_on_failure = "CONTINUE" 
name = "Setup Hadoop configuration" 
hadoop_jar_step { 
jar = "command-runner.jar" 
args = ["bash,-c,'cd /mnt; chmod +x ./userdata.sh; ./userdata.sh'"] 
}}

This isn't working and keeps on failing mentioning that No file found. Are args correctly provided ? What about script-runner.jar? Any help is highly appreciated. :(

like image 951
Ash Panwar Avatar asked Aug 11 '18 21:08

Ash Panwar


People also ask

How do I run AWS EMR shell script?

Submit a custom JAR step to run a script or commandjar on Amazon EMR. When you use command-runner. jar , you specify commands, options, and values in your step's list of arguments. The following AWS CLI example submits a step to a running cluster that invokes command-runner.

How do you write code on EMR?

Choose File, New, and Other. In the Select a wizard dialog, choose AWS Java Project and Next. In the New AWS Java Project dialog, in the Project name: field, enter the name of your new project, for example EMR-sample-code . Choose Configure AWS accounts…, enter your public and private access keys, and choose Finish.


1 Answers

With command-runner.jar you can execute many programs like bash script, and you do not have to know its full path as was the case with script-runner.jar. It is recommended to use command-runner.jar.

EMR is in cluster mode, you do not know which nodes execute the shell script, so push it to S3 :

{
  "Name": "Setup Hadoop configuration",
  "ActionOnFailure": "CONTINUE",
 "HadoopJarStep": {
    "Jar": "command-runner.jar",
    "Args": [
         "bash",
         "-c",
         " aws s3 cp s3://path_to_bucket_S3/userdata.sh .;
          chmod +x userdata.sh;
          ./userdata.sh args...;
          rm userdata.sh "
     ]
  }
}
like image 186
Ahmed Avatar answered Sep 20 '22 12:09

Ahmed