Amazon Web Services (AWS)

AWS Command Line Tools
You may want to install the AWS command line tools, which will allow you to (among other things) download files in bulk from S3.

If you are having problems with getting it to work under Windows, you may want to install it under Cygwin: http://www.thecoatlessprofessor.com/programming/installing-amazon-web-services-command-line-interface-aws-cli-for-windows-os-x-and-linux-2

Configuring AWS CLI
Once you get it installed, run:

aws configure

You will have to enter your:

AWS Access Key ID:

AWS Secret Access Key:

Default region name: us-east-1

Default output format: (doesn't matter)

Example AWS CLI Command
To upload a full directory of files to an S3 bucket:

aws s3 cp ghcnd_all/ s3://ghcnd-all/ --recursive

Running a Java MapReduce program on Amazon Web Services Elastic MapReduce
These instructions assume that you are using a particular directory for all your MapReduce projects, e.g. CS-383.

Get the Hadoop jars into a local directory where you can use them in your classpath when compiling
 Download the latest version of hadoop:  Go to http://www.apache.org/dyn/closer.cgi/hadoop/common/ Choose hadoop-2.7.3.tar.gz  Unzip and untar the file.  Instructions for Windows here.  Move the whole hadoop directory to the top level of your directory you are using for the course.</li></ol>

Create a directory for your FlightsByCarrier code

 * 1) Create a directory below your course directory to hold your code e.g. FlightsByCarrier

Get the OpenCSV jar
The FlightsByCarrier program uses OpenCSV to read the flight data CSV files.

<ol style="list-style-type: decimal;"> Download the latest version of OpenCSV: <ol start="2" style="list-style-type: decimal;"> Go to https://sourceforge.net/projects/opencsv/?source=typ_redirect</li></ol> </li> Unzip the opencsv-3.8.jar file to a folder called opencsv-3.8</li> Move the whole com subdirectory to the top level of your Flights-ByCarrier directory.</li></ol>

Edit and compile your Java code
<ol style="list-style-type: decimal;"> Change to your FlightsByCarrier directory</li> Write your code <ol start="2" style="list-style-type: decimal;"> Changes to the code in the textbook: <ol start="3" style="list-style-type: decimal;"> Leave out all @@# comments - your code will not compile</li>  FlightsByCarrier driver application: Replace  with  </li>  FlightsByCarrier mapper code: Replace  with  </li></ol> </li></ol> </li>  Compile your code with the correct version of Java, and with the Hadoop, and OpenCSV libraries: This version is split across multiple lines. This will not work if you copy and paste it. javac -target 1.7 -source 1.7 -classpath ../hadoop-2.7.3/share/hadoop/yarn/*: ../hadoop-2.7.3/share/hadoop/yarn/lib/*:../hadoop-2.7.3/share/hadoop/mapreduce/*: ../hadoop-2.7.3/share/hadoop/mapreduce/lib/*:../hadoop-2.7.3/share/hadoop/common/*: . *.java Single line version to copy and paste: javac -target 1.7 -source 1.7 -classpath ../hadoop-2.7.3/share/hadoop/yarn/*:../hadoop-2.7.3/share/hadoop/yarn/lib/*:../hadoop-2.7.3/share/hadoop/mapreduce/*:../hadoop-2.7.3/share/hadoop/mapreduce/lib/*:../hadoop-2.7.3/share/hadoop/common/*:. *.java </li>  Make a jar file with all the classes: </li></ol>

(Optional) Install AWS Command Line Interface
The AWS CLI makes it easier to upload and download multiple files, and can create and run clusters without having to connect to the AWS web interface.

To install it go here

Upload your jar and data files (Web Interface)

 * 1) Log in AWS
 * 2) Go to S3
 * 3) Upload FlightsByCarrier.jar to your bucket
 * 4) Create a folder flight-data
 * 5) Upload your CSV file to the flight-data folder

Upload your jar and data files (CLI Interface)
Note: Adjust bucket names to correspond to your own buckets.

<ol start="2" style="list-style-type: decimal;">  Upload FlightsByCarrier.jar to your bucket: </li>  Create a folder flight-data and upload your CSV file to the flight-data folder: </li></ol>

Create a cluster and run your job (Web Interface)
Note: Adjust bucket names to correspond to your own buckets.

<ol style="list-style-type: decimal;"> Go to EMR</li> Click Create Cluster</li> <li>Click on Go to advanced options</li> <li>Step 1: Software and Steps: <ol style="list-style-type: decimal;"> <li>Uncheck all tools except Hadoop 2.7.3</li> <li>Step type: Custom jar</li> <li>Click on Configure <ol start="5" style="list-style-type: decimal;"> <li>Name: FlightsByCarrier</li> <li>JAR Location: select the jar you uploaded</li> <li> Arguments: FlightsByCarrier s3://kwurst-cs-383/flight-data s3://kwurst-cs-383/flight-output '''Note: the output bucket name must not exist or your cluster will fail. Either delete any previous bucket with that name, or use a new name.'''</li> <li>Action on failure: Terminate Cluster</li> <li>Click on Add</li></ol> </li> <li>Click on Next</li></ol> </li> <li>Step 2:Hardware: <ol start="3" style="list-style-type: decimal;"> <li>Click on Next</li></ol> </li> <li>Step 3: General Cluster Settings: <ol start="4" style="list-style-type: decimal;"> <li>Cluster name: kwurst-FlightsByCarrier</li> <li>Uncheck Debugging</li> <li>Uncheck Termination protection</li> <li>Scale down behavior: Terminate at task completion</li> <li>Click on Next</li></ol> </li> <li>Step4: Security:</li> <li>Click on Create Cluster</li></ol>

Create a cluster and run your job (CLI Interface)
Note: Adjust bucket names to correspond to your own buckets.

'''Note: the output bucket name must not exist or your cluster will fail. Either delete any previous bucket with that name, or use a new name.'''

This was generated by clicking on the AWS CLI export button on the cluster page for the cluster created above.

This version is split across multiple lines. This will not work if you copy and paste it.

aws emr create-cluster --applications Name=Hadoop --ec2-attributes '{&quot;InstanceProfile&quot;:&quot;EMR_EC2_DefaultRole&quot;,&quot;SubnetId&quot;:&quot;subnet-0330be74&quot;, &quot;EmrManagedSlaveSecurityGroup&quot;:&quot;sg-2620a442&quot;,&quot;EmrManagedMasterSecurityGroup&quot;:&quot;sg-2520a441&quot;}' --release-label emr-5.3.0 --log-uri 's3n://aws-logs-318063560001-us-east-1/elasticmapreduce/' --steps '[{&quot;Args&quot;:[&quot;FlightsByCarrier&quot;,&quot;s3://kwurst-cs-383/flight-data&quot;, &quot;s3://kwurst-cs-383/flightoutput&quot;],&quot;Type&quot;:&quot;CUSTOM_JAR&quot;,&quot;ActionOnFailure&quot;:&quot;TERMINATE_CLUSTER&quot;, &quot;Jar&quot;:&quot;s3://kwurst-cs-383/FlightsByCarrier.jar&quot;,&quot;Properties&quot;:&quot;&quot;,&quot;Name&quot;:&quot;FlightsByCarrier&quot;}]' --instance-groups '[{&quot;InstanceCount&quot;:2,&quot;InstanceGroupType&quot;:&quot;CORE&quot;,&quot;InstanceType&quot;:&quot;m3.xlarge&quot;, &quot;Name&quot;:&quot;Core - 2&quot;},{&quot;InstanceCount&quot;:1,&quot;InstanceGroupType&quot;:&quot;MASTER&quot;,&quot;InstanceType&quot;:&quot;m3.xlarge&quot;, &quot;Name&quot;:&quot;Master - 1&quot;}]' --auto-terminate --auto-scaling-role EMR_AutoScaling_DefaultRole --service-role EMR_DefaultRole --name 'kwurst-FlightsByCarrier' --scale-down-behavior TERMINATE_AT_TASK_COMPLETION --region us-east-1 Single line version to copy and paste:

aws emr create-cluster --applications Name=Hadoop --ec2-attributes '{&quot;InstanceProfile&quot;:&quot;EMR_EC2_DefaultRole&quot;,&quot;SubnetId&quot;:&quot;subnet-0330be74&quot;,&quot;EmrManagedSlaveSecurityGroup&quot;:&quot;sg-2620a442&quot;,&quot;EmrManagedMasterSecurityGroup&quot;:&quot;sg-2520a441&quot;}' --release-label emr-5.3.0 --log-uri 's3n://aws-logs-318063560001-us-east-1/elasticmapreduce/' --steps '[{&quot;Args&quot;:[&quot;FlightsByCarrier&quot;,&quot;s3://kwurst-cs-383/flight-data&quot;,&quot;s3://kwurst-cs-383/flight-output&quot;],&quot;Type&quot;:&quot;CUSTOM_JAR&quot;,&quot;ActionOnFailure&quot;:&quot;TERMINATE_CLUSTER&quot;,&quot;Jar&quot;:&quot;s3://kwurst-cs-383/FlightsByCarrier.jar&quot;,&quot;Properties&quot;:&quot;&quot;,&quot;Name&quot;:&quot;FlightsByCarrier&quot;}]' --instance-groups '[{&quot;InstanceCount&quot;:2,&quot;InstanceGroupType&quot;:&quot;CORE&quot;,&quot;InstanceType&quot;:&quot;m3.xlarge&quot;,&quot;Name&quot;:&quot;Core - 2&quot;},{&quot;InstanceCount&quot;:1,&quot;InstanceGroupType&quot;:&quot;MASTER&quot;,&quot;InstanceType&quot;:&quot;m3.xlarge&quot;,&quot;Name&quot;:&quot;Master - 1&quot;}]' --auto-terminate --auto-scaling-role EMR_AutoScaling_DefaultRole --service-role EMR_DefaultRole --name 'kwurst-FlightsByCarrier' --scale-down-behavior TERMINATE_AT_TASK_COMPLETION --region us-east-1

Download Results (Web Interface)

 * 1) Log in AWS
 * 2) Go to S3
 * 3) Go to the folder flight-data
 * 4) Download each part-r-##### file individually

Download Results (CLI Interface)
Note: Adjust bucket names to correspond to your own buckets.

Fixing Connection Timeout Errors When Connecting to EMR Cluster with SSH

 * 1) Log in to AWS.
 * 2) Go to EC2.
 * 3) Choose Security Groups from the lefthand menu.
 * 4) Select the group with Group Name ElasticMapReduce-master.
 * 5) In the bottom portion of the screen, select the Inbound tab.
 * 6) Click Edit.
 * 7) Scroll down and click Add Rule.
 * 8) Set Type to SSH
 * 9) Enter 22 for Port Range.
 * 10) For Source, add the IP: 0.0.0.0/0
 * 11) SAVE