Skip to content

Commit 486d455

Browse files
committed
Updated launch_instance command line tool and image.run() method to include IAM role functionality.
1 parent 1b615fe commit 486d455

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

bin/launch_instance

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ if __name__ == "__main__":
133133
parser.add_option("-d", "--dns", help="Returns public and private DNS (implicates --wait)", default=False, action="store_true", dest="dns")
134134
parser.add_option("-T", "--tag", help="Set tag", default=None, action="append", dest="tags", metavar="key:value")
135135
parser.add_option("-s", "--scripts", help="Pass in a script or a folder containing scripts to be run when the instance starts up, assumes cloud-init. Specify scripts in a list specified by commas. If multiple scripts are specified, they are run lexically (A good way to ensure they run in the order is to prefix filenames with numbers)", type='string', action="callback", callback=scripts_callback)
136+
parser.add_option("--role", help="IAM Role to use, this implies --no-add-cred", dest="role")
136137

137138
(options, args) = parser.parse_args()
138139

@@ -152,7 +153,7 @@ if __name__ == "__main__":
152153
print "Region %s not found." % options.region
153154
sys.exit(1)
154155
ec2 = boto.connect_ec2(region=region)
155-
if not options.nocred:
156+
if not options.nocred and not options.role:
156157
cfg.add_creds(ec2)
157158

158159
iobj = IObject()
@@ -214,10 +215,15 @@ if __name__ == "__main__":
214215
if options.save_ebs:
215216
shutdown_proc = "save"
216217

218+
instance_profile_name = None
219+
if options.role:
220+
instance_profile_name = options.role
221+
217222
r = ami.run(min_count=int(options.min_count), max_count=int(options.max_count),
218223
key_name=key_name, user_data=user_data,
219224
security_groups=groups, instance_type=options.type,
220-
placement=options.zone, instance_initiated_shutdown_behavior=shutdown_proc)
225+
placement=options.zone, instance_initiated_shutdown_behavior=shutdown_proc,
226+
instance_profile_name=instance_profile_name)
221227

222228
instance = r.instances[0]
223229

boto/ec2/image.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ def run(self, min_count=1, max_count=1, key_name=None,
161161
instance_initiated_shutdown_behavior=None,
162162
private_ip_address=None,
163163
placement_group=None, security_group_ids=None,
164-
additional_info=None):
164+
additional_info=None, instance_profile_name=None,
165+
instance_profile_arn=None, tenancy=None):
166+
165167
"""
166168
Runs this instance.
167169
@@ -236,7 +238,21 @@ def run(self, min_count=1, max_count=1, key_name=None,
236238
237239
:type security_group_ids:
238240
:param security_group_ids:
241+
242+
:type instance_profile_name: string
243+
:param instance_profile_name: The name of an IAM instance profile to use.
244+
245+
:type instance_profile_arn: string
246+
:param instance_profile_arn: The ARN of an IAM instance profile to use.
239247
248+
:type tenancy: string
249+
:param tenancy: The tenancy of the instance you want to launch. An
250+
instance with a tenancy of 'dedicated' runs on
251+
single-tenant hardware and can only be launched into a
252+
VPC. Valid values are: "default" or "dedicated".
253+
NOTE: To use dedicated tenancy you MUST specify a VPC
254+
subnet-ID as well.
255+
240256
:rtype: Reservation
241257
:return: The :class:`boto.ec2.instance.Reservation` associated with the request for machines
242258
@@ -252,7 +268,10 @@ def run(self, min_count=1, max_count=1, key_name=None,
252268
instance_initiated_shutdown_behavior,
253269
private_ip_address, placement_group,
254270
security_group_ids=security_group_ids,
255-
additional_info=additional_info)
271+
additional_info=additional_info,
272+
instance_profile_name=instance_profile_name,
273+
instance_profile_arn=instance_profile_arn,
274+
tenancy=tenancy)
256275

257276
def deregister(self, delete_snapshot=False):
258277
return self.connection.deregister_image(self.id, delete_snapshot)

0 commit comments

Comments
 (0)