-
Notifications
You must be signed in to change notification settings - Fork 1.4k
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | 10000Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
from troposphere import Parameter, Ref, Template, Tags | ||
import troposphere.iam as iam | ||
import troposphere.emr as emr | ||
|
||
template = Template() | ||
template.add_description( | ||
"Sample CloudFormation template for creating an EMR cluster" | ||
) | ||
|
||
keyname = template.add_parameter(Parameter( | ||
"KeyName", | ||
Description="Name of an existing EC2 KeyPair to enable SSH " | ||
"to the instances", | ||
Type="AWS::EC2::KeyPair::KeyName" | ||
)) | ||
|
||
subnet = template.add_parameter(Parameter( | ||
"Subnet", | ||
Description="Subnet ID for creating the EMR cluster", | ||
Type="AWS::EC2::Subnet::Id" | ||
)) | ||
|
||
service_access_sg = template.add_parameter(Parameter( | ||
"ServiceAccessSecurityGroup", | ||
Description="Security Group providing service access to EMR", | ||
Type="AWS::EC2::SecurityGroup::Id" | ||
)) | ||
|
||
managed_master_sg = template.add_parameter(Parameter( | ||
"ManagedMasterSecurityGroup", | ||
Description="Security Group (managed by EMR) for master instances", | ||
Type="AWS::EC2::SecurityGroup::Id" | ||
)) | ||
|
||
managed_slave_sq = template.add_parameter(Parameter( | ||
"ManagedSlaveSecurityGroup", | ||
Description="Security Group (managed by EMR) for slave instances", | ||
Type="AWS::EC2::SecurityGroup::Id" | ||
)) | ||
|
||
# IAM roles required by EMR | ||
|
||
emr_service_role = template.add_resource(iam.Role( | ||
'EMRServiceRole', | ||
AssumeRolePolicyDocument={ | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"elasticmapreduce.amazonaws.com" | ||
] | ||
}, | ||
"Action": ["sts:AssumeRole"] | ||
}] | ||
}, | ||
ManagedPolicyArns=[ | ||
'arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole' | ||
] | ||
)) | ||
|
||
emr_job_flow_role = template.add_resource(iam.Role( | ||
"EMRJobFlowRole", | ||
AssumeRolePolicyDocument={ | ||
"Statement": [{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"ec2.amazonaws.com" | ||
] | ||
}, | ||
"Action": ["sts:AssumeRole"] | ||
}] | ||
}, | ||
ManagedPolicyArns=[ | ||
'arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforEC2Role' | ||
] | ||
)) | ||
|
||
emr_instance_profile = template.add_resource(iam.InstanceProfile( | ||
"EMRInstanceProfile", | ||
Roles=[Ref(emr_job_flow_role)] | ||
)) | ||
|
||
# EMR Cluster Resource | ||
|
||
cluster = template.add_resource(emr.Cluster( | ||
"EMRSampleCluster", | ||
Name="EMR Sample Cluster", | ||
ReleaseLabel='emr-4.3.0', | ||
BootstrapActions=[emr.BootstrapActionConfig( | ||
Name='Dummy bootstrap action', | ||
ScriptBootstrapAction=emr.ScriptBootstrapActionConfig( | ||
Path='/bin/sh', | ||
Args=['echo', 'Hello World'] | ||
) | ||
)], | ||
Configurations=[ | ||
emr.Configuration( | ||
Classification="core-site", | ||
ConfigurationProperties={ | ||
'hadoop.security.groups.cache.secs': '250' | ||
} | ||
), | ||
emr.Configuration( | ||
Classification="mapred-site", | ||
ConfigurationProperties={ | ||
'mapred.tasktracker.map.tasks.maximum': '2', | ||
'mapreduce.map.sort.spill.percent': '90', | ||
'mapreduce.tasktracker.reduce.tasks.maximum': '5' | ||
} | ||
), | ||
emr.Configuration( | ||
Classification="hadoop-env", | ||
Configurations=[ | ||
emr.Configuration( | ||
Classification="export", | ||
ConfigurationProperties={ | ||
"HADOOP_DATANODE_HEAPSIZE": "2048", | ||
"HADOOP_NAMENODE_OPTS": "-XX:GCTimeRatio=19" | ||
} | ||
) | ||
] | ||
) | ||
], | ||
JobFlowRole=Ref(emr_instance_profile), | ||
ServiceRole=Ref(emr_service_role), | ||
Instances=emr.JobFlowInstancesConfig( | ||
MasterInstanceGroup=emr.InstanceGroupConfigProperty( | ||
Name="Master Instance", | ||
InstanceCount="1", | ||
InstanceType="m3.xlarge", | ||
Market="ON_DEMAND" | ||
), | ||
CoreInstanceGroup=emr.InstanceGroupConfigProperty( | ||
Name="Core Instance", | ||
BidPrice="20", | ||
InstanceCount="1", | ||
InstanceType="m3.xlarge", | ||
Market="SPOT" | ||
) | ||
), | ||
Applications=[ | ||
emr.Application(Name="Hadoop"), | ||
emr.Application(Name="Hive"), | ||
emr.Application(Name="Mahout"), | ||
emr.Application(Name="Pig"), | ||
emr.Application(Name="Spark") | ||
], | ||
VisibleToAllUsers="true", | ||
Tags=Tags( | ||
Name="EMR Sample Cluster" | ||
) | ||
)) | ||
|
||
step = template.add_resource(emr.Step( | ||
'TestStep', | ||
Name="TestStep", | ||
ActionOnFailure='CONTINUE', | ||
HadoopJarStep=emr.HadoopJarStepConfig( | ||
Args=["5", "10"], | ||
Jar="s3://emr-cfn-test/hadoop-mapreduce-examples-2.6.0.jar", | ||
MainClass="pi", | ||
StepProperties=[ | ||
emr.KeyValue('my.custom.property', 'my.custom.value') | ||
] | ||
), | ||
JobFlowId=Ref(cluster) | ||
)) | ||
|
||
print(template.to_json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
{ | ||
"Description": "Sample CloudFormation template for creating an EMR cluster", | ||
"Parameters": { | ||
"KeyName": { | ||
"Description": "Name of an existing EC2 KeyPair to enable SSH to the instances", | ||
"Type": "AWS::EC2::KeyPair::KeyName" | ||
}, | ||
"ManagedMasterSecurityGroup": { | ||
"Description": "Security Group (managed by EMR) for master instances", | ||
"Type": "AWS::EC2::SecurityGroup::Id" | ||
}, | ||
"ManagedSlaveSecurityGroup": { | ||
"Description": "Security Group (managed by EMR) for slave instances", | ||
"Type": "AWS::EC2::SecurityGroup::Id" | ||
}, | ||
"ServiceAccessSecurityGroup": { | ||
"Description": "Security Group providing service access to EMR", | ||
"Type": "AWS::EC2::SecurityGroup::Id" | ||
}, | ||
"Subnet": { | ||
"Description": "Subnet ID for creating the EMR cluster", | ||
"Type": "AWS::EC2::Subnet::Id" | ||
} | ||
}, | ||
"Resources": { | ||
"EMRInstanceProfile": { | ||
"Properties": { | ||
"Roles": [ | ||
{ | ||
"Ref": "EMRJobFlowRole" | ||
} | ||
] | ||
}, | ||
"Type": "AWS::IAM::InstanceProfile" | ||
}, | ||
"EMRJobFlowRole": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"sts:AssumeRole" | ||
], | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"ec2.amazonaws.com" | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"ManagedPolicyArns": [ | ||
"arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceforEC2Role" | ||
] | ||
}, | ||
"Type": "AWS::IAM::Role" | ||
}, | ||
"EMRSampleCluster": { | ||
"Properties": { | ||
"Applications": [ | ||
{ | ||
"Name": "Hadoop" | ||
}, | ||
{ | ||
"Name": "Hive" | ||
}, | ||
{ | ||
"Name": "Mahout" | ||
}, | ||
{ | ||
"Name": "Pig" | ||
}, | ||
{ | ||
"Name": "Spark" | ||
} | ||
], | ||
"BootstrapActions": [ | ||
{ | ||
"Name": "Dummy bootstrap action", | ||
"ScriptBootstrapAction": { | ||
"Args": [ | ||
"echo", | ||
"Hello World" | ||
], | ||
"Path": "/bin/sh" | ||
} | ||
} | ||
], | ||
"Configurations": [ | ||
{ | ||
"Classification": "core-site", | ||
"ConfigurationProperties": { | ||
"hadoop.security.groups.cache.secs": "250" | ||
} | ||
}, | ||
{ | ||
"Classification": "mapred-site", | ||
"ConfigurationProperties": { | ||
"mapred.tasktracker.map.tasks.maximum": "2", | ||
"mapreduce.map.sort.spill.percent": "90", | ||
"mapreduce.tasktracker.reduce.tasks.maximum": "5" | ||
} | ||
}, | ||
{ | ||
"Classification": "hadoop-env", | ||
"Configurations": [ | ||
{ | ||
"Classification": "export", | ||
"ConfigurationProperties": { | ||
"HADOOP_DATANODE_HEAPSIZE": "2048", | ||
"HADOOP_NAMENODE_OPTS": "-XX:GCTimeRatio=19" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"Instances": { | ||
"CoreInstanceGroup": { | ||
"BidPrice": "20", | ||
"InstanceCount": "1", | ||
"InstanceType": "m3.xlarge", | ||
"Market": "SPOT", | ||
"Name": "Core Instance" | ||
}, | ||
"MasterInstanceGroup": { | ||
"InstanceCount": "1", | ||
"InstanceType": "m3.xlarge", | ||
"Market": "ON_DEMAND", | ||
"Name": "Master Instance" | ||
} | ||
}, | ||
"JobFlowRole": { | ||
"Ref": "EMRInstanceProfile" | ||
}, | ||
"Name": "EMR Sample Cluster", | ||
"ReleaseLabel": "emr-4.3.0", | ||
"ServiceRole": { | ||
"Ref": "EMRServiceRole" | ||
}, | ||
"Tags": [ | ||
{ | ||
"Key": "Name", | ||
"Value": "EMR Sample Cluster" | ||
} | ||
], | ||
"VisibleToAllUsers": "true" | ||
}, | ||
"Type": "AWS::EMR::Cluster" | ||
}, | ||
"EMRServiceRole": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"sts:AssumeRole" | ||
], | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"elasticmapreduce.amazonaws.com" | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"ManagedPolicyArns": [ | ||
"arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole" | ||
] | ||
}, | ||
"Type": "AWS::IAM::Role" | ||
}, | ||
"TestStep": { | ||
"Properties": { | ||
"ActionOnFailure": "CONTINUE", | ||
"HadoopJarStep": { | ||
"Args": [ | ||
"5", | ||
"10" | ||
], | ||
"Jar": "s3://emr-cfn-test/hadoop-mapreduce-examples-2.6.0.jar", | ||
"MainClass": "pi", | ||
"StepProperties": [ | ||
{ | ||
"Key": "my.custom.property", | ||
"Value": "my.custom.value" | ||
} | ||
] | ||
}, | ||
"JobFlowId": { | ||
"Ref": "EMRSampleCluster" | ||
}, | ||
"Name": "TestStep" | ||
}, | ||
"Type": "AWS::EMR::Step" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adding support for EMR resources #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Adding support for EMR resources #421
Changes from all commits
9cedf60
7bce048
0deac41
d7d2791
a6fe775
8af50f9
a6c8588
0c491a1
4ec95b5
06fccad
5a75661
dd92a66
e6f5013
d6ac3a3
288acc9
c34b755
a8a1fe1
9d1f7bd
b67cb0d
7570bef
f401cd5
44fcfb7
e271119
ab58880
a9af32a
d2486b7
3e8a15c
bddd616
1205091
c2bdd62
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.