Python botocore.exceptions.NoRegionError() Examples
The following are 17
code examples of botocore.exceptions.NoRegionError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
botocore.exceptions
, or try the search function
.
Example #1
Source File: flowlogs_reader.py From flowlogs-reader with Apache License 2.0 | 7 votes |
def _get_client( self, client_type, region_name, profile_name, boto_client_kwargs ): session_kwargs = {} if region_name is not None: session_kwargs['region_name'] = region_name if profile_name is not None: session_kwargs['profile_name'] = profile_name client_kwargs = boto_client_kwargs or {} session = boto3.session.Session(**session_kwargs) try: boto_client = session.client(client_type, **client_kwargs) except NoRegionError: boto_client = session.client( client_type, region_name=DEFAULT_REGION_NAME, **client_kwargs ) return boto_client
Example #2
Source File: test_aws_secretsmanager_caching.py From aws-secretsmanager-caching-python with Apache License 2.0 | 5 votes |
def test_default_session(self): try: SecretCache() except NoRegionError: pass
Example #3
Source File: __init__.py From aegea with Apache License 2.0 | 5 votes |
def main(args=None): parsed_args = parser.parse_args(args=args) logger.setLevel(parsed_args.log_level) has_attrs = (getattr(parsed_args, "sort_by", None) and getattr(parsed_args, "columns", None)) if has_attrs and parsed_args.sort_by not in parsed_args.columns: parsed_args.columns.append(parsed_args.sort_by) try: result = parsed_args.entry_point(parsed_args) except Exception as e: if isinstance(e, NoRegionError): msg = "The AWS CLI is not configured." msg += " Please configure it using instructions at" msg += " http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html" exit(msg) elif logger.level < logging.ERROR: raise else: err_msg = traceback.format_exc() try: err_log_filename = os.path.join(config.user_config_dir, "error.log") with open(err_log_filename, "ab") as fh: print(datetime.datetime.now().isoformat(), file=fh) print(err_msg, file=fh) exit("{}: {}. See {} for error details.".format(e.__class__.__name__, e, err_log_filename)) except Exception: print(err_msg, file=sys.stderr) exit(os.EX_SOFTWARE) if isinstance(result, SystemExit): raise result elif result is not None: if isinstance(result, dict) and "ResponseMetadata" in result: del result["ResponseMetadata"] print(json.dumps(result, indent=2, default=str))
Example #4
Source File: regions.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #5
Source File: test_resources.py From aws-shell with Apache License 2.0 | 5 votes |
def test_no_completions_when_cant_create_client(describer_creator): client_creator = mock.Mock(spec=index.CachedClientCreator) # This is raised when you don't have a region configured via config file # env var or manually via a session. client_creator.create_client.side_effect = NoRegionError() completer = index.ServerSideCompleter( client_creator=client_creator, describer_creator=describer_creator) assert completer.retrieve_candidate_values( 'ec2', 'foo', 'Bar') == []
Example #6
Source File: aws.py From cli with MIT License | 5 votes |
def client_with_default_region(service, default_region = DEFAULT_REGION): """ Return a boto3 client for the named *service* in the *default_region* if no region is specified in the default session (via the environment, AWS config, or ``boto3.setup_default_session``). """ try: return boto3.client(service) except NoRegionError: return boto3.client(service, region_name = default_region)
Example #7
Source File: test_boto_engine.py From aq with MIT License | 5 votes |
def test_get_resource_model_attributes(self): try: resource = boto3.resource('ec2') except NoRegionError: # skip for environment that doesn't have boto config like CI pass else: collection = resource.instances.all() attributes = get_resource_model_attributes(resource, collection) assert attributes assert 'instance_id' in attributes assert 'image_id' in attributes
Example #8
Source File: sqs_sensor.py From stackstorm-aws with Apache License 2.0 | 5 votes |
def _setup_sqs(self, session, account_id, region): ''' Setup SQS resources''' if region in self.sqs_res[account_id]: return self.sqs_res[account_id][region] try: self.sqs_res[account_id][region] = session.resource('sqs', region_name=region) return self.sqs_res[account_id][region] except NoRegionError: self._logger.error("The specified region '%s' for account %s is invalid.", region, account_id)
Example #9
Source File: regions.py From aws-extender with MIT License | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #10
Source File: regions.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #11
Source File: regions.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #12
Source File: regions.py From bash-lambda-layer with MIT License | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #13
Source File: regions.py From deepWordBug with Apache License 2.0 | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #14
Source File: regions.py From faces with GNU General Public License v2.0 | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #15
Source File: regions.py From faces with GNU General Public License v2.0 | 5 votes |
def _endpoint_for_partition(self, partition, service_name, region_name): # Get the service from the partition, or an empty template. service_data = partition['services'].get( service_name, DEFAULT_SERVICE_DATA) # Use the partition endpoint if no region is supplied. if region_name is None: if 'partitionEndpoint' in service_data: region_name = service_data['partitionEndpoint'] else: raise NoRegionError() # Attempt to resolve the exact region for this partition. if region_name in service_data['endpoints']: return self._resolve( partition, service_name, service_data, region_name) # Check to see if the endpoint provided is valid for the partition. if self._region_match(partition, region_name): # Use the partition endpoint if set and not regionalized. partition_endpoint = service_data.get('partitionEndpoint') is_regionalized = service_data.get('isRegionalized', True) if partition_endpoint and not is_regionalized: LOG.debug('Using partition endpoint for %s, %s: %s', service_name, region_name, partition_endpoint) return self._resolve( partition, service_name, service_data, partition_endpoint) LOG.debug('Creating a regex based endpoint for %s, %s', service_name, region_name) return self._resolve( partition, service_name, service_data, region_name)
Example #16
Source File: functional_test_utils.py From aws-dynamodb-encryption-python with Apache License 2.0 | 4 votes |
def check_metastore_cache_use_encrypt(metastore, table_name, log_capture): try: table = boto3.resource("dynamodb").Table(table_name) except NoRegionError: table = boto3.resource("dynamodb", region_name=TEST_REGION_NAME).Table(table_name) most_recent_provider = MostRecentProvider(provider_store=metastore, material_name="test", version_ttl=600.0) e_table = EncryptedTable(table=table, materials_provider=most_recent_provider) item = diverse_item() item.update(TEST_KEY) e_table.put_item(Item=item) e_table.put_item(Item=item) e_table.put_item(Item=item) e_table.put_item(Item=item) try: primary_puts = _count_puts(log_capture.records, e_table.name) metastore_puts = _count_puts(log_capture.records, metastore._table.name) assert primary_puts == 4 assert metastore_puts == 1 e_table.get_item(Key=TEST_KEY) e_table.get_item(Key=TEST_KEY) e_table.get_item(Key=TEST_KEY) primary_gets = _count_gets(log_capture.records, e_table.name) metastore_gets = _count_gets(log_capture.records, metastore._table.name) metastore_puts = _count_puts(log_capture.records, metastore._table.name) assert primary_gets == 3 assert metastore_gets == 0 assert metastore_puts == 1 most_recent_provider.refresh() e_table.get_item(Key=TEST_KEY) e_table.get_item(Key=TEST_KEY) e_table.get_item(Key=TEST_KEY) primary_gets = _count_gets(log_capture.records, e_table.name) metastore_gets = _count_gets(log_capture.records, metastore._table.name) assert primary_gets == 6 assert metastore_gets == 1 finally: e_table.delete_item(Key=TEST_KEY)
Example #17
Source File: clidriver.py From bash-lambda-layer with MIT License | 4 votes |
def main(self, args=None): """ :param args: List of arguments, with the 'aws' removed. For example, the command "aws s3 list-objects --bucket foo" will have an args list of ``['s3', 'list-objects', '--bucket', 'foo']``. """ if args is None: args = sys.argv[1:] command_table = self._get_command_table() parser = self._create_parser(command_table) self._add_aliases(command_table, parser) parsed_args, remaining = parser.parse_known_args(args) try: # Because _handle_top_level_args emits events, it's possible # that exceptions can be raised, which should have the same # general exception handling logic as calling into the # command table. This is why it's in the try/except clause. self._handle_top_level_args(parsed_args) self._emit_session_event(parsed_args) HISTORY_RECORDER.record( 'CLI_VERSION', self.session.user_agent(), 'CLI') HISTORY_RECORDER.record('CLI_ARGUMENTS', args, 'CLI') return command_table[parsed_args.command](remaining, parsed_args) except UnknownArgumentError as e: sys.stderr.write("usage: %s\n" % USAGE) sys.stderr.write(str(e)) sys.stderr.write("\n") return 255 except NoRegionError as e: msg = ('%s You can also configure your region by running ' '"aws configure".' % e) self._show_error(msg) return 255 except NoCredentialsError as e: msg = ('%s. You can configure credentials by running ' '"aws configure".' % e) self._show_error(msg) return 255 except KeyboardInterrupt: # Shell standard for signals that terminate # the process is to return 128 + signum, in this case # SIGINT=2, so we'll have an RC of 130. sys.stdout.write("\n") return 128 + signal.SIGINT except Exception as e: LOG.debug("Exception caught in main()", exc_info=True) LOG.debug("Exiting with rc 255") write_exception(e, outfile=get_stderr_text_writer()) return 255