Created
February 8, 2017 17:57
-
-
Save kheast/0c4f0041cc1152dd4694f908a1092a14 to your computer and use it in GitHub Desktop.
How to get boto3.resource to use a profile from credentials file
This file contains 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
# 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