Skip to content

Commit 31f48e5

Browse files
nchammasshivaram
authored andcommitted
[SPARK-8576] Add spark-ec2 options to set IAM roles and instance-initiated shutdown behavior
Both of these options are useful when spark-ec2 is being used as part of an automated pipeline and the engineers want to minimize the need to pass around AWS keys for access to things like S3 (keys are replaced by the IAM role) and to be able to launch a cluster that can terminate itself cleanly. Author: Nicholas Chammas <[email protected]> Closes apache#6962 from nchammas/additional-ec2-options and squashes the following commits: fcf252e [Nicholas Chammas] PEP8 fixes efba9ee [Nicholas Chammas] add help for --instance-initiated-shutdown-behavior 598aecf [Nicholas Chammas] option to launch instances into IAM role 2743632 [Nicholas Chammas] add option for instance initiated shutdown
1 parent bba6699 commit 31f48e5

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

ec2/spark_ec2.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ def parse_args():
306306
"--private-ips", action="store_true", default=False,
307307
help="Use private IPs for instances rather than public if VPC/subnet " +
308308
"requires that.")
309+
parser.add_option(
310+
"--instance-initiated-shutdown-behavior", default="stop",
311+
choices=["stop", "terminate"],
312+
help="Whether instances should terminate when shut down or just stop")
313+
parser.add_option(
314+
"--instance-profile-name", default=None,
315+
help="IAM profile name to launch instances under")
309316

310317
(opts, args) = parser.parse_args()
311318
if len(args) != 2:
@@ -602,7 +609,8 @@ def launch_cluster(conn, opts, cluster_name):
602609
block_device_map=block_map,
603610
subnet_id=opts.subnet_id,
604611
placement_group=opts.placement_group,
605-
user_data=user_data_content)
612+
user_data=user_data_content,
613+
instance_profile_name=opts.instance_profile_name)
606614
my_req_ids += [req.id for req in slave_reqs]
607615
i += 1
608616

@@ -647,16 +655,19 @@ def launch_cluster(conn, opts, cluster_name):
647655
for zone in zones:
648656
num_slaves_this_zone = get_partition(opts.slaves, num_zones, i)
649657
if num_slaves_this_zone > 0:
650-
slave_res = image.run(key_name=opts.key_pair,
651-
security_group_ids=[slave_group.id] + additional_group_ids,
652-
instance_type=opts.instance_type,
653-
placement=zone,
654-
min_count=num_slaves_this_zone,
655-
max_count=num_slaves_this_zone,
656-
block_device_map=block_map,
657-
subnet_id=opts.subnet_id,
658-
placement_group=opts.placement_group,
659-
user_data=user_data_content)
658+
slave_res = image.run(
659+
key_name=opts.key_pair,
660+
security_group_ids=[slave_group.id] + additional_group_ids,
661+
instance_type=opts.instance_type,
662+
placement=zone,
663+
min_count=num_slaves_this_zone,
664+
max_count=num_slaves_this_zone,
665+
block_device_map=block_map,
666+
subnet_id=opts.subnet_id,
667+
placement_group=opts.placement_group,
668+
user_data=user_data_content,
669+
instance_initiated_shutdown_behavior=opts.instance_initiated_shutdown_behavior,
670+
instance_profile_name=opts.instance_profile_name)
660671
slave_nodes += slave_res.instances
661672
print("Launched {s} slave{plural_s} in {z}, regid = {r}".format(
662673
s=num_slaves_this_zone,
@@ -678,16 +689,19 @@ def launch_cluster(conn, opts, cluster_name):
678689
master_type = opts.instance_type
679690
if opts.zone == 'all':
680691
opts.zone = random.choice(conn.get_all_zones()).name
681-
master_res = image.run(key_name=opts.key_pair,
682-
security_group_ids=[master_group.id] + additional_group_ids,
683-
instance_type=master_type,
684-
placement=opts.zone,
685-
min_count=1,
686-
max_count=1,
687-
block_device_map=block_map,
688-
subnet_id=opts.subnet_id,
689-
placement_group=opts.placement_group,
690-
user_data=user_data_content)
692+
master_res = image.run(
693+
key_name=opts.key_pair,
694+
security_group_ids=[master_group.id] + additional_group_ids,
695+
instance_type=master_type,
696+
placement=opts.zone,
697+
min_count=1,
698+
max_count=1,
699+
block_device_map=block_map,
700+
subnet_id=opts.subnet_id,
701+
placement_group=opts.placement_group,
702+
user_data=user_data_content,
703+
instance_initiated_shutdown_behavior=opts.instance_initiated_shutdown_behavior,
704+
instance_profile_name=opts.instance_profile_name)
691705

692706
master_nodes = master_res.instances
693707
print("Launched master in %s, regid = %s" % (zone, master_res.id))

0 commit comments

Comments
 (0)