# Buggy code
def get_sts_client(session, region):
    """Get the AWS STS endpoint specific for the given region.

    Returns the global endpoint if region is not specified.

    For the list of regional endpoints, see https://amzn.to/2ohJgtR
    """
    if region and not USE_STS_GLOBAL:
        endpoint_url = "https://sts.{}.amazonaws.com".format(region)
        region_name = region
    else:
        endpoint_url = "https://sts.amazonaws.com"
        region_name = None
    return session.client("sts", endpoint_url=endpoint_url, region_name=region_name)


# Traceback (botocore.exceptions.NoRegionError)
2019-10-31 22:12:24,498: custodian.commands:DEBUG Loaded file policy.yml
Traceback (most recent call last):
File "/usr/local/bin/custodian", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/c7n/cli.py", line 374, in main
command(config)
File "/usr/local/lib/python3.7/site-packages/c7n/commands.py", line 141, in _load_policies
return f(options, list(policies))
File "/usr/local/lib/python3.7/site-packages/c7n/commands.py", line 275, in run
local_session(clouds['aws']().get_session_factory(options))
File "/usr/local/lib/python3.7/site-packages/c7n/utils.py", line 274, in local_session
s = factory()
File "/usr/local/lib/python3.7/site-packages/c7n/credentials.py", line 57, in __call__
region or self.region, self.external_id)
File "/usr/local/lib/python3.7/site-packages/c7n/credentials.py", line 115, in assumed_session
metadata=refresh(),
File "/usr/local/lib/python3.7/site-packages/c7n/credentials.py", line 106, in refresh
session, region).assume_role, **parameters)['Credentials']
File "/usr/local/lib/python3.7/site-packages/c7n/utils.py", line 390, in _retry
return func(*args, **kw)
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 648, in _make_api_call
operation_model, request_dict, request_context)
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/usr/local/lib/python3.7/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/usr/local/lib/python3.7/site-packages/botocore/endpoint.py", line 132, in _send_request
request = self.create_request(request_dict, operation_model)
File "/usr/local/lib/python3.7/site-packages/botocore/endpoint.py", line 116, in create_request
operation_name=operation_model.name)
File "/usr/local/lib/python3.7/site-packages/botocore/hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/hooks.py", line 211, in _emit
response = handler(**kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/signers.py", line 90, in handler
return self.sign(operation_name, request)
File "/usr/local/lib/python3.7/site-packages/botocore/signers.py", line 149, in sign
auth = self.get_auth_instance(**kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/signers.py", line 233, in get_auth_instance
raise botocore.exceptions.NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.
end of run

# Fixed code
def get_sts_client(session, region):
    """Get the AWS STS endpoint specific for the given region.

    Returns the global endpoint if region is not specified.

    For the list of regional endpoints, see https://amzn.to/2ohJgtR
    """
    if region and USE_STS_REGIONAL:
        endpoint_url = "https://sts.{}.amazonaws.com".format(region)
        region_name = region
    else:
        endpoint_url = "https://sts.amazonaws.com"
        region_name = None
    return session.client("sts", endpoint_url=endpoint_url, region_name=region_name)