Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Run snyk tag monitor weekly #49

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions cdk/lib/__snapshots__/snyk-tag-monitor.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": [
Expand Down
50 changes: 26 additions & 24 deletions cdk/lib/snyk-tag-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@
new EmailSubscription('[email protected]'),
);

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);

Check warning on line 47 in cdk/lib/snyk-tag-monitor.ts

View workflow job for this annotation

GitHub Actions / CI

'tagAlarm' is assigned a value but never used

const lambdaProps: GuScheduledLambdaProps = {
rules: [{ schedule: Schedule.rate(Duration.days(1)) }],
rules: [{ schedule: Schedule.rate(Duration.days(7)) }],
monitoringConfiguration: {
toleratedErrorPercentage: 50,
snsTopicName: topic.topicName,
Expand All @@ -60,13 +60,15 @@
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);
}
}