Skip to content

Instantly share code, notes, and snippets.

@adriankeenan
Created November 29, 2025 00:25
Show Gist options
  • Select an option

  • Save adriankeenan/a349e6287f97967f6f6553d2d39992f3 to your computer and use it in GitHub Desktop.

Select an option

Save adriankeenan/a349e6287f97967f6f6553d2d39992f3 to your computer and use it in GitHub Desktop.
Pushover for SNS notifications

This is a lmabda function I'm using to forward Cloudwatch SNS alerts to my iPhone via Pushbullet.

Just create the JS lambda function, set the two pushbullet env vars, and configure the lambda as an SNS subscriber.

Far more ideal than using the SNS email sandbox (though still good as a fallback). This could also be easily extended for other event sources.

async function sendPushoverNotification(title, message, params = {}) {
const token = process.env.PUSHOVER_TOKEN;
const user = process.env.PUSHOVER_USER;
const url = 'https://api.pushover.net/1/messages.json'
try {
message = JSON.stringify(JSON.parse(message), null, 4);
} catch {}
const request = { ...params, title, message };
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token,
user,
...request,
})
});
const status = response.status;
const body = await response.text();
if (!response.ok) {
throw new Error(`Pushover API error - status: ${status}, body: ${body}`);
}
return {
request,
response: { status, body }
}
}
export const handler = async (event) => {
// Test
if (event.payload) {
return await sendPushoverNotification(event.payload.title, event.payload.message, event.payload)
}
// SNS
if (event.Records && event.Records[0].EventSource === 'aws:sns') {
return await Promise.all(
event.Records.map(async (record) => {
return sendPushoverNotification(
record.Sns.Subject ?? record.Sns.TopicArn.split(':').pop(),
record.Sns.Message,
)
})
)
}
throw new Error('Unknown event source')
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment