Lazy load boto client when using datadogpy for metrics. #558
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.
What does this PR do?
Lazy load boto3 and botocore libraries to use only when required.
Motivation
Faster cold starts when using datadogpy for sending metrics.
Testing Guidelines
Additional Notes
Original method for creating boto3 client
But
boto3.client
code is just (see https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/__init__.py#L92)where
_get_default_session()
is defined as (see https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/__init__.py#L34)The
client
method on aSession
is just (see https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/session.py#L215)Where
self._session
is an instance ofbotocore.session.Session
(usingbotocore.session.get_session
see https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/session.py#L62)Long story short, we can avoid importing all of boto3!!
Types of Changes
Check all that apply