-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserverless.yml
More file actions
156 lines (150 loc) · 4.14 KB
/
Copy pathserverless.yml
File metadata and controls
156 lines (150 loc) · 4.14 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
service: cw-telemetry
plugins:
- serverless-plugin-aws-alerts
- serverless-plugin-common-excludes
- serverless-plugin-include-dependencies
- serverless-prune-plugin
provider:
name: aws
runtime: nodejs20.x
environment:
LOG_LEVEL: ${opt:log-level, "info"}
logRetentionInDays: 30
iam:
role:
statements:
- Effect: Allow
Action:
- cloudwatch:PutMetricData
Resource: "*"
package:
patterns:
- '!coverage/**'
custom:
alerts:
nameTemplate: $[functionName]-$[metricName]
topics:
alarm: ${opt:alarmAction, ""}
insufficientData: ${opt:insufficientDataAction, ""}
ok: ${opt:okAction, ""}
definitions:
functionErrors:
threshold: 10
comparisonOperator: GreaterThanThreshold
functionErrorsConsistently:
namespace: AWS/Lambda
metric: Errors
nameTemplate: ${self:custom.alerts.nameTemplate}-Consistently
threshold: 0
statistic: Sum
period: 60
evaluationPeriods: 5
comparisonOperator: GreaterThanThreshold
functionIteratorAge:
namespace: AWS/Lambda
metric: IteratorAge
threshold: 300000 # 5 mins
statistic: Maximum
period: 60
evaluationPeriods: 1
comparisonOperator: GreaterThanThreshold
logErrors:
metric: LogErrors
threshold: 5
statistic: Sum
period: 60
evaluationPeriods: 1
comparisonOperator: GreaterThanThreshold
pattern: "{$.level > 40}"
logWarnings:
metric: LogWarnings
threshold: 0
statistic: Sum
period: 60
evaluationPeriods: 1
comparisonOperator: GreaterThanThreshold
pattern: "{$.level = 40}"
function:
- functionErrors
- functionErrorsConsistently
- functionIteratorAge
- logWarnings
- logErrors
namespace: ${self:service}-${self:custom.stage}
prune:
automatic: true
number: 3
region: ${opt:region, self:provider.region}
serviceRoleName: ${self:custom.namespace}-${self:custom.region}-role
stage: ${opt:stage, self:provider.stage}
functions:
datapointsProcessor:
handler: src/datapoints-processor.handler
memorySize: 512
timeout: 10
environment:
SUPPRESS_ERRORS: false
events:
- stream:
type: kinesis
startingPosition: TRIM_HORIZON
arn:
Fn::GetAtt:
- IngestionStream
- Arn
batchSize: ${opt:batchSize, "1000"}
resources:
Resources:
IngestionStream:
Type: AWS::Kinesis::Stream
Properties:
Name: ${self:custom.namespace}-ingestion-stream
RetentionPeriodHours: ${opt:retentionHours, "24"}
ShardCount: ${opt:shardCount, "1"}
ServiceRole:
Type: AWS::IAM::Role
Properties:
RoleName: ${self:custom.serviceRoleName}
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service:
- logs.${self:custom.region}.amazonaws.com
Policies:
- PolicyName: root
PolicyDocument:
Statement:
- Effect: Allow
Action: kinesis:PutRecord
Resource:
Fn::GetAtt:
- IngestionStream
- Arn
- Effect: Allow
Action: iam:PassRole
Resource:
Fn::Join:
- ":"
-
- "arn:aws:iam:"
- Ref: AWS::AccountId
- role/${self:custom.serviceRoleName}
Outputs:
IngestionStreamArn:
Description: The ARN for the Kinesis logs stream
Value:
Fn::GetAtt:
- IngestionStream
- Arn
Export:
Name: ${self:custom.namespace}-ingestion-stream-arn
ServiceRoleArn:
Description: The ARN for the IAM role
Value:
Fn::GetAtt:
- ServiceRole
- Arn
Export:
Name: ${self:custom.namespace}-service-role-arn