| Did this page help you? Yes No Tell us about it... |
This section covers the basics of creating a job flow using Pig in Amazon Elastic MapReduce (Amazon EMR). You'll step through how to create a job flow using Pig with either the Amazon EMR console, the CLI, or the Query API. Before you create your job flow you'll need to create objects and permissions; for more information see Setting Up Your Environment to Run a Job Flow.
A job flow using Pig takes SQL-like commands written in Pig Latin, and converts those
commands into Hadoop MapReduce algorithms. The examples that follow are based on the
Amazon EMR sample: Apache Log
Analysis using Pig. The sample evaluates Apache log files and then generates
a report containing the total bytes transferred, a list of the top 50 IP addresses, a
list of the top 50 external referrers, and the top 50 search terms using Bing and
Google. The Pig script is located in the Amazon S3 bucket
s3n://elasticmapreduce/samples/pig-apache/do-reports2.pig. Input data is
located in the Amazon S3 bucket
s3n://elasticmapreduce/samples/pig-apache/input. The output is saved to an
Amazon S3 bucket you created as part of Setting Up Your Environment to Run a Job Flow.
This example describes how to use the Amazon EMR console to create a job flow using Pig.
To create a job flow using Pig
Sign in to the AWS Management Console and open the Amazon Elastic MapReduce console at https://console.aws.amazon.com/elasticmapreduce/.
Click Create New Job Flow.

In the DEFINE JOB FLOW page, enter the following:
Enter a name in the Job Flow Name field.
We recommended you use a descriptive name. It does not need to be unique.
Select Run your own application.
Select Pig Program in the drop-down list.
Click Continue.

In the SPECIFY PARAMETERS page, indicate whether you want to run Pig from a script, or interactively from the master node. If you are running it from a script, enter values in the boxes using the following table as a guide. Click Continue.
| Field | Action |
|---|---|
| Script Location* | Specify the URI where your script resides in Amazon S3. The
value must be in the form
BucketName/path/ScriptName.
|
| Input Location | Optionally, specify the URI where your input files reside in
Amazon S3. The value must be in the form
BucketName/path/.
|
| Output Location | Optionally, specify the URI where you want the output stored in
Amazon S3. The value must be in the form
s3://BucketName/path. |
| Extra Args | Optionally, enter a list of arguments (space-separated strings) to pass to Pig. |
* Required parameter

In the CONFIGURE EC2 INSTANCES page, select the type and number of instances, using the following table as a guide, and then click Continue.
![]() | Note |
|---|---|
Twenty is the default maximum number of nodes per AWS account. For example, if you have two job flows running, the total number of nodes running for both job flows must be 20 or less. If you need more than 20 nodes, you must submit a request to increase your Amazon EC2 instance limit. For more information, go to the Request to Increase Amazon EC2 Instance Limit Form. |
| Field | Action |
|---|---|
| Instance Count | Specify the number of nodes to use in the Hadoop cluster. There is always one master node in each job flow. You can specify the number of core and tasks nodes. |
| Instance Type | Specify the Amazon EC2 instance types to use as master, core, and task nodes. Valid types are m1.small (default), m1.large, m1.xlarge, c1.medium, c1.xlarge, m2.xlarge, m2.2xlarge, and m2.4xlarge, cc1.4xlarge, cg1.4xlarge. |
| Request Spot Instances | Click this checkbox to run master, core, or task nodes on Spot Instances. For more information, see Lowering Costs with Spot Instances |
* Required parameter

In the ADVANCED OPTIONS page, set additional configuration options, using the following table as a guide, and then click Continue.
| Field | Action | |||
|---|---|---|---|---|
| Amazon EC2 Key Pair | Optionally, specify a key pair that you created previously. For more information, see Create an Amazon EC2 Key Pair and PEM File. If you do not enter a value in this field, you cannot SSH into the master node. | |||
| Amazon VPC Subnet Id | Optionally, specify a VPC subnet identifier to launch the job flow in an Amazon VPC. For more information, see Running Job Flows on an Amazon VPC. | |||
| Amazon S3 Log Path | Optionally, specify a path in Amazon S3 to store the
Amazon EMR log files. The value must be in the form
BucketName/path.
If you do not supply a location, Amazon EMR does not log
any files. | |||
| Enable Debugging | Select Yes to store Amazon Elastic MapReduce-generated log
files. You must enable debugging at this level if you want
to store the log files generated by Amazon EMR. If you select Yes, you must supply an Amazon S3 bucket name where Amazon Elastic MapReduce can upload your log files. For more information, see Troubleshooting.
| |||
| Keep Alive | Select Yes to cause the job flow to continue running when all processing is completed. |

In the BOOTSTRAP ACTIONS page, select Proceed with no Bootstrap Actions, and then click Continue.
For more information about bootstrap actions, see Bootstrap Actions.

In the REVIEW page, review the information, edit as necessary to correct any of the values, and then click Create Job Flow when the information is correct.
After you click Create Job Flow your request is processed; when it succeeds, a message appears.

Click Close.
The Amazon EMR console shows the new job flow starting.

This example describes how to use the CLI to create a job flow using Pig.
To create a job flow using Pig
Use the information in the following table to create your job flow:
| If you are using... | Enter the following... |
|---|---|
| Linux or UNIX |
$ ./elastic-mapreduce --create --name " |
| Microsoft Windows |
c:\ruby elastic-mapreduce --create --name "
|
The output looks similar to the following.
Created job flow JobFlowIDBy default, this command launches a job flow to run on a single-node cluster using
an Amazon EC2 m1.small instance. Later, when your steps are running correctly on a
small set of sample data, you can launch job flows to run on multiple nodes. You can
specify the number of nodes and the type of instance to run with the
--num-instances and --instance-type
parameters, respectively.
This section describes the Amazon EMR API Query request parameters you
need to create a job flow using Pig. For an explanation of the parameters unique to
RunJobFlow, go to RunJobFlow in the Amazon Elastic MapReduce (Amazon EMR) API Reference.
The response includes a <JobFlowID>, which you use in other Amazon EMR
operations, such as when describing or terminating a job flow. For this reason, it is
important to store job flow IDs.
The Args argument contains location information for your
input data and output data, as shown in the following example.
"Name": "Pig job flow",
"HadoopJarStep":
{
"jar":"s3://us-west-1.elasticmapreduce/libs/script-runner/script-runner.jar",
"args":
[
"s3://us-west-1.elasticmapreduce/libs/pig/pig-script",
"--base-path",
"s3://us-west-1.elasticmapreduce/libs/pig/",
"--run-pig-script",
"--ami-version 2.0",
"--args",
"-f",
"s3n://elasticmapreduce/samples/pig-apache/do-reports2.pig",
"-p",
"INPUT=s3n://elasticmapreduce/samples/pig-apache/input",
"-p",
"OUTPUT=s3n://myawsbucket/pig-apache/output"
]
}![]() | Note |
|---|---|
All paths are prefixed with their location. The prefix “s3://” refers to the
s3n file system. If you use HDFS, prepend the path with
|