elastic-mapreduce 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. data/CHANGELOG +51 -0
  2. data/Gemfile +13 -0
  3. data/Gemfile.lock +16 -0
  4. data/LICENSE.txt +393 -0
  5. data/NOTICE.txt +26 -0
  6. data/README +1007 -0
  7. data/Rakefile +35 -0
  8. data/VERSION +1 -0
  9. data/bin/elastic-mapreduce +27 -0
  10. data/cacert.pem +280 -0
  11. data/elastic-mapreduce.gemspec +104 -0
  12. data/lib/amazon/aws/exceptions.rb +211 -0
  13. data/lib/amazon/coral/awsquery.rb +128 -0
  14. data/lib/amazon/coral/awsquerychainhelper.rb +92 -0
  15. data/lib/amazon/coral/awsqueryhandler.rb +170 -0
  16. data/lib/amazon/coral/awsqueryurihandler.rb +34 -0
  17. data/lib/amazon/coral/call.rb +68 -0
  18. data/lib/amazon/coral/dispatcher.rb +33 -0
  19. data/lib/amazon/coral/ec2client.rb +91 -0
  20. data/lib/amazon/coral/elasticmapreduceclient.rb +198 -0
  21. data/lib/amazon/coral/handler.rb +20 -0
  22. data/lib/amazon/coral/httpdelegationhelper.rb +27 -0
  23. data/lib/amazon/coral/httpdestinationhandler.rb +36 -0
  24. data/lib/amazon/coral/httphandler.rb +124 -0
  25. data/lib/amazon/coral/identityhandler.rb +32 -0
  26. data/lib/amazon/coral/job.rb +25 -0
  27. data/lib/amazon/coral/logfactory.rb +35 -0
  28. data/lib/amazon/coral/option.rb +70 -0
  29. data/lib/amazon/coral/orchestrator.rb +49 -0
  30. data/lib/amazon/coral/querystringmap.rb +93 -0
  31. data/lib/amazon/coral/service.rb +130 -0
  32. data/lib/amazon/coral/simplelog.rb +98 -0
  33. data/lib/amazon/coral/urlencoding.rb +19 -0
  34. data/lib/amazon/coral/v0signaturehandler.rb +33 -0
  35. data/lib/amazon/coral/v0signaturehelper.rb +83 -0
  36. data/lib/amazon/coral/v1signaturehandler.rb +32 -0
  37. data/lib/amazon/coral/v1signaturehelper.rb +58 -0
  38. data/lib/amazon/coral/v2signaturehandler.rb +46 -0
  39. data/lib/amazon/coral/v2signaturehelper.rb +76 -0
  40. data/lib/amazon/retry_delegator.rb +66 -0
  41. data/lib/amazon/stderr_logger.rb +23 -0
  42. data/lib/client.rb +117 -0
  43. data/lib/commands.rb +1690 -0
  44. data/lib/credentials.rb +86 -0
  45. data/lib/ec2_client_wrapper.rb +73 -0
  46. data/lib/json/lexer.rb +294 -0
  47. data/lib/json/objects.rb +200 -0
  48. data/lib/json.rb +58 -0
  49. data/lib/simple_executor.rb +11 -0
  50. data/lib/simple_logger.rb +38 -0
  51. data/lib/uuidtools/version.rb +32 -0
  52. data/lib/uuidtools.rb +655 -0
  53. data/run_tests.rb +8 -0
  54. data/samples/freebase/code/freebase_jobflow.json +44 -0
  55. data/samples/similarity/lastfm_jobflow.json +78 -0
  56. data/samples/wordSplitter.py +18 -0
  57. data/tests/commands_test.rb +587 -0
  58. data/tests/credentials.json +7 -0
  59. data/tests/example.json +14 -0
  60. metadata +154 -0
data/README ADDED
@@ -0,0 +1,1007 @@
1
+ = Amazon Elastic Map Reduce Ruby Client Readme (Unofficial Gem and Ruby 1.9 Version)
2
+
3
+ == Usage
4
+ $ gem install elastic-mapreduce
5
+ $ elastic-mapreduce --help
6
+
7
+ = Amazon Elastic Map Reduce Ruby Client Readme (Original)
8
+
9
+ Location of the Ruby Client:
10
+
11
+ http://elasticmapreduce.s3.amazonaws.com/elastic-mapreduce-ruby.zip
12
+
13
+ Welcome the Amazon Elastic MapReduce Ruby client. This package
14
+ contains a pure Ruby client for the Amazon Elastic MapReduce Web
15
+ Service. Amazon Elastic MapReduce is a service that makes it easy for
16
+ researchers, data analysts, and developers to efficiently and
17
+ cost-effectively process vast amounts of data using the Amazon EC2 service.
18
+ The service launches the EC2 instances on your behalf to
19
+ process data, monitor execution and, when the processing is over,
20
+ shut down EC2 instances.
21
+
22
+ It is assumed that the reader is already familiar with Hadoop and the
23
+ creation of MapReduce jobs. Additional information on how to write
24
+ Map Reduce jobs can be found at the Hadoop website
25
+ (http://hadoop.apache.org/).
26
+
27
+ The version of Hadoop used by Amazon Elastic MapReduce is 0.20.
28
+ We also support Hadoop version 0.18.
29
+
30
+ == Conventions Used in this Document
31
+
32
+ Commands that you execute from a bash shell are indented and begin
33
+ with $.
34
+
35
+ $ echo "This is an example"
36
+ This is an example
37
+
38
+ The output of the command is sometimes shown directly below the
39
+ command.
40
+
41
+ Sometimes examples contain a value that you should modify for your own
42
+ situation, for example:
43
+
44
+ $ elastic-mapreduce --jobflow j-ABABABABAB --terminate
45
+
46
+ In this example, you should replace j-ABABABABAB with the id of the
47
+ jobflow that you wish to terminate. Another common example is
48
+ s3://mybucket/input. You should replace this with a path in to S3
49
+ that contains the data that you want to process.
50
+
51
+ Other times a value for replacement will be enclosed in angle
52
+ brackets. For example, <insert_your_aws_access_id_here>. You should
53
+ replace this with your AWS access id including the angle brackets.
54
+ For example:
55
+
56
+ "access-id": "<insert your AWS access id here>",
57
+
58
+ becomes
59
+
60
+ "access-id": "AAAAAJABASBASBJASAAA",
61
+
62
+ == Installation and Dependencies
63
+
64
+ The Amazon Elastic MapReduce Ruby client requires Ruby version 1.8.
65
+ It has been tested on Linux computers. The Ruby client can be run on Windows computers, but has not been fully tested.
66
+
67
+ To run the client you will need to have signed up for Amazon Elastic
68
+ MapReduce Service at http://aws.amazon.com. Amazon Elastic MapReduce
69
+ uses Amazon Elastic Compute Cloud (EC2) to run your job flows and Amazon
70
+ Simple Storage Service (S3) to store and access your data. After
71
+ completing the sign-up process, you can use Amazon
72
+ Elastic Compute Cloud and Simple Storage Service.
73
+
74
+ === Step 1: Download and Install Ruby
75
+
76
+ If you already have Ruby installed, you can skip this step. On Ubuntu
77
+ and Debian computers you install Ruby with:
78
+
79
+ $ apt-get install ruby1.8
80
+
81
+ On Redhat computers you can install Ruby with
82
+
83
+ yum install ruby
84
+
85
+ On Macintosh computersyou should already have Ruby installed.
86
+
87
+ On Windows computers you can install Ruby using the 1-click Windows installer
88
+ for Ruby. We recommend you install the final release available at:
89
+
90
+ http://rubyinstaller.rubyforge.org/wiki/wiki.pl
91
+
92
+ You can verify that Ruby is installed by typing
93
+
94
+ ruby -v
95
+
96
+ at the command prompt.
97
+
98
+ === Step 2: Download the Amazon Elastic MapReduce Ruby Client
99
+
100
+ The latest version of the Ruby client can be obtained by
101
+
102
+ $ mkdir elastic-mapreduce-ruby
103
+ $ cd elastic-mapreduce-ruby
104
+ $ wget http://elasticmapreduce.s3.amazonaws.com/elastic-mapreduce-ruby.zip
105
+
106
+ Unzip the archive
107
+
108
+ $ unzip elastic-mapreduce-ruby.zip
109
+
110
+ === Step 2a: Edit Your Path
111
+
112
+ If you're running bash or zsh as your shell, then you can add the directory
113
+ where you installed the elastic-mapreduce program to your path with the command:
114
+
115
+ $ export PATH=$PATH:<directory_where_you_unzipped_elastic_mapreduce_client>
116
+
117
+ For csh or tcsh
118
+
119
+ $ set path = ($path <directory_where_you_unzipped_elastic_mapreduce_client>
120
+
121
+ === Step 3: Create a Credentials File
122
+
123
+ Ensure you are already in the elastic-mapreduce-ruby
124
+ directory. Use your AWS access key and private key in the
125
+ following command. These credentials are available on the
126
+ http://aws.amazon.com website under "Your Account/Access Identifiers"
127
+ (top right).
128
+
129
+ $ cat > credentials.json
130
+ {
131
+ "access-id": "<insert your AWS access id here>",
132
+ "private-key": "<insert your AWS secret access key here>",
133
+ "key-pair": "<insert the name of your Amazon ec2 key-pair here>",
134
+ "key-pair-file": "<insert the path to the .pem file for your Amazon ec2 key pair here>",
135
+ "region": "<The region where you wish to launch your job flows. Should be one of us-east-1, us-west-1, eu-west-1, ap-southeast-1 or ap-northeast-1>"
136
+ }
137
+
138
+ Windows Users: If you are running a Windows computer then create a
139
+ credentials.json file using notepad.exe with the content above inserted between
140
+ the braces.
141
+
142
+ You do not have to include a key-pair in the credentials file, but it
143
+ is a good idea to include it so that when you run job flows you will
144
+ be able to log onto the master node to see the log files.
145
+
146
+ If you don't have an EC2 key-pair, you can create one at:
147
+
148
+ https://console.aws.amazon.com/ec2/home#c=EC2&s=KeyPairs
149
+
150
+ Save the pem file somewhere safe for use later. You will need it to log onto
151
+ the master node running your job flow.
152
+
153
+ If region is not specified, the client will default to us-east-1. Because you
154
+ pay for cross-region data transfer, the region you create your job flows
155
+ should be the one where your S3 input data exists.
156
+
157
+ Note: If you have credentials in a file other than credentials.json which is located
158
+ in the current directory, then you can specify a credentials file on the command
159
+ line with the following command:
160
+
161
+ $ elastic-mapreduce -c <yourcredentialsfile>.json --list
162
+
163
+ Windows Users: Windows users must specify "ruby" on the command line
164
+ instead of "./". The command would be:
165
+
166
+ C:\> ruby elastic-mapreduce -c <yourcredentialsfile>.json --list
167
+
168
+ You can also specify and AWS access id and private key and key pair on the command line.
169
+
170
+ $ elastic-mapreduce -a <access-id> -k <private-key> --key-pair <key-pair> --list
171
+
172
+ Similarly, you can specify a region on the command line.
173
+
174
+ $ elastic-mapreduce --region us-east-1 --list
175
+
176
+ Note that job flow listings are region specific. If you create a job
177
+ flow with region eu-west-1 then you will not be able to see it in the list if you
178
+ specify us-east-1.
179
+
180
+ == Basic Usage
181
+
182
+ You can get a summary of supported command line options with:
183
+
184
+ $ elastic-mapreduce --help
185
+
186
+ === Listing Job Flows
187
+
188
+ The web service supports the following operations: --list, --describe,
189
+ --create, --terminate, --stream, and --jar. To list job flows created in the
190
+ last 2 days:
191
+
192
+ $ elastic-mapreduce --list
193
+ j-1YE2DN7RXJBWU FAILED Example Job Flow
194
+ CANCELLED Custom Jar
195
+ j-3GJ4FRRNKGY97 COMPLETED ec2-67-202-3-73.compute-1.amazonaws.com Example job flow
196
+ j-5XXFIQS8PFNW COMPLETED ec2-67-202-51-30.compute-1.amazonaws.com demo 3/24 s1
197
+ COMPLETED Custom Jar
198
+
199
+ If you have not created any job flows in the last two days
200
+ no output returns from the command.
201
+
202
+ The example above shows three job flows created in the last two days. The
203
+ indented lines are job flow steps. The columns for a job flow line are
204
+ Job Flow Id, Job Flow State, Master Node DNS Name, and Job Flow
205
+ Name. The columns for a job flow step line are Step State, and Step
206
+ Name.
207
+
208
+ To get more information about a specific job flow use --describe and
209
+ supply the job flow id with the --jobflow parameters.
210
+
211
+ $ elastic-mapreduce --describe --jobflow <job_flow_id>
212
+ {
213
+ "JobFlows": [
214
+ {
215
+ "LogUri": null,
216
+ "Name": "Development Job Flow",
217
+ "ExecutionStatusDetail": {
218
+ "EndDateTime": 1237948135.0,
219
+ "CreationDateTime": 1237947852.0,
220
+ "LastStateChangeReason": null,
221
+ "State": "COMPLETED",
222
+ "StartDateTime": 1237948085.0,
223
+ "ReadyDateTime": 1237948085.0
224
+ },
225
+ "Steps": [],
226
+ "Instances": {
227
+ "Ec2KeyName": null,
228
+ "InstanceCount": 1.0,
229
+ "Placement": {
230
+ "AvailabilityZone": "us-east-1a"
231
+ },
232
+ "KeepJobFlowAliveWhenNoSteps": false,
233
+ "TerminationProtected": false,
234
+ "MasterInstanceType": "m1.small",
235
+ "SlaveInstanceType": "m1.small",
236
+ "MasterPublicDnsName": "ec2-67-202-3-73.compute-1.amazonaws.com",
237
+ "MasterInstanceId": "i-39325750",
238
+ "NormalizedInstanceHours": 6,
239
+ "InstanceCount": 3
240
+ },
241
+ "JobFlowId": "j-3GJ4FRRNKGY97"
242
+ }
243
+ ]
244
+ }
245
+
246
+ You can also list running and starting jobs with:
247
+
248
+ $ elastic-mapreduce --list --active
249
+
250
+ This will list job flows that are starting, running, or shutting
251
+ down. You can also list job flows that are in one of several states
252
+ with:
253
+
254
+ $ elastic-mapreduce --list --state RUNNING --state TERMINATED
255
+
256
+ This will list job flows that are either running or terminated.
257
+
258
+ === Running a Development Job Flow
259
+
260
+ When developing steps for a job flow it is handy to keep a job flow
261
+ running and to add steps to it. This way if the step fails you can
262
+ add another step without having to incur the startup cost of a
263
+ job flow.
264
+
265
+ The following command will start a job flow that will continue running and consuming resources until you terminate it.
266
+
267
+ $ elastic-mapreduce --create --alive --log-uri s3://my-example-bucket/logs
268
+ Created job flow j-36U2JMAE73054
269
+
270
+ By default, this command will launch a job flow running on a single m1.small
271
+ instance using Hadoop version 0.20. Later, when you have your steps
272
+ running correctly on small set of sample data, you will want to launch job flows
273
+ running on more instance. You can specify the number of instance and
274
+ the type of instance to run with the --num-instances and --instance-type
275
+ options.
276
+
277
+ The --alive option tells the job flow to keep running even when it has
278
+ finished all its steps. The log-uri specifies a location in Amazon S3 for
279
+ the log files from your job flow to be pushed.
280
+
281
+ --alive option can be safely omitted if you have not yet created a bucket in Amazon
282
+ S3. Log files are not pushed to Amazon S3 until 5 minutes after the
283
+ step is complete.
284
+
285
+ For debugging sessions, you will likely log onto
286
+ the master node of your job flow. Specifying a log-uri is required if
287
+ you want to be able to read log files from Amazon S3 after the job flow has
288
+ terminated.
289
+
290
+ You can use Hadoop version 0.18 by specifying the --hadoop-version option.
291
+
292
+ $ elastic-mapreduce --create --alive --log-uri s3://my-example-bucket/logs \
293
+ --hadoop-version "0.18"
294
+
295
+ Now that your job flow is created, you can add a streaming step
296
+ to the job flow.
297
+
298
+ $ elastic-mapreduce --jobflow <j-insert your job id here> --stream
299
+ Added steps to <j-insert your job id here>
300
+
301
+ Default parameters are added to the streaming step. The name is set to
302
+ "Example Streaming Step". The action on failure is set to
303
+ "CANCEL_AND_WAIT". This means that if the step fails then subsequent
304
+ steps will be cancelled and the job flow will wait for additional
305
+ steps to be added before proceeding. The streaming task is a word count
306
+ example written in Python and reads input from:
307
+
308
+ s3://elasticmapreduce/samples/wordcount/input
309
+
310
+ You can list the job flow to see the default parameters that have been
311
+ set.
312
+
313
+ $ elastic-mapreduce --jobflow j-36U2JMAE73054 --describe
314
+ { "JobFlows": [{
315
+ "LogUri": null,
316
+ "Name": "Example job flow",
317
+ "ExecutionStatusDetail": { ... },
318
+ "Steps": [
319
+ { "StepConfig": { ... },
320
+ "ExecutionStatusDetail": { ... }
321
+ }
322
+ ],
323
+ "Instances": { ... }
324
+ }]
325
+ }
326
+
327
+ === Debugging a Failed Step
328
+
329
+ First, add a step to the job flow that will fail. If you do not
330
+ have a running job flow, look at the section on running job flows above to
331
+ see how to start a job flow that will wait for you to add steps.
332
+
333
+ $ elastic-mapreduce --jobflow j-36U2JMAE73054 --stream --output hdfs://examples/output
334
+ Added steps to j-36U2JMAE73054
335
+
336
+ This job will fail because the HDFS path is wrong. It should have
337
+ three slashes rather than two after the colon. Now log onto the
338
+ master node where the job flow is running to find the log files associated with this step.
339
+
340
+ If you entered a keypair and a keypair file into the credentials
341
+ file you can now log onto the master node with:
342
+
343
+ $ elastic-mapreduce --jobflow j-ABABABABABA --ssh
344
+
345
+ For this command to work, you are require to have an ssh client installed on
346
+ your local computer. Most unix and linux
347
+ machines have an ssh client installed. On a Windows computer you will need to install Cygwin, including the Ruby and
348
+ openssh-client and execute the elastic-mapreduce client from within
349
+ Cygwin.
350
+
351
+ You can also use PuTTY, but this is significantly more work. See the
352
+ tutorial at http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2729.
353
+
354
+ Once logged into the master node where your job flow is running, you can see log files for your steps in:
355
+
356
+ $ ls /mnt/var/log/hadoop/steps/
357
+ 1
358
+ $ ls /mnt/var/log/hadoop/steps/1
359
+ controller stderr stdout syslog
360
+ $ cat /mnt/var/log/hadoop/steps/1/syslog
361
+ 2009-03-25 18:43:27,145 WARN org.apache.hadoop.mapred.JobClient (main): Use
362
+ GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
363
+ 2009-03-25 18:43:28,828 ERROR org.apache.hadoop.streaming.StreamJob (main): Error
364
+ Launching job : unknown host: examples
365
+ $ exit
366
+
367
+ The error from Hadoop indicates that it was trying to look for a host
368
+ called examples. Look back at our request and see that the output
369
+ path was set to hdfs://examples/output. This is incorrect
370
+ since we want Hadoop to access the local HDFS system with the path
371
+ /examples/output. We need to specify hdfs:///examples/output,
372
+ as below.
373
+
374
+ To fix this, specify the output of the streaming job on the
375
+ command line and submit another step to our job flow.
376
+
377
+ $ elastic-mapreduce --jobflow j-36U2JMAE73054 --stream --output hdfs:///examples/output
378
+
379
+ Now list the job flows and watch it complete:
380
+
381
+ $ elastic-mapreduce --list -n 5
382
+ j-36U2JMAE73054 WAITING ec2-67-202-20-49.compute-1.amazonaws.com Example job flow
383
+ FAILED Example Streaming Step
384
+ COMPLETED Example Streaming Step
385
+
386
+ This time the job succeeded. We can run the job again but this time
387
+ output the result to a bucket in Amazon S3. First, create a bucket
388
+ in Amazon S3. Note that buckets in Amazon S3 are unique so you will
389
+ need to choose a unique name for your bucket.
390
+
391
+ You can create a bucket using s3cmd which is available on Debian and
392
+ Ubuntu systems via apt-get, or using Amazon S3 Organizer which is a
393
+ plug-in for Firefox.
394
+
395
+ If you're not on a Debian or Ubuntu system then s3cmd can be
396
+ downloaded from http://freshmeat.net/projects/s3cmd
397
+
398
+ Amazon S3 Organizer is available at
399
+ https://addons.mozilla.org/en-US/firefox/addon/3247
400
+
401
+ To create an Amazon S3 bucket using s3cmd do the following:
402
+
403
+ $ s3cmd mb s3://my-example-bucket
404
+ Bucket 's3://my-example-bucket/' created
405
+
406
+ Note: s3cmd requires s3 paths to be specified using the prefix s3://.
407
+ Amazon Elastic MapReduce follows Hadoop’s convention which requires the
408
+ prefix s3:// for files in stored in Amazon S3.
409
+
410
+ Add a step to the job flow to put results into the bucket
411
+ you created on S3:
412
+
413
+ $ elastic-mapreduce -j j-36U2JMAE73054 --stream \
414
+ --output s3://my-example-bucket/output/1
415
+ Added steps to j-36U2JMAE73054
416
+
417
+ Note that the protocol of the output URL is s3. This tells Hadoop to
418
+ use the S3 Native File System for the output location. The 'host' part
419
+ of the URL is the bucket and this is followed by path.
420
+
421
+ Once you've finished with your job flow, don't forget to terminate it with:
422
+
423
+ $ elastic-mapreduce --jobflow j-36U2JMAE73054 --terminate
424
+
425
+ And see that it is shutting down with:
426
+
427
+ $ elastic-mapreduce --list -n 5
428
+
429
+ There are other options that you can specify when creating and adding
430
+ steps to job flows. Use the "--help" option to list them.
431
+
432
+ You can also list the log files from the last step in your jobflow
433
+ using the --logs argument.
434
+
435
+ $ elastic-mapreduce --jobflow j-ABABABABABA --logs
436
+
437
+ This command requires that you are running on a unix-like
438
+ computer with access to an ssh client because it fetches the logs from
439
+ the job flow. It also requires that the job flow is still running. If
440
+ the job flow has shutdown then the client may hang while attempting to
441
+ connect to the master node because the master node has already been
442
+ shut down.
443
+
444
+ ==== Enabling Hadoop Debugging
445
+
446
+ The Amazon Elastic MapReduce tab in the AWS Management Console
447
+ (http://console.aws.amazon.com/elasticmapreduce/home) has a debugging
448
+ feature that provides access to Hadoop jobs, tasks, and task attempts
449
+ as well as log files for steps and task attempts.
450
+
451
+ Note: To use this feature you must be signed up for SimpleDB. You can sign
452
+ up your account for Simple DB at http://aws.amazon.com/simpledb/.
453
+
454
+ Note: When enabling debugging, you must always specify a log-uri
455
+ either in your credentials file, on the command line, or as an
456
+ environment variable.
457
+
458
+ To enable Hadoop Debugging on a job flow run your job flow with the
459
+ --enable-debugging option.
460
+
461
+ $ elastic-mapreduce --create \
462
+ --name "$USER's Flow with Debugging Enabled" --alive \
463
+ --log-uri s3://mybucket/logs
464
+ --enable-debugging
465
+ Created jobflow j-ABABABABA
466
+
467
+ Make sure that you sepcified a log-uri on the command line as above or
468
+ in your credentials file. This command install a component on your job
469
+ flow that pushes information from Hadoop into Amazon Simple DB.
470
+
471
+ Next add a job flow step to your job flow
472
+
473
+ $ elastic-mapreduce --jobflow j-ABABABABA \
474
+ --stream --output hdfs:///output/1
475
+
476
+ Now you can watch the progress of our job flow in Amazon Elastic
477
+ MapReduce tab of the AWS Management Console, by first selecting the
478
+ job flow (click refresh if your job flow has not appeared) and then
479
+ clicking the "Debug" button.
480
+
481
+ ==== Adding a JAR Step
482
+
483
+ To add a JAR step you should already have started a job flow. If you have not, see
484
+ the "Running a Job Flow" section in this document.
485
+
486
+ First start a development job flow
487
+
488
+ $ elastic-mapreduce --list --active
489
+ j-36U2JMAE73054 WAITING ec2-67-202-20-49.compute-1.amazonaws.com Example job flow
490
+ FAILED Example Streaming Step
491
+ COMPLETED Example Streaming Step
492
+ COMPLETED Example Streaming Step
493
+
494
+ You can add a JAR step to your job flow with:
495
+
496
+ $ elastic-mapreduce --job flow j-36U2JMAE73054 \
497
+ --jar s3://elasticmapreduce/samples/cloudburst/cloudburst.jar \
498
+ --arg s3://elasticmapreduce/samples/cloudburst/input/s_suis.br \
499
+ --arg s3://elasticmapreduce/samples/cloudburst/input/100k.br \
500
+ --arg hdfs:///cloudburst/output/1 \
501
+ --arg 36 --arg 3 --arg 0 --arg 1 --arg 240 --arg 48 --arg 24 \
502
+ --arg 24 --arg 128 --arg 16
503
+
504
+ Windows Users: The Windows command-line interface does not allow multi-line
505
+ commands using the “\” character. You will have to edit these multi-line
506
+ examples in notepad to remove the “\” characters and the line breaks.
507
+
508
+ This will run an example job flow step that downloads and runs the
509
+ JAR file. The arguments are passed to the main function in the JAR file.
510
+
511
+ If your JAR file doesn't have a manifest.mf specifying the main class you will
512
+ need to specify the main class on the command line as:
513
+
514
+ $ elastic-mapreduce -j j-36U2JMAE73054 \
515
+ --jar s3://my-example-bucket/wordcount.jar \
516
+ --main-class org.myorg.WordCount \
517
+ --arg s3://elasticmapreduce/samples/wordcount/input/ \
518
+ --arg hdfs:///wordcount/output/1
519
+
520
+ If your job fails then log onto the master node as explained in the
521
+ section "Running a JobFlow" and look at the log files to find out why.
522
+
523
+ ==== Adding a JobFlow from JSON
524
+
525
+ The samples directory included in with Elastic Map Reduce Ruby Client
526
+ contains several mutli-step job flows that can be run using the --json
527
+ command.
528
+
529
+ The json files contain variables for bucket names etc that you need to
530
+ replace with your own bucket.
531
+
532
+ $ elastic-mapreduce -j j-36U2JMAE73054 \
533
+ --json samples/similarity/lastfm_jobflow.json \
534
+ --param '<bucket>=my-example-bucket'
535
+
536
+ This will add the job flow steps described in
537
+ samples/freebase/code/freebase_jobflow.json with <bucket> replaced by
538
+ my-example-bucket.
539
+
540
+ === Samples
541
+
542
+ The samples directory contains the following sample job flows:
543
+
544
+ * LastFM Example
545
+ ** Description: Calculation of Artist Similarity using data From LastFM
546
+ ** URL: samples/similarity/lastfm_jobflow.json
547
+ ** Parameters
548
+ *** <bucket> : name of the output bucket
549
+
550
+ * Freebase Example
551
+ ** Description: Load popular entries from Freebase into Amazon SimpleDB
552
+ ** URL: samples/freebase/code/freebase_jobflow.json
553
+ ** Parameters
554
+ *** <bucket> : name of the output bucket
555
+
556
+ Additionally there are the following articles explaining how to use
557
+ Amazon Elastic MapReduce.
558
+
559
+ * Sample Job Flows
560
+ http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=263
561
+
562
+ * CloudBurst Sample Job Flow
563
+ http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2272
564
+
565
+ * WordCount Sample Job Flow
566
+ http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2273
567
+
568
+ * Similarities Sample Job Flow
569
+ http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2274
570
+
571
+ * Freebase Sample Job Flow
572
+ http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2275
573
+
574
+ === Running a Custom Jar
575
+
576
+ This section assumes that you have already run a streaming jar and
577
+ that you are comfortable starting and debugging job flows.
578
+
579
+ ==== Compiling and Uploading a Jar
580
+
581
+ First download a copy of Hadoop 0.18.3 from the Hadoop website.
582
+
583
+ http://hadoop.apache.org/core/
584
+
585
+ Unpack the tar.gz archive somewhere handy like
586
+ /home/name/hadoop-0.18.3 or c:\hadoop if you are running on windows.
587
+
588
+ Download Eclipse from http://www.eclipse.org/downloads/, choosing the "Eclipse IDE
589
+ for Java Developers" version.
590
+
591
+ In Eclipse, create a new Java Project. In the libraries tab of the
592
+ build path settings, add all of the Hadoop JAR files from the directory where
593
+ you unpacked Hadoop.
594
+
595
+ Next, create a main class in your project. An example main class is
596
+ available here:
597
+
598
+ http://hadoop.apache.org/core/docs/r0.18.3/mapred_tutorial.html.
599
+
600
+ You can cut and paste the WordCount v1.0 source code from the browser
601
+ into Eclipse.
602
+
603
+ Now get Eclipse to export a JAR file by selecting "Export" from the File
604
+ Menu and then choosing Jar. Select an output location for the JAR file on
605
+ your disk and click through the next several pages until you are able to specify a
606
+ Main-Class in the Java manifest. Choose the main function you added in
607
+ the previous step.
608
+
609
+
610
+ Upload your JAR file to s3. To upload a file, you can use s3cmd which is
611
+ available under Debian and Ubuntu. On Windows computers, a good option is S3
612
+ Organizer which is a Firefox plugin. For this example, I'm going to use
613
+ s3cmd.
614
+
615
+ You will have to select your own unique bucket name when running this
616
+ example as the my-example-bucket already exists.
617
+
618
+ $ s3cmd mb s3://my-example-bucket
619
+ Bucket 's3://my-example-bucket/' created
620
+
621
+ $ s3cmd put --force build/wordcount.jar s3://my-example-bucket/wordcount.jar
622
+
623
+ Note that by default s3cmd sets the access control on the created bucket
624
+ and uploaded file to private which is probably what is wanted. If you want
625
+ to make your step accessible to other people, you will need to set the
626
+ access control on the bucket and the file to make them readable.
627
+
628
+ Now you are ready to execute a jar step on one of your job flows. If you
629
+ don't have job flow running, look at the section on running a job flow
630
+ to learn how to start a job flow.
631
+
632
+ Remember to replace your own job flow id and the name
633
+ of your own bucket in the jar name and the second --arg parameter.
634
+
635
+ $ elastic-mapreduce --jobflow j-C019299B1X \
636
+ --jar s3://my-example-bucket/wordcount.jar \
637
+ --arg s3://elasticmapreduce/samples/wordcount/input
638
+ --arg s3://my-example-bucket/output
639
+
640
+ If you didn't specify the main-class in the manifest then you can
641
+ specify that now on the command line with the --main-class option.
642
+
643
+ $ elastic-mapreduce --jobflow j-C019299B1X \
644
+ --jar s3://my-example-bucket/wordcount.jar \
645
+ --main-class org.myorg.WordCount \
646
+ --arg s3://elasticmapreduce/samples/wordcount/input \
647
+ --arg s3://my-example-bucket/output
648
+
649
+ You can watch the job flow by listing it.
650
+
651
+ $ elastic-mapreduce --list j-C019299B1X
652
+
653
+ If the step fails then take a look at the section on debugging a
654
+ job flow to find out how to log onto the master node and look at the
655
+ logs.
656
+
657
+ === Running a Pig Program
658
+
659
+ Pig provides a high level data manipulation language called Pig
660
+ Latin. Amazon Elastic MapReduce supports Pig version 0.3.0 See
661
+ http://hadoop.apache.org/pig/ for additional details.
662
+
663
+ ==== Running Pig in Interactive Mode
664
+
665
+ To run a pig program in interactive mode you need to create a jobflow
666
+ that will stay alive until you terminate it.
667
+
668
+ $ elastic-mapreduce --create --alive --name "Testing PIG -- $USER" \
669
+ --num-instances 5 --instance-type c1.large \
670
+ --hive-interactive
671
+ Created jobflow j-ABABABABABAB
672
+
673
+ Next ssh to the master node and run pig
674
+
675
+ $ elastic-mapreduce --jobflow j-ABABABABABAB --ssh
676
+ ...
677
+ ec2-12.13.14 $ pig
678
+ grunt>
679
+
680
+ You are now running Pig in interactive mode and can execute Pig Latin statements.
681
+
682
+ ==== Running Pig in Batch Mode
683
+
684
+ To run Pig in batch mode by adding a step to a development job flow you
685
+ run:
686
+
687
+ $ elastic-mapreduce --jobflow j-ABABABABABA \
688
+ --pig-script --args s3://mybucket/myscript.pig
689
+
690
+ Or to run a job flow that will execute a Pig script run:
691
+
692
+ $ elastic-mapreduce --create \
693
+ --pig-script \
694
+ --args -p,INPUT=s3://mybucket/input,-p,OUTPUT=s3://mybucket/output \
695
+ --args s3://mybucket/myscript.pig
696
+
697
+ Note that the script argument must come last, after the parameters that
698
+ are passed to the script. These parameters become available within the
699
+ Pig script being executed as $variable. In the above example, the
700
+ script can make reference to $input and $output within Pig string
701
+ literals.
702
+
703
+ You can also execute multiple Pig scripts
704
+ within a single job flow as
705
+
706
+ $ elastic-mapreduce --create \
707
+ --pig-script --step-name "Script 1" --args s3://mybucket/myscript.pig \
708
+ --pig-script --step-name "Script 2" --args s3://mybucket/mysecondscript.pig
709
+
710
+ You can also specify multiple scripts to be added to a development
711
+ Job flow in the same way.
712
+
713
+ === Running a Hive Program
714
+
715
+ Hive is a high level data processing language quite similar to SQL but
716
+ with a number of map reduce extensions. Amazon Elastic MapReduce
717
+ supports Hive version 0.5 on Hadoop version 0.20 and Hive version 0.4
718
+ on Hadoop version 0.18. For both the versions of Hive, we provide additional
719
+ patches that allow better integration with Amazon S3.
720
+
721
+ Please note that Hive automatically defaults to 0.5 for Hadoop 0.20 and
722
+ 0.4 for Hadoop 0.18. Currently Amazon Elastic MapReduce does not support specifying the Hive
723
+ version.
724
+
725
+ Hive 0.5 provides additional features like Percentile function, faster
726
+ recovery of partitions from S3, insert query results into an s3 directory
727
+ location, and reading lzo, bzip compressed input files.
728
+
729
+ ==== Running Hive in Interactive Mode
730
+
731
+ To run in interactive mode you need to create a job flow that will stay
732
+ alive until you terminate it.
733
+
734
+ $ elastic-mapreduce --create --alive --name "Testing Hive -- $USER" \
735
+ --num-instances 5 --instance-type c1.large \
736
+ --hive-interactive
737
+ Created jobflow j-ABABABABABAB
738
+
739
+ Next ssh to the master node and run hive
740
+
741
+ $ elastic-mapreduce --jobflow j-ABABABABABAB --ssh
742
+ ...
743
+ ec2-12.13.14 $ hive
744
+ hive>
745
+
746
+ You are now running Hive in interactive mode and execute Hive queries.
747
+
748
+ ==== Running Hive in Batch Mode
749
+
750
+ To execute a Hive script stored in S3 as a part of a job flow create the
751
+ Job flow with a step that executes the Hive script
752
+
753
+ $ elastic-mapreduce --create \
754
+ --hive-script --args s3://mybucket/myquery.q \
755
+ --args -d,INPUT=s3://mybucket/input,-d,OUTPUT=s3://mybucket/output
756
+
757
+ The --args option provides arguments to the Hive script. The first
758
+ argument is the location of the script on S3. Next,the -d argument provides a method to pass values into the script.
759
+
760
+ Within Hive scripts these parameters are available as ${variable}. In the above example ${INPUT} and ${OUTPUT} would be replaced with
761
+ the values that were passed in. These variables are substituted as a
762
+ pre-processing step and so may occur anywhere within a Hive script.
763
+
764
+ You can also add a Hive script to a development job flow, for example:
765
+
766
+ $ elastic-mapreduce --jobflow j-ABABABABABA \
767
+ --hive-script --args s3://mybucket/myquery.q \
768
+ --args -d,INPUT=s3://mybucket/input,-d,OUTPUT=s3://mybucket/output
769
+
770
+ This is useful when developing and testing scripts as in the case where
771
+ the script fails. You can add a new step to the development job flow
772
+ without having to wait for a new job flow to start.
773
+
774
+ === Terminating a Job Flow
775
+
776
+ All job flows that have been created with the --alive option will run,
777
+ consuming instance hours until they are terminated.
778
+
779
+ A job flow can be terminated by specifying the job flow id.
780
+
781
+ $ elastic-mapreduce --terminate --jobflow j-C019299B1X
782
+
783
+ === Environment Variables
784
+
785
+ The command line client accepts configuration via environment
786
+ variables. The following environment variables are supported:
787
+
788
+ ELASTIC_MAPREDUCE_ACCESS_ID
789
+ ELASTIC_MAPREDUCE_PRIVATE_KEY
790
+ ELASTIC_MAPREDUCE_KEY_PAIR
791
+ ELASTIC_MAPREDUCE_KEY_PAIR_FILE
792
+ ELASTIC_MAPREDUCE_LOG_URI
793
+ ELASTIC_MAPREDUCE_REGION
794
+ ELASTIC_MAPREDUCE_ENABLE_DEBUGGING
795
+
796
+ The environment variables will override settings in the credentials
797
+ file, but will be overridden by options passed in on the command line.
798
+
799
+ === Bootstrap Actions
800
+
801
+ A bootstrap action is a script that is run on all nodes of a job flow
802
+ prior to Hadoop starting on that node. A job flow will fail if
803
+ bootstrap action fails by returning a non-zero exit code on the master
804
+ node, or on more than 10% of the slave nodes. A job flow will also
805
+ fail if Hadoop fails to start on the master node after the bootstrap
806
+ action has run.
807
+
808
+ For example, to execute a bootstrap action, first upload your script, called
809
+ action.sh, to your bucket in S3 called s3://mybucket
810
+
811
+ $ s3cmd put action.sh s3://mybucket/bootstrap-actions/action.sh
812
+
813
+ Next, start a job flow and specify the bootstrap action:
814
+
815
+ $ elastic-mapreduce --create --alive \
816
+ --name "My Boostrap Action" \
817
+ --bootstrap-action s3://mybucket/bootstrap-actions/action.sh \
818
+ --arg first-argument \
819
+ --arg second-argument
820
+
821
+ Bootstrap actions may only be specified when a job flow is
822
+ created. This is different to steps which may be specified for a
823
+ running job flow. When creating a job flow however one may combine
824
+ several bootstrap actions and job flow steps. The bootstrap actions
825
+ will be executed in the order they are presented.
826
+
827
+ $ BUCKET=s3://mybucket/
828
+ $ INPUT=$BUCKET/input
829
+ $ OUTPUT=$BUCKET/output
830
+ $ elastic-mapreduce --create \
831
+ --name "My Example Job Flow" \
832
+ --boostrap-action $BUCKET/bootstrap-actions/action.sh \
833
+ --arg hello \
834
+ --arg world \
835
+ --hive-script \
836
+ --args s3://mybucket/hive-queries/myquery.q \
837
+ --args -d,INPUT=$INPUT,-d,OUTPUT=$OUTPUT \
838
+ --bootstrap-action $BUCKET/bootstrap-actions/action.sh \
839
+ --args hello,world
840
+
841
+ Note that the bootstrap actions are always executed before steps and
842
+ before Hadoop is running on the node.
843
+
844
+ Log files from bootstrap actions are located on each node in the
845
+ directory:
846
+
847
+ /mnt/var/log/bootstrap-actions/<action_number>
848
+
849
+ where <action_number> is the number of the bootstrap action that was
850
+ run. For example,. 1 for the first action, 2 for the second etc. The bootstrap
851
+ action logs are also pushed to your LogURI if you specified one in
852
+ the directory
853
+
854
+ s3://<log_uri>/<jobflow_id>/node/<node_id>/bootstrap-actions/<action_number>
855
+
856
+ If a bootstap action fails, then an error message containing the
857
+ failure condition is located in the LastStateChangeReason field
858
+ available when using --describe on the job flow that failed.
859
+
860
+ === Example Bootstrap Actions
861
+
862
+ This section contains a list of example bootstrap actions that are
863
+ provided by Amazon Elastic MapReduce.
864
+
865
+ ==== Configure Hadoop
866
+
867
+ The configure-hadoop bootstrap action allows you specify Hadoop site
868
+ configuration that must be set before Hadoop starts. It may be called
869
+ as:
870
+
871
+ $ elastic-mapreduce --create --alive \
872
+ --name "My Example Jobflow" \
873
+ --bootstrap-actions s3://elasticmapreduce/bootstrap-actions/configure-hadoop
874
+ --arg --site-config-file
875
+ --arg s3://mybucket/config.xml
876
+ --arg -s
877
+ --arg mapred.tasktracker.map.tasks.maximum=2
878
+
879
+ This will merge setting from the file s3://mybucket/config.xml into
880
+ the Hadoop site config file and will additionally set the value of
881
+ mapred.tasktracker.map.tasks.maximum to 2 in the Hadoop site config
882
+ file.
883
+
884
+ For more usage information you can download the script and run it
885
+ with no arguments. In this case it will output its usage information.
886
+
887
+ ==== Configure Daemons
888
+
889
+ The configure daemons script allows you to control the amount of
890
+ memory allocated to different Hadoop daemons. It may be called as:
891
+
892
+ $ elastic-mapreduce --create --alive \
893
+ --name "My Example Jobflow" \
894
+ --bootstrap-actions s3://elasticmapreduce/bootstrap-actions/configure-daemons \
895
+ --arg --namenode-heap-size=2048 \
896
+ --arg --namenode-opts=-XX:GCTimeRatio=19 \
897
+
898
+ This will set the heap size allocated to the NameNode to be 2048
899
+ megabytes and it will set the GCTimeRatio used by the java's garbage
900
+ collector to be 19.
901
+
902
+ For more usage information you can download the script onto an
903
+ instance and run it with no arguments. In this case it will output its
904
+ usage information.
905
+
906
+ ==== Run-if
907
+
908
+ The run-if script allows you to run another script conditionally. It may be called as:
909
+
910
+ elastic-mapreduce --create --alive \
911
+ --name "My Example Jobflow" \
912
+ --bootstrap-actions s3://elasticmapreduce/bootstrap-actions/run-if
913
+ --args instance.isMaster=true,s3://mybucket/myscript,hello,world
914
+
915
+ This will run the script located at s3://mybucket/myscript, passing the
916
+ arguments "hello" and "world" only on the master node. If myscript
917
+ fails then run-if command will fail and so the job flow will fail.
918
+
919
+ For more usage information, you can download the script onto an
920
+ instance and run it with no arguments. In this case it will output its
921
+ usage information onto screen.
922
+
923
+ The first argument is a conditional that reads from one of the JSON
924
+ configuration files available on every instance. The files contain
925
+ information that may be useful for bootstrap action authors and with
926
+ the run-if script. The file locations and their contents are listed
927
+ below. When referencing files from the run-if script, you only need
928
+ to specify the file name, excluding ".json".
929
+
930
+ /mnt/var/lib/info/instance.json
931
+ boolean isMaster
932
+ boolean isRunningNameNode
933
+ boolean isRunningDataNode
934
+ boolean isRunningJobTracker
935
+ boolean isRunningTaskTracker
936
+
937
+ /mnt/var/lib/info/job-flow.json
938
+ string jobFlowId
939
+ long jobFlowCreationInstance
940
+ integer instanceCount
941
+ string masterInstanceId
942
+ string masterPrivateDnsName
943
+ string masterInstanceType
944
+ string slaveInstanceType
945
+ string hadoopVersion
946
+
947
+ == Using the Ruby Client as a Library
948
+
949
+ The program elastic-mapreduce is an example of how to use the
950
+ Amazon Elastic MapReduce Ruby library. Most of the library is
951
+ devoted to parsing command line arguments and translating them into
952
+ web service calls.
953
+
954
+ To use the web service directly in your Ruby programs you need:
955
+
956
+ $LOAD_PATH << File.dirname(__FILE__)
957
+ require 'amazon/coral/elasticmapreduceclient'
958
+
959
+ config = {
960
+ :endpoint => "https://elasticmapreduce.amazonaws.com",
961
+ :ca_file => File.join(File.dirname(__FILE__), "cacert.pem"),
962
+ :aws_access_key => my_access_id,
963
+ :aws_secret_key => my_secret_key,
964
+ :signature_algorithm => :V2
965
+ }
966
+ client = Amazon::Coral::ElasticMapReduceClient.new_aws_query(config)
967
+
968
+ puts client.DescribeJobFlows.inspect
969
+ puts client.DescribeJobFlows('JobFlowId' => 'j-ABAYAS1019012').inspect
970
+
971
+ You can use the retry delegator to make your client retry if it gets
972
+ connection failures.
973
+
974
+ $LOAD_PATH << File.dirname(__FILE__)
975
+ require 'amazon/coral/elasticmapreduceclient'
976
+ require 'amazon/retry_delegator'
977
+
978
+ config = {
979
+ :endpoint => "https://elasticmapreduce.amazonaws.com",
980
+ :ca_file => File.join(File.dirname(__FILE__), "cacert.pem"),
981
+ :aws_access_key => my_access_id,
982
+ :aws_secret_key => my_secret_key,
983
+ :signature_algorithm => :V2
984
+ }
985
+ client = Amazon::Coral::ElasticMapReduceClient.new_aws_query(config)
986
+
987
+ is_retryable_error_response = Proc.new do |response|
988
+ if response == nil then
989
+ false
990
+ else
991
+ ret = false
992
+ if response['Error'] then
993
+ # don't retry on 'Timeout' because the call might have succeeded
994
+ ret ||= ['InternalFailure', 'Throttling', 'ServiceUnavailable'].include?(response['Error']['Code'])
995
+ end
996
+ ret
997
+ end
998
+ end
999
+
1000
+ client = Amazon::RetryDelegator.new(client, :retry_if => is_retryable_error_response)
1001
+
1002
+ puts client.DescribeJobFlows.inspect
1003
+ puts client.DescribeJobFlows('JobFlowId' => 'j-ABAYAS1019012').inspect
1004
+
1005
+ More information about the operations of the Amazon Elastic MapReduce
1006
+ Web Service is available in the technical documentation found at http://aws.amazon.com/documentation/elasticmapreduce/.
1007
+