Boto3 python


BOTO3
·         Amazon Web Services (AWS) has become a leader in Cloud computing.
·         We have different ways to automate ant task or to automate AWS Infrastructure provisioning.
è Shell Scripting.
è Python Scripting.
è Python Scripting with Boto3.
·         Boto3 is the name of the python open source SDK for AWS.
·         Boto3 is a python module which is used to AWS services.
·         Boto3 is an open source.
·        It allows you to create, update and delete AWS resources from your python script.
·         It’s complicated in many ways but it is rich SDK for AWS.
·         Boto3 is written on top of botocore (It is also implemented in Python) which is a low-level interface to the AWS API.
·         Botocore is the basic for the AWS-CLI which is also written in python.
·         Compare to botocore, boto3 contains a lot of great objects and methods to easily work with any of AWS services.
·         To use python in boto3 install awscli using (pip install awscli).
·         Next Check the service is installed or not using the command aws
·         To use boto3 we need to install boto3 services (pip install boto3).
·         To use AWS services install awsCLI in your desktop and install it.
·         The given the user permission on AWS website.
·         For that open AWS website and search for Identify and Access Management (IAM).
·         In that create a user and give the permission which you want to give.
·         Create a secret key for the user.
·         After creation of user that will create access id for the user when user want to use the services then the user want to enter the access id.
·         Then check for aws service is available in your desktop or not using aws command.
·         Then it will ask for access id then give the access id and hit enter and it will ask for secret key then give the secret key.
·         It will ask for region then give your region.
·         The default file format id .json
·         Now you can access the AWS CLI terminal.
How to upload data to dynamodb using boto3:
·         We need to create a table in dynamodb
·         Example is emp and we have to give primanry key in creating table as (emd_id_.
·         And click on create.
·         And go to Items tab and insert data into table.
·         If we want to update any rows then we can append.
·         To user that table in python script.

import boto3
db= boto3.resource(‘dynamodb’)
tale=db.Table(‘emp’)
table.put_item(
            items={‘emp_id’;”2”,
            ‘name’;”Jhon”,
            ‘Age’;”24”
            }
)
·         By running is code then it will upload a row into dynamodb.
·         If we want to check it then we have to go to aws website and go to dynamodb and refresh it then it will display the row which we have inserted using python code.
How to get data from using boto3:
import boto3
            db=boto3.resource(“dynamodb”)
            table=db.Table(“emd”)
            data=table.get_item(
                        key={
                                    “emp_id”;”1”
                        }
)
Print(data[“item”])

·         Then run the code then we will get the output.


Comments