-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
487 lines (469 loc) · 17.8 KB
/
template.yaml
File metadata and controls
487 lines (469 loc) · 17.8 KB
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Sets up lambda, api and base path mapping to fetch most recent publication for an author
Parameters:
CustomDomain:
Type: AWS::SSM::Parameter::Value<String>
Default: '/api/domainName'
Description: (Optional) Custom domain name for the API endpoint
CustomDomainBasePath:
Type: String
Default: 'ill'
Description: (Optional) Base path mapping in CustomDomain
AllowedPattern: "^[a-zA-Z0-9$\\-_.+!*'(),]*$"
ConstraintDescription: "May contain only letters, numbers and one of $-_.+!*'(),"
Stage:
Type: AWS::SSM::Parameter::Value<String>
Default: 'environment'
Description: dev/test/prod
PrimoServiceEndpoint:
Type: AWS::SSM::Parameter::Value<String>
Description: Url Endpoints to the Primo API
Default: '/primo/pnxServiceEndpoint'
PrimoServiceApiKey:
Type: String
Description: Api key for contacting the Primo API
Default: "{{resolve:secretsmanager:apiKeyPrimo:SecretString:apiKeyPrimo}}"
NoEcho: true
BaseBibliotekServiceEndpoint:
Type: AWS::SSM::Parameter::Value<String>
Description: Url Endpoint to the BaseBibliotek server
Default: '/nb/baseBibliotekEndpoint'
MaxConcurrency:
Type: Number
Default: 20
Description: Max number of provisioned hot instances for a lambda function
MinConcurrency:
Type: Number
Default: 1
MaxValue: 1
MinValue: 1
Description: Min number of provisioned hot instances for a lambda function
Conditions:
HasDomainName: !Not [!Equals [!Ref CustomDomain, '']]
HasCustomDomainBasePath: !Not [!Equals [!Ref CustomDomainBasePath, '']]
Globals:
Function:
Timeout: 20
# Architecures:
# - arm64
Api:
Cors:
AllowHeaders: '''Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'''
AllowMethods: '''OPTIONS, GET'''
AllowOrigin: '''*'''
EndpointConfiguration: REGIONAL
Resources:
InterLibraryLoanMetadataApi:
Type: AWS::Serverless::Api
Metadata:
cfn_nag:
rules_to_suppress:
- id: W64
reason: "Skip access logging for artifacts bucket"
- id: W68
reason: "Skip encryption for artifacts bucket"
- id: W69
reason: "Skip bucket policy for artifacts bucket"
- id: W89
reason: "Lambda functions should be deployed inside a VPC"
- id: W92
reason: "Lambda functions should define ReservedConcurrentExecutions to reserve simultaneous executions"
Properties:
Name: !Sub "${AWS::StackName}"
StageName: v1
EndpointConfiguration:
Type: REGIONAL
MethodSettings:
- ResourcePath: /ncip
HttpMethod: POST
ThrottlingBurstLimit: 2
ThrottlingRateLimit: 2
- ResourcePath: /metadata
HttpMethod: GET
ThrottlingBurstLimit: 10
ThrottlingRateLimit: 10
- ResourcePath: /libcheck
HttpMethod: GET
ThrottlingBurstLimit: 10
ThrottlingRateLimit: 10
DefinitionBody:
openapi: 3.0.3
info:
title: Inter Library Loan Metadata API
version: '1.0'
x-amazon-apigateway-request-validators:
all:
validateRequestBody: true
validateRequestParameters: true
params-only:
validateRequestBody: false
validateRequestParameters: true
body-only:
validateRequestBody: true
validateRequestParameters: false
paths:
/metadata:
get:
summary: Get bibliographic metadata by document id
description: gets bibliographic metadata by document_id
consumes:
- application/json
produces:
- application/json
parameters:
- in: query
name: document_id
required: true
type: string
description: document_id
x-amazon-apigateway-request-validator : params-only
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetInterLibraryLoanMetadataRecordFunction.Arn}:live/invocations
responses: {}
httpMethod: POST
type: AWS_PROXY
responses:
'200':
description: inter library loan metadata
content:
application/json:
schema:
$ref: '#/components/schemas/getInterLibraryLoanRecordResponseBody'
'400':
description: Bad request.
content:
application/json:
schema:
title: 400 Bad request
type: object
properties:
error:
type: string
description: error message
'500':
description: Internal server error.
content:
application/json:
schema:
title: 500 internal server error
type: object
properties:
error:
type: string
description: error message
/ncip:
post:
summary: Ncip message to send
description: sends NCIP message to external ncip-server
consumes:
- application/json
produces:
- application/json
parameters:
- in: ncip
name: ncip
required: true
type: string
description: ncip message
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PostInterLibraryLoanNcipFunction.Arn}/invocations
responses: {}
httpMethod: POST
type: AWS_PROXY
responses:
'200':
description: inter library loan metadata
content:
application/json:
schema:
$ref: '#/components/schemas/putInterLibraryLoanNcipResponseBody'
'400':
description: Bad request.
content:
application/json:
schema:
title: 400 Bad request
type: object
properties:
error:
type: string
description: error message
'500':
description: Internal server error.
content:
application/json:
schema:
title: 500 internal server error
type: object
properties:
error:
type: string
description: error message
/libcheck:
get:
summary: Get library ncip and alma status
description: Retrieves whether library has ncip server and/or is alma library
consumes:
- application/json
produces:
- application/json
parameters:
- in: query
name: libuser
required: true
type: string
description: libuser
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetInterLibraryLoanLibcheckFunction.Arn}/invocations
responses: {}
httpMethod: POST
type: AWS_PROXY
responses:
'200':
description: Library ncip and alma status
content:
application/json:
schema:
$ref: '#/components/schemas/getInterLibraryLoanLibcheckResponseBody'
'400':
description: Bad request.
content:
application/json:
schema:
title: 400 Bad request
type: object
properties:
error:
type: string
description: error message
'500':
description: Internal server error.
content:
application/json:
schema:
title: 500 internal server error
type: object
properties:
error:
type: string
description: error message
components:
schemas:
getInterLibraryLoanRecordResponseBody:
title: inter library loan metadata record
type: object
properties:
title:
type: string
description: bibliographic record containing metadata
postInterLibraryLoanNcipResponseBody:
title: inter library loan ncip response
type: object
properties:
title:
type: string
description: response message from ncip-server
getInterLibraryLoanLibcheckResponseBody:
title: Inter library loan library check
type: object
properties:
isAlmaLibrary:
type: boolean
description: Library is Alma library
isNcipLibrary:
type: boolean
description: Library has NCIP server
GetInterLibraryLoanMetadataRecordFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
Environment:
Variables:
ALLOWED_ORIGIN: '*'
STAGE: !Ref Stage
BASEBIBLIOTEKSERVICE_ENDPOINT: !Ref BaseBibliotekServiceEndpoint
PRIMO_SERVICE_ENDPOINT: !Ref PrimoServiceEndpoint
PRIMO_SERVICE_API: !Ref PrimoServiceApiKey
Handler: no.unit.MetadataHandler::handleRequest
Runtime: java17
MemorySize: 2048
AutoPublishAlias: live
DeploymentPreference:
Type: AllAtOnce # Or Canary10Percent5Minutes, Linear10PercentEvery1Minute, ...
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: 1
Events:
GetInterLibraryLoanMetadataRecordEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref InterLibraryLoanMetadataApi
Method: get
Path: /metadata
Timeout: 60
PostInterLibraryLoanNcipFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
Environment:
Variables:
ALLOWED_ORIGIN: '*'
Handler: no.unit.ncip.NcipHandler::handleRequest
Runtime: java17
MemorySize: 1024
Events:
PutEvent:
Type: Api
Properties:
RestApiId: !Ref InterLibraryLoanMetadataApi
Method: post
Path: /ncip
GetInterLibraryLoanLibcheckFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
Environment:
Variables:
ALLOWED_ORIGIN: '*'
BASEBIBLIOTEKSERVICE_ENDPOINT: !Ref BaseBibliotekServiceEndpoint
Handler: no.unit.libcheck.LibcheckHandler::handleRequest
Runtime: java17
MemorySize: 1024
Events:
GetInterLibraryLoanLibcheckEvent:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref InterLibraryLoanMetadataApi
Method: get
Path: /libcheck
PostInterLibraryLoanNcipFunctionAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: !Sub "PostInterLibraryLoanNcipFunctionAlarm-${AWS::StackName}"
AlarmDescription: 'Alot of invocations (NCIP requests) alarm. Take action (disable lambda) if not "real" requests.'
Namespace: AWS/Lambda
Dimensions:
- Name: FunctionName
Value: !Ref PostInterLibraryLoanNcipFunction
MetricName: Invocations
Statistic: Sum
Period: 600 #10 minutes
EvaluationPeriods: 1
Threshold: 100
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref PostInterLibraryLoanNcipFunctionAlarmNotification
PostInterLibraryLoanNcipFunctionAlarmNotification:
Type: AWS::SNS::Topic
Properties:
TopicName: !Sub "PostInterLibraryLoanNcipFunctionAlarmNotification-${AWS::StackName}"
GetInterLibraryLoanMetadataRecordFunctionScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: !Ref MaxConcurrency
MinCapacity: !Ref MinConcurrency
ResourceId: !Sub function:${GetInterLibraryLoanMetadataRecordFunction}:live # You need to specify an alis or version here
RoleARN: !Sub arn:aws:iam::${AWS::AccountId}:role/aws-service-role/lambda.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_LambdaConcurrency
ScalableDimension: lambda:function:ProvisionedConcurrency
ServiceNamespace: lambda
DependsOn: GetInterLibraryLoanMetadataRecordFunctionAliaslive # This is your function logical ID + "Alias" + what you use for AutoPublishAlias
GetInterLibraryLoanMetadataRecordFunctionScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: GetInterLibraryLoanMetadataRecordFunctionScalingPolicy
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref GetInterLibraryLoanMetadataRecordFunctionScalableTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 0.70 # Any value between 0.1 and 0.9 can be used here
PredefinedMetricSpecification:
PredefinedMetricType: LambdaProvisionedConcurrencyUtilization
CloudWatchEventRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- !Sub lambda.amazonaws.com
- !Sub events.amazonaws.com
Action: "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: CloudWatchEventPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- "lambda:InvokeFunction"
Resource: "*"
CWEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: "Description"
Name: "CWEventRule"
ScheduleExpression: "cron(0/5 6-16 ? * MON-SAT *)"
State: "ENABLED"
RoleArn: !GetAtt [ CloudWatchEventRole, Arn ]
Targets:
-
Arn:
Fn::Join:
- ""
- - !GetAtt GetInterLibraryLoanMetadataRecordFunction.Arn
- ":live"
Id: "GetInterLibraryLoanMetadataRecordFunction"
Input: '{"queryStringParameters": {"healthcheck":"healthcheck"}}'
-
Arn: !GetAtt GetInterLibraryLoanLibcheckFunction.Arn
Id: "GetInterLibraryLoanLibcheckFunction"
Input: '{"queryStringParameters": {"healthcheck":"healthcheck"}}'
PermissionForEventsToInvokeMetadataFunction:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Fn::Join:
- ""
- - !GetAtt GetInterLibraryLoanMetadataRecordFunction.Arn
- ":live"
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::GetAtt:
- "CWEventRule"
- "Arn"
PermissionForEventsToInvokeLibcheckFunction:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt GetInterLibraryLoanLibcheckFunction.Arn
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::GetAtt:
- "CWEventRule"
- "Arn"
InterLibraryLoanMetadataBasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Condition: HasDomainName
Properties:
BasePath: !If
- HasCustomDomainBasePath
- !Ref CustomDomainBasePath
- !Ref 'AWS::NoValue'
DomainName: !Ref CustomDomain
RestApiId: !Ref InterLibraryLoanMetadataApi
Stage: !Ref InterLibraryLoanMetadataApi.Stage
openapi:
info:
paths:
Outputs:
ApiEndpoint:
Description: "Endpoint base URL for the API"
Value: !If
- HasDomainName
- !Sub "https://${CustomDomain}/${CustomDomainBasePath}"
- !Sub "https://${InterLibraryLoanMetadataApi}.execute-api.${AWS::Region}.amazonaws.com/${InterLibraryLoanMetadataApi.Stage}/"