Aws notes

From raju

boto3 related

specify a fallback region

The idea here is to specify a fallback region if the user has not already configured a default region.

    def get_region():
        session = boto3.session.Session()
        region_name = session.region_name
        if region_name is None:
            # User has not configured the region. Set it to a fallback value.
            fallback_region = 'us-east-1'
            region_name = fallback_region
        return region_name
    
    
    ec2 = boto3.client('ec2', region_name=get_region())
    

google searches | specify region if not defined in ~/.aws/config, set region if it is not already set, programmatically get aws region python

Ref:-

default region

A default region can be specified in multiple ways. One way is to set it in ~/.aws/config by adding lines such as

    [default]
    region = us-east-1
    

replace us-east-1 with your region code.

dummy

useful links

    • What is the difference between a region and an availability zone?
    • Is the tag "us-east-1a" a region or an availability zone?