Provides infrastructure layer compute capabilities, including both bare metal and virtual servers with various optimizations includins compute, memory, IO, and disk. Also supports accelerations options such as GPUs, FPGAs, Inferentia and Trainium.
Provides image recognition capability for images (in batch or real-time) and video that provides a analysis of the content such as real-world objects, faces, celebrities, and path mapping.
Provides a publish/subscribe notification service with multiple subscription types including Amazon Simple Queue Service (SQS), Amazon Kinesis Data Firehose, AWS Lambda, generic HTTPS endpoints, SMS and email.
A serverless, fully-managed, message queue service that supports producing, store, and consuming messages and enables loose coupling between applications.
Provides private networking capability spanning multiple availability zones and supporting subnets, routing, network access control groups, security groups and gateways.
Provides tracing of service invocations in distributed applications for observability, allowing users to diagnose issues or optimize their service interactions.
All about Cloud, mostly about Amazon Web Services (AWS)
More Python and Boto3 - Arguments and Sessions
2017-05-03 / 723 words / 4 minutes
In “Automating with Python and Boto3” the Python script had no special code for authentication or region selection. It simply uses defaults like those setup with the aws configure CLI command, or environment variables. Sooner of later though, there is a need to work in a different region, or handle multiple accounts, so the defaults aren’t enough. Fortunately, Boto3 supports alternatives for region selection and credentials.
Command Line Arguments with Python and Boto3
Python has a great library for managing command line parameters. You simply define the arguments that you want to parse, and then call the parser. The values associated with the arguments are stored in a map.
A couple of critical points to remember. First, arguments which contain a dash (“-“) are changed in the map to an underscore (“_”). Second, you don’t need to declare “-h” or “—help” arguments for displaying help. In fact, if you do you’ll get a conflict error. For example, the following program:
1
2
3
4
5
6
7
import argparse
parser = argparse.ArgumentParser( description=‘Test Command Line Parser’ )
parser.add_argument( ‘–help’, help=‘Provides command line help’ )
args = parser.parse_args()
print( args )
will cause the error:
There are lots of ways to determine the credentials to use. I prefer to use profiles to select between the different accounts. Although profiles can be configured with a default region, I like to allow a region to be specified on the command line. I typically like to support arguments like:
optional arguments:
-h, –help show this help message and exit
–profile PROFILE The AWS Profile to use
–region REGION The AWS Region
1
2
3
4
5
6
7
8
9
$ python args.py –help
usage: args.py [-h] [–profile PROFILE] [–region REGION]
AWS Utility
optional arguments:
-h, –help show this help message and exit
–profile PROFILE The AWS Profile to use
–region REGION The AWS Region
The code to generate this help text is:
args = parser.parse_args()
print( ‘Profile: %s’ % args.profile )
print( ‘Region: %s’ % args.region )
Sessions and Clients with Python and Boto3
Once we know the profile and region to use we need to tell Boto3 to use them. This is done using Boto3 Sessions. Boto3 Sessions define a connection to AWS. A single Python program can have multiple sessions open concurrently.
Sessions don’t provide a way to access AWS Services. Clients provide an interface to one AWS Service by supporting methods which call AWS. Boto3 Clients are created from the session.
The following is an example program with support profile and region selection. It provides the same functionality as the example program from “Automating with Python and Boto3“. Lines 13 and 14 create the Boto3 Session which supports multiple profiles and multiple regions:
import argparse
import boto3
from botocore.exceptions import ClientError
All data and information provided on this site is for informational
purposes only. cloudninja.cloud makes no representations as to accuracy,
completeness, currentness, suitability, or validity of any information
on this site and will not be liable for any errors, omissions, or
delays in this information or any losses, injuries, or damages
arising from its display or use. All information is provided on an
as-is basis.
This is a personal weblog. The opinions expressed here represent my
own and not those of my employer. My opinions may change over time.