What are you proposing?
SAM helps simplify the definition of Lambda functions, API Gateway and associated configurations. But it does not provide yet any mechanisms to simplify operational aspects of your application. I am proposing adding the ability for SAM to automatically create Cloudwatch alarms for all resources in the template.
Example code
Globals:
Function:
Alarms:
# All Lambda functions will get a Throttle CloudWatch alarm. If necessary, each function can override certain properties alarm as they need
Throttles:
Metric: "throttle"
# Notify if the Lambda gets throttled in 5min interval
Threshold: 1
Timeframe: "5min"
Notification:
Type: Email
Address: pager@example.com
MyFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs4.3
CodeUri: s3://bucket/key
...
Alarms:
Throttles:
# Override the timeframe to 10mins for this function
Timeframe: "10min"
Errors:
Metric: "my-custom-metric"
Threshold: 100
Timeframe: "1min"
Notification:
Type: SNS
Address: !Ref OpsSnsTopic
Alarms will also be available for API resources as well. It is just not shown in the above template.
Automatic alarms
In addition to the above syntax, I propose adding a short-cut for example, Alarms: "default" which is a special case where SAM will automatically create necessary alarms for each resource with reasonable default configuration that should "just work" out of the box.
"default" will expand to a Alarm Template that is pre-configured in SAM and will be publicly documented.
In the future, we could expose make Alarm Template functionality a first-class citizen allowing users to define their own alarm templates. So you could define the template once, and use Alarms: "my-prod-template" to let SAM automatically create alarms based on your template.
How would this work?
When an Alarms configuration is specified, SAM will automatically create AWS::CloudWatch::Metric for the specific resource and AWS::CloudWatch::Alarm on the metric with given configuration. Users will be able to refer to the generated Metric & Alarm resources in rest of the template using !Ref MyFunction.Metric.<metric-name> or !Ref MyFunction.Alarm.<alarm-name> shorthand syntax that SAM will provide.
Process
This Issue describes a very broad set of features. We need your feedback to understand what is important to you. Please comment with your thoughts and help us evolve the requirements into a spec that can be implemented.
What are you proposing?
SAM helps simplify the definition of Lambda functions, API Gateway and associated configurations. But it does not provide yet any mechanisms to simplify operational aspects of your application. I am proposing adding the ability for SAM to automatically create Cloudwatch alarms for all resources in the template.
Example code
Alarms will also be available for API resources as well. It is just not shown in the above template.
Automatic alarms
In addition to the above syntax, I propose adding a short-cut for example,
Alarms: "default"which is a special case where SAM will automatically create necessary alarms for each resource with reasonable default configuration that should "just work" out of the box."default" will expand to a Alarm Template that is pre-configured in SAM and will be publicly documented.
In the future, we could expose make Alarm Template functionality a first-class citizen allowing users to define their own alarm templates. So you could define the template once, and use
Alarms: "my-prod-template"to let SAM automatically create alarms based on your template.How would this work?
When an Alarms configuration is specified, SAM will automatically create
AWS::CloudWatch::Metricfor the specific resource andAWS::CloudWatch::Alarmon the metric with given configuration. Users will be able to refer to the generated Metric & Alarm resources in rest of the template using!Ref MyFunction.Metric.<metric-name>or!Ref MyFunction.Alarm.<alarm-name>shorthand syntax that SAM will provide.Process
This Issue describes a very broad set of features. We need your feedback to understand what is important to you. Please comment with your thoughts and help us evolve the requirements into a spec that can be implemented.