Imagine this scenario:
It’s Friday evening. Traffic spikes unexpectedly. Memory usage climbs past your threshold. The broker upgrades itself, no manual intervention is required. This is not hypothetical. Let’s see how it works.
Setting up webhook notifications
- Open your instance’s Alarm settings
- Add a Webhook recipient
- Provide a public endpoint URL
- Assign the webhook to one or more alarms
When an alarm triggers, CloudAMQP sends a POST request with alarm details to your endpoint.
Example alarm payload:
{
"alarm_type": "memory",
"value": 85,
"instance_id": "3555175d-4055-46e9-81b1-288a17846b9a",
"triggered_at": "2026-02-20T08:30:00Z"
}
Triggering an automatic upgrade
To implement automatic upgrades, you'll need to make an authenticated API call to CloudAMQP's upgrade endpoint. Use your CloudAMQP API key in the request header.
POST https://customer.cloudamqp.com/api/instances/{instance_id}/actions/upgrade
Request body:
JSON
{
"plan": "bunny-2",
"reason": "Triggered by memory alarm"
}
Example: upgrading automatically from a webhook (Python)
Below is a minimal Python example that:
- receives an alarm webhook
- checks memory usage
- triggers an upgrade if a threshold is exceeded
import requests
import os
CLOUDAMQP_API_KEY = os.environ.get("CLOUDAMQP_API_KEY")
INSTANCE_ID = os.environ.get("CLOUDAMQP_INSTANCE_ID")
UPGRADE_PLAN = "bunny-2" # this is the target plan
def handle_alarm(alarm_payload: dict):
alarm_type = alarm_payload.get("alarm_type")
alarm_value = alarm_payload.get("value")
if alarm_type == "memory" and alarm_value > 80:
trigger_upgrade(alarm_type, alarm_value)
def trigger_upgrade(alarm_type: str, alarm_value: int):
url = f"https://customer.cloudamqp.com/api/instances/{INSTANCE_ID}/actions/upgrade"
headers = {
"Authorization": f"Bearer {CLOUDAMQP_API_KEY}",
"Content-Type": "application/json"
}
payload = {
"plan": UPGRADE_PLAN,
"reason": f"Automatic upgrade triggered by {alarm_type} alarm ({alarm_value}%)"
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
Before using the example code, replace the following values with your own CloudAMQP credentials.
- CLOUDAMQP_API_KEY
- Log in to your CloudAMQP Console
- Click your profile icon in the top-right corner
- API Access
- Create a new API key or copy an existing one
- CLOUDAMQP_INSTANCE_ID
- Open your instance in the CloudAMQP console
- Click the Overview page of the instance
- Check the browser address bar
This is used to authenticate API requests to CloudAMQP.
How to find it:
This identifies the CloudAMQP instance that should be upgraded.
How to find it:
You’ll see something like:
https://api.cloudamqp.com/console/3555175d-4055-46e9-81b1-288a17846b9a/details
The part below is your instance ID:
3555175d-4055-46e9-81b1-288a17846b9a
For production use, we recommend storing these values as environment variables:
export CLOUDAMQP_API_KEY="your-api-key-here"
export CLOUDAMQP_INSTANCE_ID="your-instance-id-here"
Run and connect the webhook
The Python example above shows the upgrade logic, but it must run as a webhook service so CloudAMQP can send alarm events to it.
One simple way to do this is to package the code in a Docker container and run it on a publicly accessible server.
Docker setup
Create the following files in the same directory as your Python example.
requirements.txt
requests
flask
Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["python", "app.py"]
Build and run the container:
docker build -t cloudamqp-alarm-webhook .
docker run -d \
-p 8080:8080 \
-e CLOUDAMQP_API_KEY="YOUR_API_KEY" \
-e CLOUDAMQP_INSTANCE_ID="YOUR_INSTANCE_ID" \
cloudamqp-alarm-webhook
The webhook endpoint will be available at:
http://
Once the webhook service is running and publicly accessible, the final step is to connect it to an alarm in the CloudAMQP console.
Step 1: Open your instance alarms
- Log in to your ClouadAMQP console
- Open the instance you want to monitor
- Navigate to Alarms
You will manage both alarm recipients and alarms from this page.
Step 2: Create the webhook recipient
This step defines where CloudAMQP sends alarm events.
- In the Notification recipients section, click Add new recipients
- Select Webhook as the recipient type
-
Paste your webhook URL, for example:
(
http://<server-ip>:8080/cloudamqp/alarm)
This webhook recipient can now be reused by multiple alarms.
Step 3: Create an alarm and attach the webhook
This step defines when the webhook is triggered.
-
In the
Alarms section, click Add new alarm - Select the alarm type ( Memory )
- Configure the alarm threshold and duration
- Under Recipients , select the webhook recipient you just created
- Click Save
The alarm is now active and connected to your webhook.
What happens when the alarm triggers
When the configured threshold is exceeded:
- CloudAMQP triggers the alarm
-
A
POSTThe request is sent to the webhook URL - The webhook evaluates the alarm payload
- If the condition matches, an automatic upgrade is triggered
Let our support team know if you have any questions setting up alarms.