#NEWLINE# def get_session( boto3_profile = None , region_name = None , access_key_id = None , secret_access_key = None ) : #NEWLINE# #INDENT# if boto3_profile : #NEWLINE# #INDENT# if ( access_key_id or secret_access_key or region_name ) : #NEWLINE# #INDENT# raise ValueError ( 'access_key_id, secret_access_key, and region_name cannot be used with boto3_profile' ) #NEWLINE# #UNINDENT# return boto3 . session . Session ( profile_name = boto3_profile ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( access_key_id or secret_access_key or region_name ) : #NEWLINE# #INDENT# if ( ( not access_key_id ) or ( not secret_access_key ) or ( not region_name ) ) : #NEWLINE# #INDENT# raise ValueError ( 'access_key_id, secret_access_key, and region_name must all be set' ) #NEWLINE# #UNINDENT# return boto3 . session . Session ( aws_access_key_id = access_key_id , aws_secret_access_key = secret_access_key , region_name = region_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'boto_profile or explicit AWS credentials (access_key_id, secret_access_key, region_name) must be provided' )