id: aws-cloudfront-5xx-error-rate-sentinel
namespace: company.cloud
inputs:
- id: distribution_id
type: STRING
description: Amazon CloudFront distribution ID.
- id: error_rate_threshold_pct
type: FLOAT
defaults: 5.0
description: Maximum acceptable percentage of 5XX error rate at edge locations.
tasks:
- id: query_cloudfront_telemetry
type: io.kestra.plugin.aws.cli.AwsCLI
region: "us-east-1"
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
commands:
- |
START_TIME=$(date -u -v-15M +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d "15 minutes ago" +%Y-%m-%dT%H:%M:%SZ)
END_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
aws cloudwatch get-metric-data --metric-data-queries '[{"Id":"err5xx","MetricStat":{"Metric":{"Namespace":"AWS/CloudFront","MetricName":"5xxErrorRate","Dimensions":[{"Name":"DistributionId","Value":"{{ inputs.distribution_id }}"},{"Name":"Region","Value":"Global"}]},"Period":900,"Stat":"Average"}}]' --start-time "$START_TIME" --end-time "$END_TIME" --output json > /tmp/cf_telemetry.json
ERROR_RATE=$(jq '.MetricDataResults[0].Values[0] // 0' /tmp/cf_telemetry.json)
echo "::set-output name=error_rate::$ERROR_RATE::"
- id: evaluate_edge_health
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.query_cloudfront_telemetry.vars.error_rate | float >
inputs.error_rate_threshold_pct }}"
then:
- id: notify_edge_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"channel": "#edge-network-alerts",
"attachments": [
{
"color": "danger",
"title": "🚨 AWS CloudFront 5XX Edge Error Rate Spike Alert",
"text": "CloudFront distribution `{{ inputs.distribution_id }}` recorded an average 5XX error rate of *{{ outputs.query_cloudfront_telemetry.vars.error_rate }}%*, exceeding threshold *{{ inputs.error_rate_threshold_pct }}%*. Impact: Global edge points of presence are serving HTTP 502/503/504 errors to visitors, indicating origin pool failure or misconfigured SSL handshakes.",
"footer": "Kestra Edge Sentinel • AWS CloudFront"
}
]
}
errors:
- id: alert_pipeline_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{
"channel": "#edge-network-alerts",
"attachments": [
{
"color": "danger",
"title": "⚠️ CloudFront Sentinel Execution Failed",
"text": "The CloudFront metric query workflow encountered an error. Please verify AWS credentials and distribution ID.",
"footer": "Kestra Workflow Failure Sentinel"
}
]
}
triggers:
- id: periodic_schedule
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"
disabled: true
inputs:
distribution_id: replace-with-your-distribution-id