How to Configure AWS CLI to Use Boto3

In this AWS lesson we want to learn How to Configure AWS CLI to Use Boto3, in the previous lesson we have learned How to Install AWS CLI and Boto3, now in this lesson we want to talk about the configuration. we already have talked that when it comes to integrating AWS functionality into your Python projects, two essential tools come to mind: AWS Command Line Interface (CLI) and Boto3. AWS CLI allows you to manage AWS services from the command line, and Boto3 serves as the official SDK for Python.

 

 

Prerequisites

Before starting our configuration process, ensure that you have the following prerequisites:

  • Python installed on your system
  • AWS CLI installed and configured with your AWS credentials

If you haven’t installed AWS CLI you can check my previous lesson about AWS CLI Installation.

 

 

Configure AWS CLI for Boto3

I assume that you have already installed Boto3, if you don’t know how to install Boto3, you can use pip for the installation (pip install boto3).

 

So now we need to open our AWS console and create an IAM user. now let’s talk about IAM user.

 

 

What is IAM User?

IAM or Identity and Access Management is a service provided by Amazon Web Services (AWS) that enables you to manage users, groups, and permissions inside your AWS environment. An IAM user is an entity that represents a person or application interacting with AWS services. These users can have unique credentials (such as username and password) and access permissions.

 

 

How to Create IAM User with AWS Management Console?

We will learn about creating IAM user using Python and Boto3, but right now we need to create user with AdministratorAccess.

 

First go to AWS Management Console and search for IAM in the search bar, and then click on that.

How to Configure AWS CLI to Use Boto3
How to Configure AWS CLI to Use Boto3

 

 

 

After that click on Users, and then click on Create User and this page will be opened, give your username and then click on Next button, if you wan to give the user access to AWS Management Console, then you need to check this option (Provide user access to the AWS Management Console ). in our case we don’t need that, because we are not going to give console access to the user, we will give programmatic access for the user.

How to Configure AWS CLI to Use Boto3
How to Configure AWS CLI to Use Boto3

 

 

 

After clicking on Next, we need to attach a policy to the user, a policy is a document that defines permissions and access control rules. These policies are attached to IAM identities (such as users, groups, or roles) and determine what actions those identities are allowed or denied to perform on AWS resources. IAM policies are written in JSON (JavaScript Object Notation) format and consist of one or more statements, each describing a specific set of permissions.

 

For example in our case we want to give AdministratorAccess to our this user, so he will have full administrative access to all AWS services and resources within your AWS account. However, it’s important to use carefully when granting such broad permissions, as they can potentially allow unrestricted access to sensitive resources. Always follow the principle of least privilege and grant only the permissions necessary for users to perform their intended tasks.

 

Now from the page choose Attach policies directly, and then from the bottom choose AdministratorAccess.

AWS Administrator Access Policy
AWS Administrator Access Policy

 

 

 

Then click on next and create the user, after that we want to create access key and secret key for the user to give programmatic access for the user, click on the created user and then go to Security credentials, and at the bottom create access key, make sure to note that, because we will use that later.

 

 

After that open your terminal and write these commands.

AWS Configure
AWS Configure

 

And now you are done with the configuration.

 

 

 

FAQS

 

Q: What is the relationship between AWS CLI and Boto3?

A: AWS CLI (Command Line Interface) and Boto3 are both tools provided by AWS for interacting with AWS services. AWS CLI allows you to manage AWS resources from the command line, and Boto3 is the official AWS SDK for Python, and using Boto3 you can do programmatic access to AWS services within Python code.

 

 

Q: Do I need to configure AWS CLI to use Boto3?

A: No, configuring AWS CLI is not strictly necessary to use Boto3. However, configuring AWS CLI can simplify credential management and make it easier to work with Boto3, especially in environments where AWS CLI credentials are already set up.

 

 

Q: How does configuring AWS CLI affect Boto3?

A: Configuring AWS CLI sets up the necessary credentials and configurations required by Boto3 to interact with AWS services. When AWS CLI is configured, Boto3 can automatically use the same credentials and settings.

 

 

Learn More

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Codeloop
Share via
Copy link
Powered by Social Snap
×