Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_partition_for_region to Session #3060

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/enhancement-Session-24336.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "enhancement",
"category": "Session",
"description": "Added `get_partition_for_region` to lookup partition for a given region_name"
}
12 changes: 12 additions & 0 deletions boto3/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ def get_credentials(self):
"""
return self._session.get_credentials()

def get_partition_for_region(self, region_name):
"""Lists the partition name of a particular region.

:type region_name: string
:param region_name: Name of the region to list partition for (e.g.,
us-east-1).

:rtype: string
:return: Returns the respective partition name (e.g., aws).
"""
return self._session.get_partition_for_region(region_name)

def client(self, service_name, region_name=None, api_version=None,
use_ssl=True, verify=None, endpoint_url=None,
aws_access_key_id=None, aws_secret_access_key=None,
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ def test_get_available_regions(self):
)
assert partitions == ['foo']

def test_get_partition_for_region(self):
bc_session = mock.Mock()
bc_session.get_partition_for_region.return_value = 'baz'
session = Session(botocore_session=bc_session)

partition = session.get_partition_for_region('foo-bar-1')
bc_session.get_partition_for_region.assert_called_with(
'foo-bar-1'
)
assert partition == 'baz'

def test_create_client(self):
session = Session(region_name='us-east-1')
client = session.client('sqs', region_name='us-west-2')
Expand Down