Saturday, March 25, 2023

Python Automations using Boto3 for AWS

The objective of this post is for experimenting with AWS Boto3 automations and AWS Lambda, most of the realtime usecase on AWS cloud controlled and acceleration with them. We should know as SRE or DevOps Engineer how to refer to the Boto3 documentation where AWS team provided lot of details and examples of each Boto3 method, I'm pretty sure you could make great automations with this Boto3 module explore ideas.

Python for AWS Using Boto3

Let's jump on it...

Prerequisites

You must have AWS account [this can be your company provided or free-tire account].

Getting Started Python Automations using Boto3 

Step 1: Add User in IAM 
Let's get into the IAM adding user you can provide username as devops-admin
Select AWS Access TYPE {tic} programmatic access this allows to access key ID and secret access key for the AWS API, CLI SDK (Boto3 uses this).

Set permissions for 'devopsuser' Select policy type as 'AdministrationAccess' to access AWS resources and services [For this testing purpose only]. When you proceed for 'Create' user you will get the 'Add user' page you can download .csv file that contains - Access key and Secret access key[show/hide] store them in a text file as well.

Step 2: Download and install aws cli
[optional for to run from Laptop] Download 'aws cli' AWS command line on your laptop.
aws-cli is a unified tool to manage your AWS services. This can be used for automate multiple AWS services. From Mac/Linux you can install using following command:
pip install awscli

Select the Options as per your Laptop - Windows 32bit or 64bit installer, And install awscli on your laptop.
Note that Amazon Linux will have awscli already installed.

Step 3: Configuring aws cli 

This will work only when you have awscli installed, Run the following command:

aws configure 

Setting up aws-cli environment using 'aws configure' command


use the step1 outcome here Acess Key, Secret access key and then choose region as per your location generally in Projects we have to use company provided region. Choice of Output always JSON format[default] leave it to none for this experiment. 

This above set aws configuration will be used in Boto3 Python programs automatically once it set otherwise we can provide as parameters in the program.

Step 4: Python 3 installation

To install on RedHat family Linux(Rocky, CentOS, Suse) you can use the following commands

Check for latest Python installed
python -V
yum info python

Python package manager Pip is required, Let's do Pip installation
wget https://bootstrap.pypa.io/get-pip.py
  python get-pip.py
Boto3 on Ubuntu :
apt-get install Python3-pip3
pip3 install boto3
Verify pip version details
pip show

Finally, all set to go!! Let's do Boto3 installation 

pip install boto3

You could see in the installion summary it installs botocore s3transfer and boto3
You can verify on the same with the following :
pip3 show boto3 

No comments:

Post a Comment

DevOps Foundation course

DevOps Foundation course
Join us to learn DevOps from the Beginning