-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_function.py
70 lines (48 loc) · 1.92 KB
/
lambda_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import json
import requests
from os import environ
def slack_alert(repo_name, findings):
h = {"Content-Type": "application/json"}
if len(findings) > 0:
m = {
"channel": environ['SLACK_CHANNEL'],
"icon_emoji": environ['SLACK_EMOJI'],
"username": environ['SLACK_USERNAME'],
"attachments": [{
"title": "ECR Scan Findings",
"color": "danger",
"fallback": f"ECR scan found issues in {repo_name}",
"text": f"ECR scan found {findings['CRITICAL']} CRITICAL and {findings['WARNING']} WARNING security issues in {repo_name}"
}]
}
requests.post(environ['SLACK_WEBHOOK'], data=json.dumps(m), headers=h)
else:
m = {
"channel": environ['SLACK_CHANNEL'],
"icon_emoji": environ['SLACK_EMOJI'],
"username": environ['SLACK_USERNAME'],
"attachments": [{
"title": "ECR Scan Findings",
"color": "good",
"fallback": f"ECR scan found issues in {repo_name}",
"text": f"ECR scan found no security issues in {repo_name}"
}]
}
requests.post(environ['SLACK_WEBHOOK'], data=json.dumps(m), headers=h)
return "Ok"
def lambda_handler(event, context):
findings_json = {}
repo = event['detail']['repository-name']
if event['detail']['scan-status'] != "COMPLETE":
print(f"Scan status {event['detail']['scan-status']}")
return "Ok"
findings = event['detail'].get('finding-severity-counts')
if findings is None:
print("No findings")
pass
else:
if findings.get("CRITICAL") is not None:
findings_json['CRITICAL'] = findings.get("CRITICAL")
if findings.get("MEDIUM") is not None:
findings_json['CRITICAL'] = findings.get("CRITICAL")
slack_alert(repo, findings_json)