The Simplest Way to Make Cloud Functions and Pagerduty Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use cloud functions and pagerduty to turn system events into incident alerts or automated fixes. A serverless function runs code on an event and sends an alert to the on-call team. This setup can also work in reverse during an active outage. When an alert fires, the incident platform can trigger a serverless function to gather logs. Both paths cut down manual work during high-stress pages. Still, connecting these tools requires careful work with secret keys, roles, and payload data. How

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams use cloud functions and pagerduty to turn system events into incident alerts or automated fixes. A serverless function runs code on an event and sends an alert to the on-call team.

This setup can also work in reverse during an active outage. When an alert fires, the incident platform can trigger a serverless function to gather logs. Both paths cut down manual work during high-stress pages. Still, connecting these tools requires careful work with secret keys, roles, and payload data.

How cloud functions and pagerduty pass data and keys

Data flows between cloud functions and pagerduty over HTTPS requests in two main directions. In the first path, a monitoring check spots an error and runs a function. The function formats the error details and sends an event payload to the incident API. It uses a routing key or an API token to prove its identity.

In the second path, the incident tool sends a webhook to the function URL. This happens when an incident starts, changes state, or gets a note from an engineer. The function must check the webhook signature before it runs any logic. After that check passes, the function uses its own cloud role to read system state. It might query a database or check server health, then post an update back.

Each step depends on stored secrets and cloud permissions. The function needs a safe place to read the API key at runtime. The incident platform needs a valid endpoint and a shared secret to sign outgoing payloads.

Common failure modes and how to scope permissions

Many teams start by putting one global API token into a shared function setting. That token often has full admin rights across every team schedule and service. If a bad actor reads that function setting, they can silence alerts or read incident notes. Shared service accounts also make audit logs hard to read during a review.

Another common risk comes from broad cloud roles attached to webhook functions. If an incident webhook triggers a function with admin cloud rights, any spoofed request is dangerous. Unlogged actions inside that function also hide what changed during an incident. Moreover, error payloads sent to the incident tool might include sensitive user fields. You should make sure masking rewrites matched fields in results, such as emails or phone numbers.

Cloud Functions IAM + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix these issues, scope every key and role to a single task. Give each function its own routing key tied to one service only. Use a dedicated secret store instead of plain text variables for API tokens. When the incident tool calls a function, check the cryptographic signature on every single request. Assign the function a minimal cloud role that can only read the needed metrics.

Designing reliable incident payloads and retry rules

Network drops and rate limits can break alert delivery right when an outage hits. If twenty systems fail at once, your functions might flood the incident API with calls. Without a deduping key, the on-call engineer gets twenty separate phone calls for one root cause.

Have your function build a steady deduping key from the service name and error type. The incident tool will group matching events into one open incident. Set up exponential backoff in your function code so temporary network errors retry cleanly. Keep function execution times short so webhook calls do not time out.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

How do we stop duplicate alerts when a function runs many times?

Generate a consistent deduping key inside your function based on the failing service and error class. Send this key in the event payload so the incident tool merges repeat triggers.

Where should a serverless function store the incident API token?

Store the token in a managed cloud secret store rather than in plain function settings. Grant the function role read permissions for that single secret only at runtime.

How can a function check that an incoming incident webhook is real?

Read the signature header sent with the webhook request and compare it using your webhook secret. Reject any request that fails this check or has an old timestamp.

The query runs. The emails stay hidden.