@@ -54,8 +54,6 @@ def init_api():
54
54
from datadog import api
55
55
56
56
if not api ._api_key :
57
- import boto3
58
-
59
57
DD_API_KEY_SECRET_ARN = os .environ .get ("DD_API_KEY_SECRET_ARN" , "" )
60
58
DD_API_KEY_SSM_NAME = os .environ .get ("DD_API_KEY_SSM_NAME" , "" )
61
59
DD_KMS_API_KEY = os .environ .get ("DD_KMS_API_KEY" , "" )
@@ -64,15 +62,15 @@ def init_api():
64
62
)
65
63
66
64
if DD_API_KEY_SECRET_ARN :
67
- api ._api_key = boto3 . client ("secretsmanager" ).get_secret_value (
65
+ api ._api_key = _boto3_client ("secretsmanager" ).get_secret_value (
68
66
SecretId = DD_API_KEY_SECRET_ARN
69
67
)["SecretString" ]
70
68
elif DD_API_KEY_SSM_NAME :
71
- api ._api_key = boto3 . client ("ssm" ).get_parameter (
69
+ api ._api_key = _boto3_client ("ssm" ).get_parameter (
72
70
Name = DD_API_KEY_SSM_NAME , WithDecryption = True
73
71
)["Parameter" ]["Value" ]
74
72
elif DD_KMS_API_KEY :
75
- kms_client = boto3 . client ("kms" )
73
+ kms_client = _boto3_client ("kms" )
76
74
api ._api_key = decrypt_kms_api_key (kms_client , DD_KMS_API_KEY )
77
75
else :
78
76
api ._api_key = DD_API_KEY
@@ -87,3 +85,7 @@ def init_api():
87
85
88
86
# Unmute exceptions from datadog api client, so we can catch and handle them
89
87
api ._mute = False
88
+
89
+ def _boto3_client (* args , ** kwargs ):
90
+ import botocore
91
+ return botocore .session .get_session ().create_client (* args , ** kwargs )
0 commit comments