chore: simplify botocore/boto3-related util code #256
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes:
This PR removes the redundant creation of botocore configs (which are just duplicates of the config used in
get_boto_session) found inget_sagemaker_sessionandget_bedrock_runtime_client.Since we set the default client config used by the botocore session underlying the boto3 session that is used to create all of our clients (sagemaker, bedrock, etc), we don't need to pass the
configparameter to.client().Note that it is very awkward to validate that the correct botocore config (i.e. our adaptive retry config) gets used when we create the sagemaker and bedrock clients, so I have not added a new unit test that checks this. Here is the logic flow for how the default botocore config ends up getting used:
boto3.session.Session.clientis called withconfig=None(since we don't explicitly pass a config)self._session.create_clientis called withconfig=Nonewhereselfrefers to aboto3.session.Sessioninstanceself._sessionis the botocore session that manually create inget_boto_session. Thus,self._session.create_clientcalls thecreate_clientmethod inbotocore.session.Session.botocore.session.Session.create_clientis of relevance:and
If I were to mock things, I would want to mock the instance method
create_client. But sincecreate_clientis called with a whole bunch of different args which aren't themselves easily mockable, there's no clean way to just check that theconfiginclient_config=configis our adaptive retry config.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.