Skip to content

Commit be4c9fb

Browse files
committed
only override ssm endpoint url in commercial fips
1 parent 36d7df2 commit be4c9fb

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

datadog_lambda/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def get_api_key() -> str:
9494
# SSM endpoints: https://docs.aws.amazon.com/general/latest/gr/ssm.html
9595
fips_endpoint = (
9696
f"https://ssm-fips.{LAMBDA_REGION}.amazonaws.com"
97-
if config.fips_mode_enabled
97+
if config.fips_mode_enabled and not config.is_gov_region
9898
else None
9999
)
100100
ssm_client = _boto3_client("ssm", endpoint_url=fips_endpoint)

tests/test_api.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,33 @@ def test_ssm_fips_endpoint(self, mock_boto3_client):
9696
}
9797
mock_boto3_client.return_value = mock_client
9898

99+
os.environ["AWS_REGION"] = "us-east-1"
100+
os.environ["DD_API_KEY_SSM_NAME"] = "test-ssm-param"
101+
102+
api_key = api.get_api_key()
103+
104+
mock_boto3_client.assert_called_with(
105+
"ssm", endpoint_url="https://ssm-fips.us-east-1.amazonaws.com"
106+
)
107+
self.assertEqual(api_key, "test-api-key")
108+
109+
@patch("datadog_lambda.config.Config.fips_mode_enabled", True)
110+
@patch("datadog_lambda.config.Config.is_gov_region", True)
111+
@patch("botocore.session.Session.create_client")
112+
def test_ssm_gov_endpoint(self, mock_boto3_client):
113+
mock_client = MagicMock()
114+
mock_client.get_parameter.return_value = {
115+
"Parameter": {"Value": "test-api-key"}
116+
}
117+
mock_boto3_client.return_value = mock_client
118+
99119
os.environ["AWS_REGION"] = "us-gov-west-1"
100120
os.environ["DD_API_KEY_SSM_NAME"] = "test-ssm-param"
101121

102122
api_key = api.get_api_key()
103123

104124
mock_boto3_client.assert_called_with(
105-
"ssm", endpoint_url="https://ssm-fips.us-gov-west-1.amazonaws.com"
125+
"ssm", endpoint_url=None
106126
)
107127
self.assertEqual(api_key, "test-api-key")
108128

0 commit comments

Comments
 (0)