Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function Throttle Alarms Serverless.yml Example
'use strict';
function sleep(ms){
return new Promise(resolve => setTimeout(resolve, ms));
}
module.exports.hello = async (event, context) => {
await sleep(5000); // hit api endpoint twice in 5 seconds, get a 429!
return {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};
service: function-throttle-alerting-example
custom:
alerts:
stages:
- dev
dashboards: false
definitions:
functionThrottles:
period: 60
topics:
ok: ${self:service}-${opt:stage}-alerts-ok
alarm:
topic: ${self:service}-${opt:stage}-alerts-alarm
notifications:
- protocol: email
endpoint: jared.short@serverless.com
insufficientData: ${self:service}-${opt:stage}-alerts-insufficient-data
alarms:
- functionThrottles
provider:
name: aws
runtime: nodejs8.10
functions:
hello:
handler: handler.hello
reservedConcurrency: 1 # make it easy to throttle and get 429 / 500 on api gateway
events:
- http:
path: test
method: get
plugins:
- serverless-plugin-aws-alerts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment