Skip to content

Commit 1ecdf55

Browse files
awood45Alex Woodammokhov
authored
Add Session Object to SessionProxy (#164)
* Add Session Object to SessionProxy Allows for the user of the plugin to retrieve the boto3 Session object and use it directly as needed. Co-authored-by: Alex Wood <[email protected]> Co-authored-by: Anton Mokhovikov <[email protected]>
1 parent 9d494c9 commit 1ecdf55

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/cloudformation_cli_python_lib/boto3_proxy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class SessionProxy:
1010
def __init__(self, session: Session):
1111
self.client = session.client
1212
self.resource = session.resource
13+
self.session = session
1314

1415

1516
def _get_boto_session(

src/cloudformation_cli_python_lib/log_delivery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _put_log_event(self, msg: logging.LogRecord) -> None:
9090
self.client.exceptions.DataAlreadyAcceptedException,
9191
self.client.exceptions.InvalidSequenceTokenException,
9292
) as e:
93-
self.sequence_token = str(e).split(" ")[-1]
93+
self.sequence_token = str(e).rsplit(" ", maxsplit=1)[-1]
9494
self._put_log_event(msg)
9595

9696
def emit(self, record: logging.LogRecord) -> None:

tests/lib/boto3_proxy_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from boto3.session import Session
12
from cloudformation_cli_python_lib.boto3_proxy import SessionProxy, _get_boto_session
23
from cloudformation_cli_python_lib.utils import Credentials
34

5+
import botocore # pylint: disable=C0411
6+
47

58
def test_get_boto_session_returns_proxy():
69
proxy = _get_boto_session(Credentials("", "", ""))
@@ -10,3 +13,17 @@ def test_get_boto_session_returns_proxy():
1013
def test_get_boto_session_returns_none():
1114
proxy = _get_boto_session(None)
1215
assert proxy is None
16+
17+
18+
def test_can_create_boto_client():
19+
proxy = _get_boto_session(Credentials("", "", ""))
20+
client = proxy.client(
21+
"s3", region_name="us-west-2"
22+
) # just in case AWS_REGION not set in test environment
23+
assert isinstance(client, botocore.client.BaseClient)
24+
25+
26+
def test_can_retrieve_boto_session():
27+
proxy = _get_boto_session(Credentials("", "", ""))
28+
session = proxy.session
29+
assert isinstance(session, Session)

0 commit comments

Comments
 (0)