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

fix: read from default boto3 session if present. #3224

Merged
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
3 changes: 2 additions & 1 deletion samtranslator/region_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def is_service_supported(cls, service, region=None): # type: ignore[no-untyped-
:return: True, if the service is supported in the region
"""

session = boto3.Session()
# Attempt to re-use an existing session if present.
session = boto3.Session() if not boto3.DEFAULT_SESSION else boto3.DEFAULT_SESSION

if not region:
# get the current region
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_region_configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase
from unittest.mock import patch

import boto3
from parameterized import parameterized
from samtranslator.region_configuration import RegionConfiguration

Expand Down Expand Up @@ -51,6 +52,11 @@ def test_when_apigw_edge_configuration_is_not_supported(self, partition):
def test_is_service_supported_positive(self, service, region):
self.assertTrue(RegionConfiguration.is_service_supported(service, region))

def test_is_service_supported_positive_boto3_default_session(self):
new_region = "us-west-2"
boto3.setup_default_session(region_name=new_region)
self.assertTrue(RegionConfiguration.is_service_supported("ec2", new_region))

def test_is_service_supported_negative(self):
# use an unknown service name
self.assertFalse(RegionConfiguration.is_service_supported("ec1", "us-east-1"))
Expand Down