code: def _map_regions(settings):
      """Reverse the mapping of accounts/orgs <> regions to make it nicer for terraform to use
  
      Args:
          settings (dict): Mapping or accounts/orgs to regions
              Example:
                  {
                      'accounts': {
                          '123456789012': ['us-east-1'],
                          '234567890123': ['us-east-1']
                      },
                      'organizations': {
                          'o-aabbccddee': ['us-west-1']
                      }
                  }
  
      Returns:
          dict: An inverse mapping of regions <> accounts/orgs
              Example:
                  {
                      'us-east-1': {
                          'accounts': ['123456789012', '234567890123'],
                      },
                      'us-west-1': {
                          'organizations': ['o-aabbccddee']
                      }
                  }
      """
      region_map = defaultdict(dict)
      for scope in ["accounts", "organizations"]:
          for aws_id, regions in settings.get(scope, {}).items():
              for region in regions:
                  region_map[region] = region_map.get(
                      region, defaultdict(list)
                  )
                  region_map[region][scope].append(aws_id)
  
      return region_map
  
imports: from collections import defaultdict
  import json
  from streamalert.shared.logger import get_logger
label_desc: Use image node_id 2 for calling a global function with example usage: _map_regions(settings) and returns: region_map