-
Notifications
You must be signed in to change notification settings - Fork 0
/
digitization_tasks_template.yaml
250 lines (230 loc) · 7.97 KB
/
digitization_tasks_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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
AWSTemplateFormatVersion: '2010-09-09'
Description: >
digitization-tasks
Creates Asana tasks for new Aeon digitization transactions.
Parameters:
ApplicationEnvironment:
Type: String
Description: Environment in which the application should be deployed.
AllowedValues:
- dev
- prod
ApplicationName:
Type: String
Description: Name of the application to be deployed.
Default: digitization_tasks
AeonAccessToken:
Type: String
Description: Access token for Aeon.
AsanaAccessToken:
Type: String
Description: Access token for Asana.
Mappings:
Aeon:
BaseUrl:
dev: 'https://raccess.rockarch.org/aeonapi'
prod: 'https://raccess.rockarch.org/aeonapi'
PhotoduplicationStatus:
dev: 53
prod: 53
TransactionStatus:
dev: 8
prod: 8
BillingStatus:
dev: 21
prod: 21
Asana:
ProjectId:
dev: 1206971441441570
prod: 1206971441441570
UnclaimedSectionId:
dev: 1206971441441575
prod: 1206971441441575
BillingSectionId:
dev: 1207658380417124
prod: 1207658380417124
WorkspaceId:
dev: 4711715224923
prod: 4711715224923
Resources:
DigitizationTasksFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Description: !Sub 'Allows ${ApplicationName} lambda to be executed successfully.'
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: DigitizationTasksParameterStorePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'ssm:GetParametersByPath*'
- 'ssm:PutParameter'
Resource: !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${ApplicationEnvironment}/${ApplicationName}*'
AeonAccessTokenParam:
Type: AWS::SSM::Parameter
Properties:
Description: Access token for Aeon client.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/AEON_ACCESS_TOKEN
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !Ref AeonAccessToken
AeonBaseUrlParam:
Type: AWS::SSM::Parameter
Properties:
Description: Base URL for Aeon client.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/AEON_BASEURL
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Aeon, BaseUrl, !Ref ApplicationEnvironment]
AeonPhotoduplicationStatusCodeParam:
Type: AWS::SSM::Parameter
Properties:
Description: Photoduplication status code for new transactions.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/AEON_PHOTODUPLICATION_STATUS
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Aeon, PhotoduplicationStatus, !Ref ApplicationEnvironment]
AeonTransactionStatusCodeParam:
Type: AWS::SSM::Parameter
Properties:
Description: Transaction status code for new transactions.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/AEON_TRANSACTION_STATUS
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Aeon, TransactionStatus, !Ref ApplicationEnvironment]
AeonBillingStatusCodeParam:
Type: AWS::SSM::Parameter
Properties:
Description: Transaction status code for transactions awaiting payment.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/AEON_BILLING_STATUS
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Aeon, BillingStatus, !Ref ApplicationEnvironment]
AsanaAccessTokenParam:
Type: AWS::SSM::Parameter
Properties:
Description: Token for Asana client.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/ASANA_ACCESS_TOKEN
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !Ref AsanaAccessToken
AsanaProjectIdParam:
Type: AWS::SSM::Parameter
Properties:
Description: Asana project ID in which new tasks should be created.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/ASANA_PROJECT_ID
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Asana, ProjectId, !Ref ApplicationEnvironment]
AsanaUnclaimedSectionIdParam:
Type: AWS::SSM::Parameter
Properties:
Description: Asana section ID under which new tasks should be created.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/ASANA_UNCLAIMED_SECTION_ID
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Asana, UnclaimedSectionId, !Ref ApplicationEnvironment]
AsanaBillingSectionIdParam:
Type: AWS::SSM::Parameter
Properties:
Description: Asana section ID for tasks waiting to be billed.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/ASANA_BILLING_SECTION_ID
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Asana, BillingSectionId, !Ref ApplicationEnvironment]
AsanaWorkspaceIdParam:
Type: AWS::SSM::Parameter
Properties:
Description: Asana workspace ID.
Name: !Sub /${ApplicationEnvironment}/${ApplicationName}/ASANA_WORKSPACE_ID
Tags:
Environment: !Ref ApplicationEnvironment
Application: !Ref ApplicationName
Type: String
Value: !FindInMap [Asana, WorkspaceId, !Ref ApplicationEnvironment]
DigitizationTasksFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: !Sub 'rac-${ApplicationEnvironment}-lambda'
S3Key: !Sub '${ApplicationName}.zip'
FunctionName: !Ref ApplicationName
Handler: handle_new_digitization_transactions.main
Role: !GetAtt DigitizationTasksFunctionRole.Arn
Runtime: python3.11
Timeout: 270
Environment:
Variables:
ENV:
Ref: ApplicationEnvironment
APP_CONFIG_PATH:
Ref: ApplicationName
Architectures:
- x86_64
Tags:
- Key: Environment
Value: !Ref ApplicationEnvironment
- Key: Application
Value: !Ref ApplicationName
DigitizationTasksEventRule:
Type: AWS::Events::Rule
Properties:
Description: "Triggers every hour"
Name: every_hour
ScheduleExpression: "cron(0 12-22 ? * MON-FRI *)"
State: "ENABLED"
Targets:
- Arn: !GetAtt DigitizationTasksFunction.Arn
Id: "DigitizationTasks"
DigitizationTasksEventRulePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref DigitizationTasksFunction
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt DigitizationTasksEventRule.Arn
DigitizationTasksTravisEcRPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref DigitizationTasksFunction
Action: "lambda:UpdateFunctionCode"
Principal: "arn:aws:iam::817658541382:user/TravisECR"
DigitizationTasksLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${DigitizationTasksFunction}"
RetentionInDays: 90
Outputs:
DigitizedAvTriggerFunction:
Description: "Digitization Tasks Lambda Function ARN"
Value: !GetAtt DigitizationTasksFunction.Arn