-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverless.yml
134 lines (125 loc) · 3.91 KB
/
serverless.yml
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
service: tags-monitorization
provider:
name: aws
runtime: python3.8
region: ${opt:region, 'us-east-1'}
stage: ${self:custom.currentStage}
stackTags:
app: "tags-monitorization"
environment: "Producción"
project: "tags-monitorization"
plugins:
- serverless-python-requirements
custom:
currentStage: ${opt:stage, 'dev'}
notificationEmail: "testuser1@domaintest.com,testuser2@domaintest.com"
senderEmail: "noreply@domaintest.com"
subject: "Untagged resources Apside report"
bucketName: "tags-monitorization-bucket"
reportCron: "cron(0 13 ? * MON,WED *)"
customTags: "app,environment,project"
pythonRequirements:
dockerizePip: true
functions:
extractor:
handler: handler.monitorization
environment:
S3_BUCKET: !Ref costsS3Bucket
SENDER: ${self:custom.senderEmail}
RECIPIENT: ${self:custom.notificationEmail}
SUBJECT: ${self:custom.subject}
BODY_TEXT: ${file(./emailText.txt)}
BODY_HTML: ${file(./emailHtml.html)}
TAGS: ${self:custom.customTags}
events:
- schedule:
name: tagsMonitorizationCronRule
rate: ${self:custom.reportCron}
enabled: true
role: lambdaBucketRole
resources:
Resources:
costsS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.bucketName}
LifecycleConfiguration:
Rules:
- Id: "${self:custom.bucketName}-ExpirationRule"
ExpirationInDays: 180
Status: 'Enabled'
Prefix: ''
Transitions:
- TransitionInDays: 31
StorageClass: 'ONEZONE_IA'
CorsConfiguration:
CorsRules:
- AllowedOrigins:
- '*'
AllowedHeaders:
- '*'
AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
MaxAge: 3000
lambdaBucketRole:
Type: AWS::IAM::Role
Properties:
RoleName: lambdaBucketTagsMonitorizationRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: lambdaBucketTagsMonitorizationPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- 'Fn::Join':
- ':'
- - 'arn:aws:logs'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'log-group:/aws/lambda/*:*:*'
- Effect: Allow
Action:
- "s3:PutObject"
- "s3:GetObject"
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::"
- "Ref" : "costsS3Bucket"
- "/*"
- Effect: Allow
Action:
- "s3:ListBucket"
Resource:
Fn::Join:
- ""
- - "arn:aws:s3:::"
- "Ref" : "costsS3Bucket"
- Effect: Allow
Action:
- "SES:SendEmail"
- "SES:SendRawEmail"
Resource:
Fn::Join:
- ':'
- - 'arn:aws:ses'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'identity/${self:custom.senderEmail}'