-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
157 lines (145 loc) · 5.01 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
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
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-kinesisfirehose-deliverystream.html
# https://serverlessland.com/patterns/kinesis-firehose-s3-sam-java
service: kds-kfslambda-test
frameworkVersion: "3"
provider:
name: aws
region: ${opt:region, 'us-west-1'}
stage: ${opt:stage, 'dev'}
environment:
NODE_ENV: ${opt:stage, 'dev'}
plugins:
- serverless-bundle
- serverless-iam-roles-per-function
- serverless-offline
custom:
common:
S3_JSON_DESTINATION_BUCKET_NAME: ${self:service}-bucket
S3_JSON_DESTINATION_BUCKET_REGION: ${self:provider.region}
functions:
transform:
handler: src/handler.preprocess
runtime: nodejs18.x
memorySize: 128
timeout: 300
logRetentionInDays: 1
resources:
Resources:
S3BucketForKinesisDestination:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.common.S3_JSON_DESTINATION_BUCKET_NAME}
DataStream:
Type: AWS::Kinesis::Stream
Properties:
Name: ${self:service}-kinesis
RetentionPeriodHours: 24
StreamModeDetails:
StreamMode: ON_DEMAND
# ShardCount: 3
Tags:
- Key: Environment
Value: ${self:provider.stage}
- Key: SLS_Service
Value: ${self:service}
DeliveryStreamRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
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:
PolicyName: ${self:service}-firehose_delivery_policy
Roles:
- !Ref DeliveryStreamRole
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "s3:AbortMultipartUpload"
- "s3:GetBucketLocation"
- "s3:GetObject"
- "s3:ListBucket"
- "s3:ListBucketMultipartUploads"
- "s3:PutObject"
Resource:
- !GetAtt S3BucketForKinesisDestination.Arn
- !Join
- ""
- - "arn:aws:s3:::"
- !Ref S3BucketForKinesisDestination
- "*"
- Effect: Allow
Action:
- "kinesis:DescribeStream"
- "kinesis:GetShardIterator"
- "kinesis:GetRecords"
- "kinesis:ListShards"
Resource:
- !GetAtt DataStream.Arn
KinesisInvokeLambdaPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: ${self:service}-kinesis-invoke-lambda-policy
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "lambda:InvokeFunction"
Resource:
- !GetAtt TransformLambdaFunction.Arn
Roles:
- !Ref DeliveryStreamRole
KinesisDeliveryStream:
Type: AWS::KinesisFirehose::DeliveryStream
DependsOn:
- DeliveryStreamPolicy
Properties:
DeliveryStreamName: ${self:service}-kinesis-delivery-stream
DeliveryStreamType: KinesisStreamAsSource
Tags:
- Key: Environment
Value: ${self:provider.stage}
- Key: SLS_Service
Value: ${self:service}
KinesisStreamSourceConfiguration:
KinesisStreamARN: !GetAtt DataStream.Arn
RoleARN: !GetAtt DeliveryStreamRole.Arn
ExtendedS3DestinationConfiguration:
BucketARN: !GetAtt S3BucketForKinesisDestination.Arn
BufferingHints:
SizeInMBs: 64 ## must be at least 64 when Dynamic Partitioning is enabled.
IntervalInSeconds: 60
CompressionFormat: ZIP #UNCOMPRESSED
ErrorOutputPrefix: firehose-error/!{firehose:error-output-type}/!{timestamp:yyyy'-'MM'-'dd}/
# Prefix: firehose-data/!{timestamp:yyyy'-'MM'-'dd}/
Prefix: firehose-data/!{partitionKeyFromQuery:email}/!{timestamp:yyyy'-'MM'-'dd}/ ## if enable DynamicPartitioning
RoleARN: !GetAtt DeliveryStreamRole.Arn
DynamicPartitioningConfiguration:
Enabled: true
ProcessingConfiguration:
Enabled: true
Processors:
- Type: MetadataExtraction
Parameters:
- ParameterName: MetadataExtractionQuery
ParameterValue: '{email : .email}'
- ParameterName: JsonParsingEngine
ParameterValue: JQ-1.6
- Type: AppendDelimiterToRecord
Parameters:
- ParameterName: Delimiter
ParameterValue: "\\n"
- Parameters:
- ParameterName: LambdaArn
ParameterValue: !GetAtt TransformLambdaFunction.Arn
Type: Lambda