Automation

Azure Functions: validate a slot swap before releasing event triggers

A production runbook for proving slot settings, event-source isolation, trigger behavior, observability and rollback before swapping an Azure Function App.

22 Oct 2026 azureazure-functionsdeployment-slotsevent-drivenservice-busmanaged-identitydevopsobservabilityautomationrunbookrollbackproduction

An Azure Function App is ready to move from staging to production. Its HTTP health endpoint is green, the package is correct, and the slot swap is reversible. Yet the application also consumes Service Bus messages and writes to a production dependency. If the event-source settings are not isolated, staging can process live messages before promotion. If they move with the code unexpectedly, the new version can listen to the wrong queue after the swap.

This runbook treats the swap as a change to an event-processing contract, not only an HTTP routing change. The goal is to prove which slot can receive each trigger, which identity performs the work, how one canary event is observed, and when to promote, hold or swap back without creating a second incident.

Freeze the trigger and release contract

Start with one inventory that joins the release, slots and external state. Do not rely on the function list alone: bindings can reference app settings, Key Vault references and identities whose behavior differs by slot.

yaml function-slot-release-contract.yml
release:
function_app: fn-orders-prod
resource_group: rg-orders-prod
source_slot: staging
target_slot: production
artifact_digest: <sha256>
hosting_plan: elastic-premium

triggers:
http_health:
  side_effect: none
service_bus_orders:
  source_setting: OrdersServiceBus
  entity: orders-prod
  consumer: orders
  idempotency_key: orderId

slot_contract:
staging_event_source: orders-canary
production_event_source: orders-prod
event_source_settings_are_sticky: true
runtime_identity_by_slot: recorded
rollback_owner: <on-call-release-owner>

evidence:
canary_event_id: slot-swap-7f31
pre_swap_window_utc: <start/end>
post_swap_window_utc: <start/end>

First confirm that the hosting plan supports deployment slots. Flex Consumption currently uses site update strategies rather than deployment slots. If the platform does not support the release mechanism, stop here instead of adapting commands until they appear to work.

Prove which settings stay with each slot

During a swap, code and non-sticky configuration can move while slot-specific settings remain attached to their slot. Event-source and binding settings should be marked as deployment slot settings before the change so events and outputs stay connected to the intended environment.

Export names and stickiness without printing secret values.

bash 01-audit-slot-settings.sh
set -euo pipefail

RG="rg-orders-prod"
APP="fn-orders-prod"

az functionapp config appsettings list -g "$RG" -n "$APP" --query "[].{name:name,slotSetting:slotSetting}" -o json > production-setting-contract.json

az functionapp config appsettings list -g "$RG" -n "$APP" --slot staging --query "[].{name:name,slotSetting:slotSetting}" -o json > staging-setting-contract.json

for key in AzureWebJobsStorage OrdersServiceBus FUNCTIONS_WORKER_RUNTIME; do
jq --arg key "$key" '.[] | select(.name == $key)'   production-setting-contract.json
jq --arg key "$key" '.[] | select(.name == $key)'   staging-setting-contract.json
done

Review at least the host storage connection, every trigger or output connection, runtime version, Key Vault references, feature flags and identity selector. A matching setting name is not enough. Prove the target resource, slot flag and identity that resolves it. Keep values redacted from tickets and logs.

Isolate staging from production events

A staging slot is a live application. Protect its endpoint and give non-HTTP triggers an explicit test boundary. For the running case, staging listens to orders-canary, while production listens to orders-prod. Both settings remain sticky.

If a separate canary entity is impossible, use a trigger-disable setting attached to staging and validate the package through side-effect-free paths. Do not enable a production listener merely to prove startup. Also verify that timers, Event Grid subscriptions, storage listeners and Durable Functions task hubs cannot collide with production state.

text event-source-isolation-matrix.txt
Service Bus or Event Hubs
Distinct entity, subscription or consumer group for staging
One synthetic message with a unique business id

Timer trigger
Disabled in staging, or guarded by an explicit environment lease
No production write during warmup

Storage trigger
Separate container or prefix and separate poison-message path

Durable Functions
Distinct task hub name and storage contract

HTTP trigger
Restricted staging hostname and a side-effect-free readiness route

The contract must include outputs too. A canary input that writes to the production database is not isolated.

Warm the host without mistaking warmup for validation

Deploy the immutable package to staging and record the deployed digest. Confirm that the Functions host starts, indexes the expected functions and resolves configuration with the staging identity.

The warmup trigger is useful on supported plans when a new instance is added during scale-out, but it is not called for every restart or other non-scaling startup. It cannot be the only release gate. Run an explicit readiness probe and one canary through the real binding.

bash 02-probe-staging-and-send-canary.sh
set -euo pipefail

CANARY_ID="slot-swap-7f31"
STAGING_HOST="fn-orders-prod-staging.azurewebsites.net"

curl --fail-with-body --silent --show-error -H "x-correlation-id: $CANARY_ID" "https://$STAGING_HOST/api/health/ready"

NAMESPACE="sb-orders-prod"
QUEUE="orders-canary"
TOKEN=$(az account get-access-token --resource https://servicebus.azure.net --query accessToken -o tsv)

curl --fail-with-body --silent --show-error -X POST "https://$NAMESPACE.servicebus.windows.net/$QUEUE/messages" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "BrokerProperties: {"MessageId":"$CANARY_ID"}" --data "{"orderId":"$CANARY_ID","mode":"validation"}"

The caller needs only the Service Bus data-plane send permission on the canary entity. Adapt the send step to the approved SDK or operational tool available in the environment. The important evidence is the immutable canary identifier, not the client used to publish it.

Correlate one event from receipt to side effect

The candidate is ready only when the event appears once in the intended slot, under the intended identity, and produces the bounded expected result. Query by canary ID and retain the slot, role instance, operation and dependency outcome.

kusto 03-correlate-trigger-canary.kql
let CanaryId = "slot-swap-7f31";
let Window = 30m;
union isfuzzy=true requests, dependencies, traces, exceptions
| where timestamp > ago(Window)
| where tostring(customDimensions["CanaryId"]) == CanaryId
  or operation_Id == CanaryId
  or message has CanaryId
| project timestamp, itemType, operation_Id, name,
        success, resultCode, cloud_RoleName, cloud_RoleInstance,
        Slot = tostring(customDimensions["Slot"]),
        Trigger = tostring(customDimensions["Trigger"]),
        message
| order by timestamp asc

Validate the negative path as well: production must not see the staging canary, and staging must not consume from the production entity. Check active messages, dead letters, retries and downstream writes before declaring success. A single successful trace does not exclude duplicate processing.

Define the promotion and rollback gates

Take a pre-swap baseline for invocation count, failures, duration, queue depth, dead letters and dependency errors. Preserve the slot configuration exports and the previous artifact digest.

text slot-swap-decision-gates.txt
Promote
Package digest and function inventory match the release
Event-source and output settings are sticky and correctly targeted
One canary is processed once by staging with the expected identity
Production does not observe the staging canary
Baseline, rollback command and owner are recorded

Hold
A trigger target or slot flag is ambiguous
Staging shares a production consumer group or Durable task hub
Readiness passes but the binding canary does not
Telemetry cannot distinguish slots or prove duplicate absence

Swap back
New production events fail, duplicate or reach the wrong dependency
Error, retry or dead-letter rate crosses the release threshold
Previous code remains compatible with current external state

Execute the swap explicitly, then publish a new production canary. Do not reuse the staging canary ID.

bash 04-swap-and-validate.sh
az functionapp deployment slot swap --name "$APP" --resource-group "$RG" --slot staging --target-slot production

# Re-run readiness, then publish a new canary to the production event source.
# Keep the previous artifact and configuration exports until the gate closes.

A reverse swap restores code and swappable configuration; it does not undo messages already acknowledged, duplicate writes, external calls or schema changes. Before swapping back, verify that the previous version can still read the current message and data formats. Quarantine ambiguous events and reconcile them by idempotency key.

Conclusion

An Azure Functions slot swap is safe only when event ownership is as clear as HTTP routing. Prove sticky binding settings, isolate staging sources and outputs, correlate one canary end to end, and watch duplicates and dead letters after promotion.

The decision is operationally complete when the team can state which slot processed each event, which identity acted, which threshold closes the rollout, and what external state must be reconciled if the code is swapped back.