@@ -57,8 +57,6 @@ def get_api_key() -> str:
5757 if api_key :
5858 return api_key
5959
60- import boto3
61-
6260 DD_API_KEY_SECRET_ARN = os .environ .get ("DD_API_KEY_SECRET_ARN" , "" )
6361 DD_API_KEY_SSM_NAME = os .environ .get ("DD_API_KEY_SSM_NAME" , "" )
6462 DD_KMS_API_KEY = os .environ .get ("DD_KMS_API_KEY" , "" )
@@ -85,7 +83,7 @@ def get_api_key() -> str:
8583 if is_gov_region
8684 else None
8785 )
88- secrets_manager_client = boto3 . client (
86+ secrets_manager_client = _boto3_client (
8987 "secretsmanager" , endpoint_url = endpoint_url , region_name = secrets_region
9088 )
9189 api_key = secrets_manager_client .get_secret_value (
@@ -96,7 +94,7 @@ def get_api_key() -> str:
9694 fips_endpoint = (
9795 f"https://ssm-fips.{ LAMBDA_REGION } .amazonaws.com" if is_gov_region else None
9896 )
99- ssm_client = boto3 . client ("ssm" , endpoint_url = fips_endpoint )
97+ ssm_client = _boto3_client ("ssm" , endpoint_url = fips_endpoint )
10098 api_key = ssm_client .get_parameter (
10199 Name = DD_API_KEY_SSM_NAME , WithDecryption = True
102100 )["Parameter" ]["Value" ]
@@ -105,7 +103,7 @@ def get_api_key() -> str:
105103 fips_endpoint = (
106104 f"https://kms-fips.{ LAMBDA_REGION } .amazonaws.com" if is_gov_region else None
107105 )
108- kms_client = boto3 . client ("kms" , endpoint_url = fips_endpoint )
106+ kms_client = _boto3_client ("kms" , endpoint_url = fips_endpoint )
109107 api_key = decrypt_kms_api_key (kms_client , DD_KMS_API_KEY )
110108 else :
111109 api_key = DD_API_KEY
@@ -133,3 +131,9 @@ def init_api():
133131
134132 # Unmute exceptions from datadog api client, so we can catch and handle them
135133 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