Skip to content

Commit a41cbb3

Browse files
committed
use fips endpoints in govcloud regions
1 parent 6e2e5d5 commit a41cbb3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

datadog_lambda/api.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,36 @@ def get_api_key() -> str:
6464
DD_KMS_API_KEY = os.environ.get("DD_KMS_API_KEY", "")
6565
DD_API_KEY = os.environ.get("DD_API_KEY", os.environ.get("DATADOG_API_KEY", ""))
6666

67+
REGION = os.environ.get("AWS_REGION", "")
68+
is_gov_region = REGION.startswith("us-gov-")
69+
6770
if DD_API_KEY_SECRET_ARN:
68-
api_key = boto3.client("secretsmanager").get_secret_value(
71+
# Secrets manager endpoints: https://docs.aws.amazon.com/general/latest/gr/asm.html
72+
fips_endpoint = f"https://secretsmanager-fips.{REGION}.amazonaws.com" if is_gov_region else None
73+
secrets_manager_client = boto3.client(
74+
"secretsmanager",
75+
endpoint_url=fips_endpoint
76+
)
77+
api_key = secrets_manager_client.get_secret_value(
6978
SecretId=DD_API_KEY_SECRET_ARN
7079
)["SecretString"]
7180
elif DD_API_KEY_SSM_NAME:
72-
api_key = boto3.client("ssm").get_parameter(
81+
# SSM endpoints: https://docs.aws.amazon.com/general/latest/gr/ssm.html
82+
fips_endpoint = f"https://ssm-fips.{REGION}.amazonaws.com" if is_gov_region else None
83+
ssm_client = boto3.client(
84+
"ssm",
85+
endpoint_url=fips_endpoint
86+
)
87+
api_key = ssm_client.get_parameter(
7388
Name=DD_API_KEY_SSM_NAME, WithDecryption=True
7489
)["Parameter"]["Value"]
7590
elif DD_KMS_API_KEY:
76-
kms_client = boto3.client("kms")
91+
# KMS endpoints: https://docs.aws.amazon.com/general/latest/gr/kms.html
92+
fips_endpoint = f"https://kms-fips.{REGION}.amazonaws.com" if is_gov_region else None
93+
kms_client = boto3.client(
94+
"kms",
95+
endpoint_url=fips_endpoint
96+
)
7797
api_key = decrypt_kms_api_key(kms_client, DD_KMS_API_KEY)
7898
else:
7999
api_key = DD_API_KEY

0 commit comments

Comments
 (0)