(
    service: str,
    profile: str = None,
    region: str = None,
    secret_key: str = None,
    access_key: str = None,
    endpoint_url: str = None,
)
return client
Build connection to some AWS service.
Build connection to some AWS service.
Build connection to some AWS service .
def _get_aws_client(
    service: str,
    profile: str = None,
    region: str = None,
    secret_key: str = None,
    access_key: str = None,
    endpoint_url: str = None,
):
    """
    Build connection to some AWS service.
    """

    if region:
        aws_region = region
    else:
        aws_region = os.getenv("AWS_DEFAULT_REGION")

    # Fallback to querying metadata for region
    if not aws_region:
        try:
            azone = (
                urlopen(
                    METADATA_URL + "placement/availability-zone", data=None, timeout=5
                )
                .read()
                .decode()
            )
            aws_region = azone[:-1]
        except HTTPError as e:
            logging.exception(
                "Error determining region used for AWS client.  Typo in code?\n\n"
                + str(e)
            )
            sys.exit(1)
        except URLError:
            logging.exception("Timed out connecting to metadata service.\n\n")
            sys.exit(1)

    if profile:
        session = boto3.Session(
            profile_name=profile,
            aws_access_key_id=access_key,
            aws_secret_access_key=secret_key,
        )
        client = session.client(service, region_name=aws_region)
    else:
        client = boto3.client(
            service,
            region_name=aws_region,
            aws_access_key_id=access_key,
            aws_secret_access_key=secret_key,
            endpoint_url=endpoint_url,
        )
    return client
def _get_aws_client ( service : str , profile : str = None , region : str = None , secret_key : str = None , access_key : str = None , endpoint_url : str = None , ) : if region : aws_region = region else : aws_region = os . getenv ( "AWS_DEFAULT_REGION" ) # Fallback to querying metadata for region if not aws_region : try : azone = ( urlopen ( METADATA_URL + "placement/availability-zone" , data = None , timeout = 5 ) . read ( ) . decode ( ) ) aws_region = azone [ : - 1 ] except HTTPError as e : logging . exception ( "Error determining region used for AWS client.  Typo in code?\n\n" + str ( e ) ) sys . exit ( 1 ) except URLError : logging . exception ( "Timed out connecting to metadata service.\n\n" ) sys . exit ( 1 ) if profile : session = boto3 . Session ( profile_name = profile , aws_access_key_id = access_key , aws_secret_access_key = secret_key , ) client = session . client ( service , region_name = aws_region ) else : client = boto3 . client ( service , region_name = aws_region , aws_access_key_id = access_key , aws_secret_access_key = secret_key , endpoint_url = endpoint_url , ) return client