Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Created June 19, 2021 14:19
Show Gist options
  • Save leegilmorecode/fdc56a316a43cfc7a61c6834d4b8bb64 to your computer and use it in GitHub Desktop.
Save leegilmorecode/fdc56a316a43cfc7a61c6834d4b8bb64 to your computer and use it in GitHub Desktop.
Bespoke IaC configuration depending on stage being deployed
import { config } from "@shared/config";
import { Stages } from "@models/Stages";
import hello from "@functions/hello";
export const configureAlarms = () => {
// only add alarm if prod or staging
if (config.stage === Stages.prod || config.stage === Stages.staging) {
return {
HelloFunctionErrorAlarm: {
Type: "AWS::CloudWatch::Alarm",
Properties: {
AlarmName: "HelloFunctionErrorAlarm",
AlarmDescription: "Alarm if lambda errors more than threshold",
Namespace: "AWS/Lambda",
MetricName: "Errors",
Dimensions: [
{
Name: "FunctionName",
Value: hello.name,
},
],
Statistic: "Sum",
ComparisonOperator: "GreaterThanThreshold",
Threshold: 0,
EvaluationPeriods: 5,
Period: 60,
TreatMissingData: "breaching",
},
},
};
}
return {};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment