From edbebc8c3a83e8fb98eee46c8e4293dbac0aad7d Mon Sep 17 00:00:00 2001 From: Natasha <67543397+NovemberTang@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:42:03 +0000 Subject: [PATCH 1/2] only run once a week --- .../snyk-tag-monitor.test.ts.snap | 40 +++++++++---------- cdk/lib/snyk-tag-monitor.ts | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cdk/lib/__snapshots__/snyk-tag-monitor.test.ts.snap b/cdk/lib/__snapshots__/snyk-tag-monitor.test.ts.snap index 0be96ba..19d25bc 100644 --- a/cdk/lib/__snapshots__/snyk-tag-monitor.test.ts.snap +++ b/cdk/lib/__snapshots__/snyk-tag-monitor.test.ts.snap @@ -408,7 +408,25 @@ exports[`The SnykTagMonitor stack matches the snapshot 1`] = ` }, "Type": "AWS::CloudWatch::Alarm", }, - "snyktagmonitorsnyktagmonitorrate1day0AllowEventRuleSnykTagMonitorsnyktagmonitorAE4097CFB7932521": { + "snyktagmonitorsnyktagmonitorrate7days06190F24C": { + "Properties": { + "ScheduleExpression": "rate(7 days)", + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "snyktagmonitor01C2294D", + "Arn", + ], + }, + "Id": "Target0", + }, + ], + }, + "Type": "AWS::Events::Rule", + }, + "snyktagmonitorsnyktagmonitorrate7days0AllowEventRuleSnykTagMonitorsnyktagmonitorAE4097CF885D65C7": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -420,31 +438,13 @@ exports[`The SnykTagMonitor stack matches the snapshot 1`] = ` "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "snyktagmonitorsnyktagmonitorrate1day0D20FBF83", + "snyktagmonitorsnyktagmonitorrate7days06190F24C", "Arn", ], }, }, "Type": "AWS::Lambda::Permission", }, - "snyktagmonitorsnyktagmonitorrate1day0D20FBF83": { - "Properties": { - "ScheduleExpression": "rate(1 day)", - "State": "ENABLED", - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "snyktagmonitor01C2294D", - "Arn", - ], - }, - "Id": "Target0", - }, - ], - }, - "Type": "AWS::Events::Rule", - }, "snyktagmonitortopicF2FA58D7": { "Properties": { "Tags": [ diff --git a/cdk/lib/snyk-tag-monitor.ts b/cdk/lib/snyk-tag-monitor.ts index 9ae3e74..ca9321f 100644 --- a/cdk/lib/snyk-tag-monitor.ts +++ b/cdk/lib/snyk-tag-monitor.ts @@ -47,7 +47,7 @@ export class SnykTagMonitor extends GuStack { const tagAlarm = new GuAlarm(this, `${app}-alarm`, tagAlarmProps) const lambdaProps: GuScheduledLambdaProps = { - rules: [{ schedule: Schedule.rate(Duration.days(1)) }], + rules: [{ schedule: Schedule.rate(Duration.days(7)) }], monitoringConfiguration: { toleratedErrorPercentage: 50, snsTopicName: topic.topicName, From 7a5cc814c77287099e1de2fbe7d88995bec33555 Mon Sep 17 00:00:00 2001 From: Natasha <67543397+NovemberTang@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:42:19 +0000 Subject: [PATCH 2/2] formatting --- cdk/lib/snyk-tag-monitor.ts | 48 +++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/cdk/lib/snyk-tag-monitor.ts b/cdk/lib/snyk-tag-monitor.ts index ca9321f..ec21bd2 100644 --- a/cdk/lib/snyk-tag-monitor.ts +++ b/cdk/lib/snyk-tag-monitor.ts @@ -25,26 +25,26 @@ export class SnykTagMonitor extends GuStack { new EmailSubscription('devx.security@guardian.co.uk'), ); - const metricProps: MetricProps = { - namespace: 'snyk-tag-monitor', - metricName: 'snykTagCount', - dimensionsMap: { - 'stage': this.stage - }, - period: Duration.days(1), - statistic: "Minimum" - } - const tagMetric = new Metric(metricProps) + const metricProps: MetricProps = { + namespace: 'snyk-tag-monitor', + metricName: 'snykTagCount', + dimensionsMap: { + stage: this.stage, + }, + period: Duration.days(1), + statistic: 'Minimum', + }; + const tagMetric = new Metric(metricProps); - const tagAlarmProps: GuAlarmProps = { - comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD, - threshold: 4500, - evaluationPeriods: 1, - snsTopicName: topic.topicName, - metric: tagMetric, - app: app, - } - const tagAlarm = new GuAlarm(this, `${app}-alarm`, tagAlarmProps) + const tagAlarmProps: GuAlarmProps = { + comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD, + threshold: 4500, + evaluationPeriods: 1, + snsTopicName: topic.topicName, + metric: tagMetric, + app: app, + }; + const tagAlarm = new GuAlarm(this, `${app}-alarm`, tagAlarmProps); const lambdaProps: GuScheduledLambdaProps = { rules: [{ schedule: Schedule.rate(Duration.days(7)) }], @@ -60,13 +60,15 @@ export class SnykTagMonitor extends GuStack { SNS_TOPIC_ARN: topic.topicArn, }, timeout: Duration.minutes(5), - retryAttempts: 1 + retryAttempts: 1, }; const lambda = new GuScheduledLambda(this, app, lambdaProps); topic.grantPublish(lambda); - const policyStatement = new PolicyStatement({actions: ['cloudwatch:PutMetricData'], resources: ['*']}) - lambda.addToRolePolicy(policyStatement) - + const policyStatement = new PolicyStatement({ + actions: ['cloudwatch:PutMetricData'], + resources: ['*'], + }); + lambda.addToRolePolicy(policyStatement); } }