@@ -57,8 +57,6 @@ def get_api_key() -> str:
57
57
if api_key :
58
58
return api_key
59
59
60
- import boto3
61
-
62
60
DD_API_KEY_SECRET_ARN = os .environ .get ("DD_API_KEY_SECRET_ARN" , "" )
63
61
DD_API_KEY_SSM_NAME = os .environ .get ("DD_API_KEY_SSM_NAME" , "" )
64
62
DD_KMS_API_KEY = os .environ .get ("DD_KMS_API_KEY" , "" )
@@ -85,7 +83,7 @@ def get_api_key() -> str:
85
83
if is_gov_region
86
84
else None
87
85
)
88
- secrets_manager_client = boto3 . client (
86
+ secrets_manager_client = _boto3_client (
89
87
"secretsmanager" , endpoint_url = endpoint_url , region_name = secrets_region
90
88
)
91
89
api_key = secrets_manager_client .get_secret_value (
@@ -96,7 +94,7 @@ def get_api_key() -> str:
96
94
fips_endpoint = (
97
95
f"https://ssm-fips.{ LAMBDA_REGION } .amazonaws.com" if is_gov_region else None
98
96
)
99
- ssm_client = boto3 . client ("ssm" , endpoint_url = fips_endpoint )
97
+ ssm_client = _boto3_client ("ssm" , endpoint_url = fips_endpoint )
100
98
api_key = ssm_client .get_parameter (
101
99
Name = DD_API_KEY_SSM_NAME , WithDecryption = True
102
100
)["Parameter" ]["Value" ]
@@ -105,7 +103,7 @@ def get_api_key() -> str:
105
103
fips_endpoint = (
106
104
f"https://kms-fips.{ LAMBDA_REGION } .amazonaws.com" if is_gov_region else None
107
105
)
108
- kms_client = boto3 . client ("kms" , endpoint_url = fips_endpoint )
106
+ kms_client = _boto3_client ("kms" , endpoint_url = fips_endpoint )
109
107
api_key = decrypt_kms_api_key (kms_client , DD_KMS_API_KEY )
110
108
else :
111
109
api_key = DD_API_KEY
@@ -133,3 +131,9 @@ def init_api():
133
131
134
132
# Unmute exceptions from datadog api client, so we can catch and handle them
135
133
api ._mute = False
134
+
135
+
136
+ def _boto3_client (* args , ** kwargs ):
137
+ import botocore .session
138
+
139
+ return botocore .session .get_session ().create_client (* args , ** kwargs )
0 commit comments