-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
165 lines (153 loc) · 3.63 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
---
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
SAM template for shiftboard-bot
Parameters:
AppName:
Type: String
Default: shiftboard-bot
Env:
Type: String
AllowedValues:
- dev
- test
- prod
TableName:
Type: String
Default: shiftboard-bot
SSMAPIParameterPath:
Type: String
Default: "shiftboard/api"
SSMNotificationsParameterPath:
Type: String
Default: "shiftboard/notifications"
Globals:
Function:
Timeout: 10
Runtime: go1.x
MemorySize: 128
Tags:
app:
Ref: AppName
env:
Ref: Env
Resources:
DatabaseTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: ID
AttributeType: S
BillingMode: PROVISIONED
KeySchema:
- AttributeName: ID
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 10
WriteCapacityUnits: 10
Tags:
- Key: app
Value:
Ref: AppName
- Key: env
Value:
Ref: Env
TableName:
Ref: TableName
TimeToLiveSpecification:
AttributeName: TTL
Enabled: true
RetrieverFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/retriever
Environment:
Variables:
WORKER_FUNCTION:
Ref: WorkerFunction
NOTIFICATION_FUNCTION:
Ref: NotificationFunction
Handler: retriever
MemorySize: 128
Architectures:
- x86_64
Policies:
- LambdaInvokePolicy:
FunctionName:
Ref: NotificationFunction
- LambdaInvokePolicy:
FunctionName:
Ref: WorkerFunction
- SSMParameterReadPolicy:
ParameterName:
Ref: SSMAPIParameterPath
WorkerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/worker
Environment:
Variables:
TABLE_NAME:
Ref: TableName
NOTIFICATION_FUNCTION:
Ref: NotificationFunction
Handler: worker
Architectures:
- x86_64
Policies:
- DynamoDBCrudPolicy:
TableName:
Ref: DatabaseTable
- LambdaInvokePolicy:
FunctionName:
Ref: NotificationFunction
NotificationFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/notification
Handler: notification
MemorySize: 128
Architectures:
- x86_64
Policies:
- SESCrudPolicy:
IdentityName: "*"
- SSMParameterReadPolicy:
ParameterName:
Ref: SSMNotificationsParameterPath
RetrieverFunctionSchedule:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: "rate(1 hour)"
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- RetrieverFunction
- Arn
Id: RetrieverFunctionV1
RetrieverInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: RetrieverFunction
Action: "lambda:InvokeFunction"
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- RetrieverFunctionSchedule
- Arn
Outputs:
RetrieverFunctionName:
Description: Retriever function name
Value:
Ref: RetrieverFunction
WorkerFunctionName:
Description: Worker function name
Value:
Ref: WorkerFunction
NotificationFunctionName:
Description: Notification function name
Value:
Ref: NotificationFunction