Skip to content

Instantly share code, notes, and snippets.

@kheast
Created February 8, 2017 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kheast/0c4f0041cc1152dd4694f908a1092a14 to your computer and use it in GitHub Desktop.
Save kheast/0c4f0041cc1152dd4694f908a1092a14 to your computer and use it in GitHub Desktop.
How to get boto3.resource to use a profile from credentials file
# To get boto3.resource to use a profile name, one must first
# setup a default session. The credentials provided during the
# session setup will be subsequently used by resource().
#
# See: https://github.com/boto/boto3/issues/21
# https://github.com/boto/boto3/pull/69
boto3.setup_default_session(profile_name=self.dpkg.profile_name)
self.ec2 = boto3.resource('ec2', region_name=self.dpkg.region_name)
filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
for inst in self.ec2.instances.filter(Filters=filters):
if inst.public_ip_address == fapi.env.hosts[0]:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment