-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
155 lines (148 loc) · 5.13 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
service: sentiment-analysis-serverless
plugins:
- serverless-bundle
- serverless-pseudo-parameters
- serverless-step-functions
provider:
name: aws
runtime: nodejs12.x
memorySize: 256
stage: ${opt:stage, 'dev'}
region: us-east-1
environment:
CUSTOMER_FEEDBACK_TABLE: ${self:custom.CustomerFeedbackTable.name}
NUMBER_OF_RECORDS_TO_PROCESS: 10 #Max is 25 records, hard limit by AWS Comprehend batch
iamRoleStatements:
- Effect: "Allow"
Action:
- "*"
Resource:
- "*"
functions:
s3Trigger:
handler: src/handlers/s3Trigger.handler
environment:
stage: ${self:provider.stage}
statemachine_arn: arn:aws:states:#{AWS::Region}:#{AWS::AccountId}:stateMachine:hellostepfunc1
events:
- s3:
bucket: sentiment-analysis-serverless-source
event: s3:ObjectCreated:*
rules:
- suffix: .csv
readFeedback:
handler: src/handlers/readFeedback.handler
computeSentiment:
handler: src/handlers/computeSentiment.handler
iterator:
handler: src/handlers/iterator.handler
stepFunctions:
stateMachines:
hellostepfunc1:
name: "hellostepfunc1"
definition:
Comment: "Read CSV files and do sentiment analysis"
StartAt: ReadFeedbackFromS3
States:
ReadFeedbackFromS3:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-readFeedback"
Next: ProcessAllItems
ProcessAllItems:
Type: Parallel
InputPath: $
Branches:
- StartAt: ConfigureCountEN
States:
ConfigureCountEN:
Type: Pass
Parameters:
records.$: $.en
languageCode: "en"
ResultPath: $.iterator
Next: CurateData
CurateData:
Type: Pass
OutputPath: $.iterator
Next: IteratorEN
IteratorEN:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-iterator"
Next: IsCountReachedEN
IsCountReachedEN:
Type: Choice
Choices:
- Variable: $.continue
BooleanEquals: true
Next: ComputeSentimentEN
Default: DefaultStateEN
ComputeSentimentEN:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-computeSentiment"
ResultPath: $.result
Next: IteratorEN
DefaultStateEN:
Type: Pass
Parameters:
continue.$: $.continue
End: true
- StartAt: ConfigureCountES
States:
ConfigureCountES:
Type: Pass
Parameters:
records.$: $.es
languageCode: es
ResultPath: $.iterator
Next: CurateDataES
CurateDataES:
Type: Pass
OutputPath: $.iterator
Next: IteratorES
IteratorES:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-iterator"
Next: IsCountReachedES
IsCountReachedES:
Type: Choice
Choices:
- Variable: $.continue
BooleanEquals: true
Next: ComputeSentimentES
Default: DefaultStateES
ComputeSentimentES:
Type: Task
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-computeSentiment"
ResultPath: $.result
Next: IteratorES
DefaultStateES:
Type: Pass
Parameters:
continue.$: $.continue
End: true
End: true
resources:
Resources:
ProcessedBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: sentiment-analysis-serverless-destination
FeedbackDynamoDbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: FeedbackResultTable-${self:provider.stage}
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
custom:
CustomerFeedbackTable:
name: !Ref FeedbackDynamoDbTable
arn: !GetAtt FeedbackDynamoDbTable.Arn
bundle:
linting: false