in src/mount_efs/__init__.py [0:0]
def get_target_region(config, options):
def _fatal_error(message):
fatal_error(
'Error retrieving region. Please set the "region" parameter '
"in the efs-utils configuration file or specify it as a "
"mount option.",
message,
)
if "region" in options:
return options.get("region")
try:
return config.get(CONFIG_SECTION, "region")
except NoOptionError:
pass
try:
return get_region_from_instance_metadata(config)
except Exception as e:
metadata_exception = e
logging.warning(
"Region not found in config file and metadata service call failed, falling back "
'to legacy "dns_name_format" check'
)
try:
region = get_region_from_legacy_dns_format(config)
sys.stdout.write(
'Warning: region obtained from "dns_name_format" field. Please set the "region" '
"parameter in the efs-utils configuration file."
)
return region
except Exception:
logging.warning('Legacy check for region in "dns_name_format" failed')
_fatal_error(metadata_exception)