Skip to content

Commit

Permalink
feat!: support adding tags for alarms (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
LironEr authored Apr 16, 2024
1 parent bd50afa commit a898839
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ custom:
nameTemplate: $[functionName]-$[metricName]-alarm # Optional - naming template for alarms, can be overwritten in definitions
prefixTemplate: $[stackName] # Optional - override the alarm name prefix
suffixTemplate: alarm # Optional - override the alarm name suffix
tags:
TEAM: my-team

definitions: # these defaults are merged with your definitions
lambdaErrors:
Expand Down
9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
comment: false

coverage:
status:
patch: off
project:
default:
only_pulls: true
target: auto
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface AlarmDefinition {
insufficientDataActions?: string[];
treatMissingData?: string;
metricFilter?: AlarmMetricFilterDefinition;
tags?: Record<string, string | null>;
}

// Can be string (arn) or object (!Ref/!Sub...) or an array of those
Expand Down
9 changes: 9 additions & 0 deletions src/utils/alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ export function generateCloudFormationResourcesForDefinition(
TreatMissingData: alarm.treatMissingData,
};

if (alarm.tags && Object.keys(alarm.tags).length > 0) {
cfAlarmProperties.Tags = Object.entries(alarm.tags)
.map(([key, value]) => ({
Key: key,
Value: value,
}))
.filter((tag) => !!tag.Value);
}

resources[
awsNaming.getNormalizedResourceName(`${lambdaLogicalId}${awsNaming.normalizeName(alarmDefinitionName)}Alarm`)
] = {
Expand Down
1 change: 1 addition & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const alarmDefSchema = z.object({
insufficientDataActions: z.array(z.string()).optional(),
treatMissingData: z.optional(z.enum(['missing', 'ignore', 'breaching', 'notBreaching'])),
metricFilter: z.optional(alarmMetricFilterDefSchema),
tags: z.optional(z.record(z.string().min(1).max(128), z.string().min(1).max(256).nullable())),
}) satisfies z.ZodType<AlarmDefinition>;

const alarmActionSchema = z.union([
Expand Down

0 comments on commit a898839

Please sign in to comment.