From f21ef8dbb2ef6526b8b47e18b9d8d91dd520c086 Mon Sep 17 00:00:00 2001
From: teramonagi <teramonagi@gmail.com>
Date: Thu, 29 Oct 2015 10:54:04 -0700
Subject: [PATCH] [SPARK-10532][EC2] Added --profile option to specify the name
 of profile

"profiles" give us the way that you can specify the set of credentials you want to use when you initialize a connection to AWS.

You can keep multiple sets of credentials in the same credentials files using different profile names.
For example, you can use --profile option to do that when you use "aws cli tool".

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

Author: teramonagi <teramonagi@gmail.com>

Closes #8696 from teramonagi/SPARK-10532.
---
 ec2/spark_ec2.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ec2/spark_ec2.py b/ec2/spark_ec2.py
index 3a2361c6d6..9327e21e43 100755
--- a/ec2/spark_ec2.py
+++ b/ec2/spark_ec2.py
@@ -181,6 +181,10 @@ def parse_args():
     parser.add_option(
         "-i", "--identity-file",
         help="SSH private key file to use for logging into instances")
+    parser.add_option(
+        "-p", "--profile", default=None,
+        help="If you have multiple profiles (AWS or boto config), you can configure " +
+             "additional, named profiles by using this option (default: %default)")
     parser.add_option(
         "-t", "--instance-type", default="m1.large",
         help="Type of instance to launch (default: %default). " +
@@ -1315,7 +1319,10 @@ def real_main():
         sys.exit(1)
 
     try:
-        conn = ec2.connect_to_region(opts.region)
+        if opts.profile is None:
+            conn = ec2.connect_to_region(opts.region)
+        else:
+            conn = ec2.connect_to_region(opts.region, profile_name=opts.profile)
     except Exception as e:
         print((e), file=stderr)
         sys.exit(1)
-- 
GitLab