-
Notifications
You must be signed in to change notification settings - Fork 3
/
serverless.yml
106 lines (95 loc) · 2.64 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
service: kinesis-autoscaler
custom:
scaleUpTopicName: ${self:service}-scale-up-${self:provider.stage}
scaleDownTopicName: ${self:service}-scale-down-${self:provider.stage}
autoscalerLogsTableName: ${self:service}-logs-${self:provider.stage}
provider:
name: aws
runtime: python3.9
region: ${opt:region, 'us-east-1'}
stage: ${opt:stage, 'dev'}
memorySize: 1024
timeout: 30
environment:
STAGE: ${self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- kinesis:UpdateShardCount
- kinesis:DescribeStreamSummary
Resource: '*'
- Effect: Allow
Action:
- cloudwatch:DescribeAlarms
- cloudwatch:PutMetricAlarm
- cloudwatch:SetAlarmState
- cloudwatch:GetMetricData
Resource: '*'
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:DescribeTable
Resource:
- Fn::GetAtt:
- AutoscalerLogsTable
- Arn
functions:
scale-up:
description: 'Scales up Kinesis data stream'
handler: handler.scale_up
events:
- sns:
arn:
Ref: ScaleUpTopic
topicName: ${self:custom.scaleUpTopicName}
scale-down:
description: 'Scales down Kinesis data stream'
handler: handler.scale_down
events:
- sns:
arn:
Ref: ScaleDownTopic
topicName: ${self:custom.scaleDownTopicName}
resources:
Resources:
ScaleUpTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: ${self:custom.scaleUpTopicName}
TopicName: ${self:custom.scaleUpTopicName}
ScaleDownTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: ${self:custom.scaleDownTopicName}
TopicName: ${self:custom.scaleDownTopicName}
AutoscalerLogsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.autoscalerLogsTableName}
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: stream_name
AttributeType: S
- AttributeName: scaling_datetime
AttributeType: S
KeySchema:
- AttributeName: stream_name
KeyType: HASH
- AttributeName: scaling_datetime
KeyType: RANGE
TimeToLiveSpecification:
AttributeName: expiration_datetime
Enabled: true
Outputs:
ScaleUpTopicArn:
Value:
Ref: ScaleUpTopic
Export:
Name: ScaleUpTopicArn-${self:provider.stage}
ScaleDownTopicArn:
Value:
Ref: ScaleDownTopic
Export:
Name: ScaleDownTopicArn-${self:provider.stage}
plugins:
- serverless-python-requirements