Configure AWS with Boto3 — Python

Tolga Koca
2 min readJan 28, 2024

--

When you’re working with AWS (Amazon Web Services), you might want to automate tasks like launching services like EC2, S3, VPC, and more.

There are several ways to do these tasks. You can use AWS console (AWS GUI), AWS CLI, Terraform as an IaC tool, or even Boto3 as a Python library.

Photo by Alex Kulikov on Unsplash

In this article, we setup our PC to run Python scripts to configure AWS services. We use Boto3 which is the AWS SDK (Software Development Kit) for Python.

Before our script can communicate with AWS, we need the right credentials. This is like giving our computer the keys to access your AWS account.

1- Install AWS CLI

First, we need to have the AWS Command Line Interface (CLI) installed on our computer. This is a tool that lets us interact with AWS services using commands in our command prompt or terminal. You can download and install it here. You can install it on Windows, Mac, or Linux systems.

2- Configure AWS CLI

Once installed, we open terminal/cmd and run the following command:

aws configure

This command starts a setup process where you’ll enter:

Your AWS Access Key ID

Your AWS Secret Access Key

Your preferred AWS region (like us-west-1)

Your preferred output format (like json)

You can find your Access Key ID and Secret Access Key in your AWS account’s security credentials section. The region is where you want your AWS resources to be located, and the output format is how you want AWS to display responses.

3- Install Python and Pycharm (if needed)

You must already have Python installed on your PC. You can download it here.

You can use Pycharm IDE for Python projects. You can download it here as a free PyCharm Community Edition version.

4- Install Boto3

Open the terminal in your Python projects folder and install boto3 with the pip package download manager.

pip install boto3

5- Import Boto3 in Python Code

After successful installation, you can open a Python file and import the boto3 library.

import boto3

This line adds the Boto3 library to your script, giving you access to AWS services within your Python code.

Now we are ready to deploy any configuration in AWS with Python scripts.

Interested in diving deeper? I run a comprehensive DevOps Bootcamp with over 30 hours of content and 60+ real-life projects on my website, DevOpsNuts.com. It’s designed to give you a solid foundation in all these areas.

Like this article? Follow me for more insights. And hey, if you’re a student, drop me a message for a special discount!

Let’s make your DevOps journey exciting and achievable by 2024! 🚀👩‍💻👨‍💻

--

--