8000 Add support for API Key in SSM (#95) · DataDog/datadog-lambda-python@947e4b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 947e4b2

Browse files
Add support for API Key in SSM (#95)
1 parent 6a236e2 commit 947e4b2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ If `DD_FLUSH_TO_LOG` is set to `false` (not recommended), the Datadog API Key mu
4949
- DD_API_KEY - the Datadog API Key in plain-text, NOT recommended
5050
- DD_KMS_API_KEY - the KMS-encrypted API Key, requires the `kms:Decrypt` permission
5151
- DD_API_KEY_SECRET_ARN - the Secret ARN to fetch API Key from the Secrets Manager, requires the `secretsmanager:GetSecretValue` permission (and `kms:Decrypt` if using a customer managed CMK)
52+
- DD_API_KEY_SSM_NAME - the Parameter Name to fetch API Key from the Systems Manager Parameter Store, requires the `ssm:GetParameter` permission (and `kms:Decrypt` if using a SecureString with a customer managed CMK)
5253

5354
You can also supply or override the API key at runtime (not recommended):
5455

datadog_lambda/metric.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,18 @@ def submit_errors_metric(lambda_context):
136136
# Set API Key and Host in the module, so they only set once per container
137137
if not api._api_key:
138138
DD_API_KEY_SECRET_ARN = os.environ.get("DD_API_KEY_SECRET_ARN", "")
139+
DD_API_KEY_SSM_NAME = os.environ.get("DD_API_KEY_SSM_NAME", "")
139140
DD_KMS_API_KEY = os.environ.get("DD_KMS_API_KEY", "")
140141
DD_API_KEY = os.environ.get("DD_API_KEY", os.environ.get("DATADOG_API_KEY", ""))
141142
if DD_API_KEY_SECRET_ARN:
142143
api._api_key = boto3.client("secretsmanager").get_secret_value(
143144
SecretId=DD_API_KEY_SECRET_ARN
144145
)["SecretString"]
146+
elif DD_API_KEY_SSM_NAME:
147+
api._api_key = boto3.client("ssm").get_parameter(
148+
Name=DD_API_KEY_SSM_NAME,
149+
WithDecryption=True
150+
)["Parameter"]["Value"]
145151
elif DD_KMS_API_KEY:
146152
api._api_key = boto3.client("kms").decrypt(
147153
CiphertextBlob=base64.b64decode(DD_KMS_API_KEY)

0 commit comments

Comments
 (0)
0