AWS SDKs
The AWS SDKs behave identically to the AWS CLI. For example you can use Environment Variables or a Named Profile before the application is launced with the AWS SDK.
Environment Variables
myscript.py
import boto3
ec2 = boto3.client('ec2')
for i in ec2.instances.all():
if i.state['Name'] == 'stopped':
i.start()
Then, to invoke myscript.py
with temporary credentials from SAML.to, in a Subshell ($(...)
)
$(saml-to assume the-role-name --headless)
python myscript.py
Named Profiles
myscript.py
import boto3
ec2 = boto3.client('ec2', profile_name='the-profile-name')
for i in ec2.instances.all():
if i.state['Name'] == 'stopped':
i.start()
Then, to invoke myscript.py
with temporary credentials from SAML.to:
saml-to assume the-role-name --save the-profile-name
python myscript.py
Last updated