boto3: A Python Library for Mocking AWS Services
Hello friends, We use the AWS SDK for Python (Boto3) to create, configure, and manage AWS services, such as Amazon Elastic Compute Cloud (Amazon EC2) and Amazon Simple Storage Service (Amazon S3). The SDK provides an object-oriented API as well as low-level access to AWS services.
Resource APIs
Boto3 has two distinct levels of APIs. Client (or "low-level") APIs provide one-to-one mappings to the underlying HTTP API operations. Resource APIs hide explicit network calls but instead provide resource objects and collections to access attributes and perform actions.
for i in ec2.instances.all():
if i.state['Name'] == 'stopped':
i.start()
Up-to-date and Consistent Interface
Boto3's 'client' and 'resource' interfaces have dynamically generated classes driven by JSON models that describe AWS APIs. This allows us to provide very fast updates with strong consistency across all supported services.
Waiters
Boto3 comes with 'waiters', which automatically poll for pre-defined status changes in AWS resources. For example, you can start an Amazon EC2 instance and use a waiter to wait until it reaches the 'running' state, or you can create a new Amazon DynamoDB table and wait until it is available to use. Boto3 has waiters for both client and resource APIs.
Service-specific High-level Features
Boto3 comes with many features that are service-specific, such as automatic multi-part transfers for Amazon S3 and simplified query conditions for Amazon DynamoDB.
Recommended by LinkedIn
Installation
To get started with Boto3, you can install it using pip. Assuming that you have a supported version of Python installed, you can first set up your environment with:
pip install boto3
After installing Boto3, you can set up credentials and a default region. Then, from a Python interpreter, you can import Boto3 and start using it.
Configuration
Before using Boto3, you need to set up authentication credentials for your AWS account using either the IAM Console or the AWS CLI. You can either choose an existing user or create a new one. If you have the AWS CLI installed, then you can use the aws configure command to configure your credentials file:
aws configure
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY
region=us-east-1
Using Boto3
To use Boto3, you must first import it and indicate which service or services you’re going to use:
import boto3
# Let's use Amazon S3
s3 = boto3.resource('s3')
Nice