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.

Similar Reads

Prerequisites

To try the stuff mentioned in this article, you should be ready with the following:...

Installations

If you haven’t set up your system for Boto3 yet, follow the below steps...

What is AWS Profile?

AWS profiles are just named configurations that you can use to organize your credentials across multiple AWS accounts, accounts can be from same account or from multiple accounts, each profile has it’s own Access Key, Secret key and other basic user preferences....

Why do we even need Multiple profiles?

When managing multiple projects, each with distinct AWS configurations or handling personal and work-related accounts, organizing and dynamically utilizing credentials becomes crucial. AWS offers a solution by allowing you to configure profiles for each user, ensuring seamless and organized access to different accounts based on specific project requirements. This approach streamlines the process of switching between user accounts, facilitating efficient and secure development across various scenarios....

AWS Profile Terms

ACCESS_KEY: The AWS Access Key is a unique identifier associated with an AWS account or IAM user.It serves as a credential to access AWS services programmatically through APIs or command-line tools.Access keys are used in conjunction with the AWS Access Key ID for authentication.You can think of it as an username for AWS cli....

Configure AWS Profile

To configure AWS profile, run the below command...

Accessing resources with specific profile

Note: We’re just using an sample IAM boto3 api call for demonstrating the scenario...

Set default profile in boto3

Unlike specifying the profile in the session, we can set default profile for the boto3 like below:...

Conclusion

In this article we leanrnt how to create multiple profiles in aws cli, and access resources using specific profile with differnt methods.Multiple profiles allow us to work on different projects, each with its unique AWS configuration, ensuring separation and security....

Manage Multiple AWS Profiles for Boto3 – FAQ’s

How many profiles can i configure?...