-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.yml
110 lines (110 loc) · 3.61 KB
/
module.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
---
# Copyright 2018 widdix GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Description: 'cfn-modules: AWS Kinesis data stream'
# cfn-modules:implements(ExposeArn, ExposeName, LambdaDependency)
Parameters:
AlertingModule:
Description: 'Optional but recommended stack name of alerting module.'
Type: String
Default: ''
KmsKeyModule:
Description: 'Optional but recommended stack name of kms-key module.'
Type: String
Default: ''
RetentionPeriodHours:
Description: 'The number of hours for the data records that are stored in shards to remain accessible.'
Type: Number
Default: 24
MinValue: 24
MaxValue: 168
ShardCount:
Description: 'The number of shards that the stream uses.'
Type: Number
Default: 1
MinValue: 1
Conditions:
HasAlertingModule: !Not [!Equals [!Ref AlertingModule, '']]
HasKmsKeyModule: !Not [!Equals [!Ref KmsKeyModule, '']]
Resources:
Stream:
Type: 'AWS::Kinesis::Stream'
Properties:
RetentionPeriodHours: !Ref RetentionPeriodHours
ShardCount: !Ref ShardCount
StreamEncryption: !If [HasKmsKeyModule, {EncryptionType: KMS, KeyId: {'Fn::ImportValue': !Sub '${KmsKeyModule}-Arn'}}, !Ref 'AWS::NoValue']
StreamReadProvisionedThroughputExceededAlarm:
Condition: HasAlertingModule
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- 'Fn::ImportValue': !Sub '${AlertingModule}-Arn'
AlarmDescription: 'stream read provisioned throughput exceeded'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: StreamName
Value: !Ref Stream
EvaluationPeriods: 1
MetricName: ReadProvisionedThroughputExceeded
Namespace: 'AWS/Kinesis'
OKActions:
- 'Fn::ImportValue': !Sub '${AlertingModule}-Arn'
Period: 300
Statistic: Sum
Threshold: 0
TreatMissingData: notBreaching
StreamWriteProvisionedThroughputExceededAlarm:
Condition: HasAlertingModule
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
- 'Fn::ImportValue': !Sub '${AlertingModule}-Arn'
AlarmDescription: 'stream write provisioned throughput exceeded'
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: StreamName
Value: !Ref Stream
EvaluationPeriods: 1
MetricName: WriteProvisionedThroughputExceeded
Namespace: 'AWS/Kinesis'
OKActions:
- 'Fn::ImportValue': !Sub '${AlertingModule}-Arn'
Period: 300
Statistic: Sum
Threshold: 0
TreatMissingData: notBreaching
Outputs:
ModuleId:
Value: 'kinesis-data-stream'
ModuleVersion:
Value: '0.1.0'
StackName:
Value: !Ref 'AWS::StackName'
Arn:
Value: !GetAtt 'Stream.Arn'
Export:
Name: !Sub '${AWS::StackName}-Arn'
IamActions:
Value: 'kinesis:GetRecords,kinesis:GetShardIterator,kinesis:PutRecord,kinesis:PutRecords'
Export:
Name: !Sub '${AWS::StackName}-IamActions'
IamResources:
Value: !GetAtt 'Stream.Arn'
Export:
Name: !Sub '${AWS::StackName}-IamResources'
Name:
Value: !Ref Stream
Export:
Name: !Sub '${AWS::StackName}-Name'