Skip to main content

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 

Comments

Popular posts from this blog

Python Interview Questions -Coding Snipets

 This post is dedicated for all DevOps Engineer, Software Engineers who are preparing for Coding Interviews,  Overview of Coding Interviews Most Companies looking for People with minimum Coding knowledge. In a coding interview, you will be given a small problem to solve within 10 - 20 minutes online screen or in-person on their system. In the question, you might be having some part of the code framed and you might be asked to write a snippet of code in between. You need to understand the code comments and proceed to build the expected snippet of code. Bigger companies look for the General purpose questions, where small companies look for specific questions. The General questions would be like this: Determine if the given word is a palindrome or not. (Example madam) Determine given number is prime or not. How to prepare for a coding interview? Now we have the flexibility to choose the programming language on which you are comfortable.  In general DevOps Infra guys will be ...

Python Sets and Dictionaries

Python Sets Python Maps examples A mapping object maps hashable values to arbitrary objects. Mappings are mutable objects. There is currently only one standard mapping type, the dictionary. Dictionaries consist of pairs (called items) of keys and their corresponding values. Dictionaries can be created by placing a comma-separated list of key: value pairs within curly braces Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples. Python Set Operations and methods Python Set methods continueed >>> SET={'new','old','list','new'} >>> SET set(['new', 'old', 'list']) Lets play with set operations, it is more like school math here... >>> s={1,2,3,4} >>> k={3,4,5,6} >>> len(s) 4 >>> len(k) 4 >>> 1 in s True >>...

Program Controls and loops in Python

Python Programming controls The flow of program will be controlled with conditional statements where this flow  if condition if-else condition if-elif condition while loop while - else loop for loop for with if- else loop if condition Here I would like to work on program control statements, wherein relate some operating system functionalities so that, this would give some basic prototype for the sys admin scripts. #!/usr/bin/python # This illustrate if condition # Filename : ifex.py import os d=os.listdir('/home/pavanbsd/pybin') print d f='ifex.py' if f in d: print "File exists" else: print "Not found..." if-elif-else ladder No worries, coming soon... When you need the task that need to be done repeatedly then your choice is using loops. Python provides two simple loop constructs easy to use! More powerful then other scripting compare to, it has 'else' block. while loop Understand the power of while loop,...