Accessing resources with specific profile
Note: We’re just using an sample IAM boto3 api call for demonstrating the scenario
We can access the aws resources without specifying the profile like below:
Accessing without profile (here aws sdk will look for default profile, if default profile doesn’t exist it will raise an error):
import boto3
client = boto3.client("iam")
response = client.get_user(
UserName='myname'
)
We can access aws resources by using specific profile like below:
import boto3
session = boto3.Session(profile_name='myprofile2')
client = session.client("iam")
response = client.get_user(
UserName='myname'
)
Here in the above case, we’re configuring the aws profile before initializing the client, so that every client initialized using the configured session will use your profile credentials (`myprofile2` in this case).
How To Manage Multiple AWS Profiles For Boto3
Amazon Web Services (AWS) is a leading cloud provider, it provides us with a variety of cloud services that are scalable globally, including compute, database, storage, analytics, developer tools, and enterprise applications. You can launch cloud resources, start building applications, and deploy them globally with ease. AWS will take care of most of the things. It works based on the pay-as-You-Go pricing model, which means you need not pay anything before utilizing the resources, you’ll pay on the go.