-
Notifications
You must be signed in to change notification settings - Fork 20
/
template.yaml
182 lines (168 loc) · 5.28 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: AlleyCat - KDF example
# This template builds the Kinesis stream ARN from the base
# template using the following expression:
# !Sub "arn:aws:kinesis:${AWS::Region}:${AWS::AccountId}:stream/alleycat"
Parameters:
KinesisStreamName:
Type: String
Default: 'alleycat'
DeliveryBucketName:
Type: String
Default: 'alleycat-firehose-bucket'
HistoryBucketName:
Type: String
Default: 'alleycat-history-bucket'
DynamoDBtableName:
Type: String
Default: alleycat-races
Resources:
##########################################
# S3 Delivery Bucket #
##########################################
DeliveryBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref DeliveryBucketName
HistoryBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref HistoryBucketName
CorsConfiguration:
CorsRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- GET
- PUT
- POST
- DELETE
- HEAD
AllowedOrigins:
- "*"
##########################################
# Lambda functions #
##########################################
FirehoseProcessFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: transformer/
Handler: app.handler
Runtime: nodejs14.x
Timeout: 30
MemorySize: 256
S3ProcessorFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3-processor/
Handler: app.handler
Runtime: nodejs14.x
Timeout: 30
MemorySize: 1024
Environment:
Variables:
DDB_TABLE: !Ref DynamoDBtableName
HistoryBucket: !Ref HistoryBucketName
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref DynamoDBtableName
- S3ReadPolicy:
BucketName: !Ref DeliveryBucketName
- S3WritePolicy:
BucketName: !Ref HistoryBucketName
Events:
NewObjectEvent:
Type: S3
Properties:
Bucket: !Ref DeliveryBucket
Events: s3:ObjectCreated:*
##########################################
# Kinesis Data Firehose configuration #
##########################################
DeliveryStream:
Type: AWS::KinesisFirehose::DeliveryStream
DependsOn:
- DeliveryStreamPolicy
Properties:
DeliveryStreamName: "alleycat-data-firehose"
DeliveryStreamType: "KinesisStreamAsSource"
KinesisStreamSourceConfiguration:
KinesisStreamARN: !Sub "arn:aws:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${KinesisStreamName}"
RoleARN: !GetAtt DeliveryStreamRole.Arn
ExtendedS3DestinationConfiguration:
BucketARN: !GetAtt DeliveryBucket.Arn
BufferingHints:
SizeInMBs: 1
IntervalInSeconds: 60
CloudWatchLoggingOptions:
Enabled: true
LogGroupName: "/aws/kinesisfirehose/alleycat-firehose"
LogStreamName: "S3Delivery"
CompressionFormat: "GZIP"
EncryptionConfiguration:
NoEncryptionConfig: "NoEncryption"
Prefix: ""
RoleARN: !GetAtt DeliveryStreamRole.Arn
ProcessingConfiguration:
Enabled: true
Processors:
- Type: "Lambda"
Parameters:
- ParameterName: "LambdaArn"
ParameterValue: !GetAtt FirehoseProcessFunction.Arn
##########################################
# IAM roles and policies #
##########################################
DeliveryStreamRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: firehose.amazonaws.com
Action: 'sts:AssumeRole'
Condition:
StringEquals:
'sts:ExternalId': !Ref 'AWS::AccountId'
DeliveryStreamPolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- !Ref DeliveryStreamRole
PolicyName: firehose_delivery_policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 's3:AbortMultipartUpload'
- 's3:GetBucketLocation'
- 's3:GetObject'
- 's3:ListBucket'
- 's3:ListBucketMultipartUploads'
- 's3:PutObject'
Resource:
- !GetAtt DeliveryBucket.Arn
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref DeliveryBucket
- '*'
- Effect: Allow
Action:
- 'lambda:InvokeFunction'
- 'lambda:GetFunctionConfiguration'
Resource:
- !GetAtt FirehoseProcessFunction.Arn
- Effect: Allow
Action:
- 'kinesis:DescribeStream'
- 'kinesis:GetShardIterator'
- 'kinesis:GetRecords'
- 'kinesis:ListShards'
Resource:
- !Sub 'arn:aws:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${KinesisStreamName}'