Skip to content

Commit b02e9d6

Browse files
committed
Lambda fix for CDK
1 parent 0e9376d commit b02e9d6

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

infrastructure/scripts/setup/monitoring.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,23 @@ trap cleanup EXIT
4545

4646
# -- Generate secure username and password for webhook
4747
WEBHOOK_USER="grafana-alerts"
48-
WEBHOOK_PASSWORD=$(openssl rand -base64 16 | tr -d '\n')
49-
50-
# -- Create the secret for webhook
51-
aws secretsmanager create-secret \
52-
--name grafana-webhook-credentials \
48+
WEBHOOK_PASSWORD="$(openssl rand -base64 16 | tr -d '\n')"
49+
SECRET_NAME="grafana-webhook-credentials"
50+
SECRET_VALUE="{\"username\":\"$WEBHOOK_USER\",\"password\":\"$WEBHOOK_PASSWORD\"}"
51+
52+
# -- Create or update the secret for webhook
53+
if aws secretsmanager describe-secret --secret-id "$SECRET_NAME" >/dev/null 2>&1; then
54+
echo "🔁 Secret '$SECRET_NAME' exists. Updating..."
55+
aws secretsmanager put-secret-value \
56+
--secret-id "$SECRET_NAME" \
57+
--secret-string "$SECRET_VALUE"
58+
else
59+
echo "➕ Creating secret '$SECRET_NAME'..."
60+
aws secretsmanager create-secret \
61+
--name "$SECRET_NAME" \
5362
--description "Basic auth credentials for Grafana webhook to Lambda" \
54-
--secret-string "{\"username\":\"$WEBHOOK_USER\",\"password\":\"$WEBHOOK_PASSWORD\"}"
63+
--secret-string "$SECRET_VALUE"
64+
fi
5565

5666
echo "Webhook credentials created:"
5767
echo "Username: $WEBHOOK_USER"

0 commit comments

Comments
 (0)