Skip to main content

Posts

Showing posts with the label Python

AWS Manage S3 Buckets using Python Boto3

 In this post, I will show you  how to create S3 bucket,  how to put objects into the bucket,  how to upload multiple objects in s3,  how to download multiple objects,  how to control access policy, and  how to host a static website in S3.  1. How to create S3 Bucket using Python3 Boto3? Object : resource method: create_bucket  important method  parameters:   ACL : private or public   Bucket - name of the bucket name this should be unique for each bucket   CreateBucketConfiguration - have the LocationConstrating that is region on which you want to host your s3 bucket. import boto3 s3_resource = boto3.resource('s3') bucket = s3_resource.create_bucket(ACL='private', Bucket='vybhava2023demo.com', CreateBucketConfiguration={ 'LocationConstrating': 'us-west-2' }) print("Successfully create bucket:", bucket) 2. How to put the objects into the S3 Bucket using Boto3 When you want to add fil...

Manage AWS EC2 Instances using Python Boto3 script

Hey Welcome! back to Automations with Python for AWS!!  Now IT market says AWS is the top number one Cloud Computing platform. That is why I've selected this AWS automations using Python Boto3. In this post we will be exploring the AWS EC2 Instance related operations, and manage them in a reusable form. Create EC2 instance using Python Boto3 Launch AWS EC2 instance using Python Boto3 script Stop AWS EC2 instance using Python Boto3 script Start AWS EC2 Instance using Python Boto3 script Terminate AWS EC2 instance using Python Boto3 script Fetching Public IP of given instance-id How do you Create EC2 instance using Python3 Boto3?   Creating EC2 instance using Boto3 Python code #============================================= # File : create_ec2.py # Description: Create EC2 instance by Boto3 import boto3 ec2 = boto3.resource('ec2') instances = ec2.create_instances( ImageId="ami-0dafa01c8100180f8", MinCount=1, MaxCount=1, Inst...

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 ...

Operators in Python

Hello Pythonist, here in this post I wiould like to share you about the all Python operators how they can coperates on the literals and variables at different sinarios. Unlike any other Programming languages,  Python supports wide variety of operators. Logical operators Comparison operators Bitwise operators Let's explore more ... Logical Operators The Python Logical operators are simple English words  and  or  not All these above operators returns boolean values based on the combination of operands. Comparison operators There are several comparison operators as >, <, >=, <=, ==, !=  Also in operators Bitwise Operators Binary number 0 and 1 will be used as operands bitwise operators & | ^ and ~ allow us to manipulate single bits of data and they returns 0 or 1 based on the data bit values passed. Python Bit-wise Operators Bit shift operators Left bit-shift operator << Right bit-shift operator >>

Installation of Python 3 in Linux

Beliefs As our belief, every Linux flavor has Python as one of the Shell. but that shell was created long back based on the OS release time repositories. In the most common situation where built-in Python might be at Python 2.7.x version but the latest version is on Python 3.7.x. The big challenge here is 'how do I upgrade or install Python3 on Linux?' So I've chased this challenge and completed the latest version installed on my Oracle Linux box. Python 3 installation on RHELflavors How do I install Python3 latest version on Linux? Python Programming is simple and kids can learn by doing! It's capabilities to interact with machine internals and the simple structure makes easy to write and understand it. The latest Python version for download you can find from the Python official site . Here I'm installing Python3 on the Oracle Linux same steps will be followed on any RHEL flavors as well. yum -y groupinstall development yum -y install zlib-devel Note: I...

Control your PC from Python Code

Hey guys, One of the easiest programming languages in the World is our Python. Here this post is intended for those who want to learn the hacking techniques! Here I would like to share simple 4lines of Python hack tricks that make shutdown or restart your PC. The logic here is that have the function contains the CMD Command line 'shutdown' with forceful(/s) timeout as 1 minute. Shutdown logic is here... import os def shutdown(): os.system("shutdown /s /t 1") shutdown() Restart logic is here import os def restart(): os.system("shutdown /r /t 1") restart() Jump to Linux VM and same thought to execute the same script then it failed! "Must be root." The solution there you need to be superuser to shutdown your Linux machine. To have better understand about the shutdown command in Linux operating system, used the --help option. [vagrant@mydev ~]$ sudo shutdown --help shutdown [OPTIONS...] [TIME] [WALL...] Shut down the system. ...