-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.yaml
68 lines (60 loc) · 2.25 KB
/
template.yaml
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
# To deploy with SAM:
# download and install sam: https://github.com/awslabs/aws-sam-cli
# sam package --template-file template.yaml --s3-bucket your-s3-bucket --output-template sam-output.yaml
# sam deploy --template-file sam-output.yaml --stack-name WatchSecurityGroup --capabilities CAPABILITY_IAM
# To test locally: (make sure to modifify the "groupId" with a real security group, add your webhook into vars.json)
# sam local invoke -e events/event_iam.json WatchSecurityGroupFunction -n vars.json
Transform: AWS::Serverless-2016-10-31
Description: Lambda function to watch EC2 Security Group Events to Send to Teams/Slack
Parameters:
WebHook:
Description: MS Teams Webhook
Type: String
Default: https://outlook.office.com/webhook/your/webhook/etc
WebHookSlack:
Description: Slack Webhook
Type: String
Default: https://hooks.slack.com/services/your/webhook/slack
Resources:
# Lambda Function
WatchSecurityGroupFunction:
Type: AWS::Serverless::Function
Properties:
Handler: watch-security-group.lambda_handler
Timeout: 10
Tracing: Active
MemorySize: 128
Runtime: python3.6
CodeUri: ./source/
Description: Detects EC2 Security Group Events to Send to Teams/Slack
Policies:
- AWSLambdaVPCAccessExecutionRole
- CloudWatchLogsFullAccess
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- ec2:DescribeSecurityGroupReferences
- ec2:DescribeSecurityGroups
- ec2:DescribeStaleSecurityGroups
Resource: '*'
Events:
WatchSecurityGroupRule:
Type: CloudWatchEvent
Description: Detects EC2 Security Group Events to Send to Teams/Slack
Properties:
Pattern:
source:
- "aws.ec2"
detail-type:
- "AWS API Call via CloudTrail"
detail:
eventSource:
- "ec2.amazonaws.com"
eventName:
- "AuthorizeSecurityGroupIngress"
- "RevokeSecurityGroupIngress"
Environment:
Variables:
TEAM_WEBHOOK: !Ref WebHook
SLACK_WEBHOOK: !Ref WebHookSlack