-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
178 lines (169 loc) · 6.28 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
166
167
168
169
170
171
172
173
174
175
176
177
178
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: 'alma'
Description: (Optional) Base path mapping in CustomDomain
AllowedPattern: "^[a-zA-Z0-9$\\-_.+!*'(),]*$"
ConstraintDescription: "May contain only letters, numbers and one of $-_.+!*'(),"
SruEndpoint:
Type: AWS::SSM::Parameter::Value<String>
Default: '/alma/sruEndpoint'
Description: Url Endpoint to the SRU server
Conditions:
HasDomainName: !Not [!Equals [!Ref CustomDomain, '']]
HasCustomDomainBasePath: !Not [!Equals [!Ref CustomDomainBasePath, '']]
Globals:
Function:
Timeout: 20
Runtime: java17
Api:
Cors:
AllowHeaders: '''Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'''
AllowMethods: '''OPTIONS, GET'''
AllowOrigin: '''*'''
EndpointConfiguration: REGIONAL
OpenApiVersion: 3.0.3
Resources:
AlmaSruProxyAccessLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 180
AlmaSruProxyApi:
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
AccessLogSetting:
DestinationArn: !GetAtt AlmaSruProxyAccessLogGroup.Arn
Format: '{ "apiId": "$context.apiId", "requestId": "$context.requestId", "requestTime": "$context.requestTime", "requestTimeEpoch": "$context.requestTimeEpoch", "httpMethod": "$context.httpMethod", "path": "$context.path", "status": "$context.status", "error.message": "$context.error.message" }'
DefinitionBody:
openapi: 3.0.3
info:
title: Alma SRU Proxy
version: '1.0'
paths:
/:
get:
summary: Get Alma record given by mms_id and optional institution
description: gets the Alma record by mms_id
consumes:
- application/json
produces:
- application/json
parameters:
- in: query
name: mms_id
required: false
type: string
description: mms_id.
- in: query
name: institution
required: false
type: string
description: institution (alma_code).
- in: query
name: isbn
required: false
type: string
description: isbn.
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetAlmaSruRecordFunction.Arn}/invocations
responses: {}
httpMethod: POST
type: AWS_PROXY
responses:
'200':
description: alma record
content:
application/json:
schema:
$ref: '#/components/schemas/getAlmaSruRecordResponseBody'
'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:
getAlmaSruRecordResponseBody:
title: alma record
type: object
properties:
title:
type: string
description: bibliographic record from Alma
GetAlmaSruRecordFunction:
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: '*'
ALMA_SRU_HOST: !Ref SruEndpoint
Handler: no.unit.alma.GetAlmaSruRecordHandler::handleRequest
MemorySize: 1024
Events:
GetAlmaSruRecordEvent:
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 AlmaSruProxyApi
Method: get
Path: /
AlmaSruProxyBasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Condition: HasDomainName
Properties:
BasePath: !If
- HasCustomDomainBasePath
- !Ref CustomDomainBasePath
- !Ref 'AWS::NoValue'
DomainName: !Ref CustomDomain
RestApiId: !Ref AlmaSruProxyApi
Stage: !Ref AlmaSruProxyApi.Stage
Outputs:
ApiEndpoint:
Description: "Endpoint base URL for the API"
Value: !If
- HasDomainName
- !Sub "https://${CustomDomain}/${CustomDomainBasePath}"
- !Sub "https://${AlmaSruProxyApi}.execute-api.${AWS::Region}.amazonaws.com/${AlmaSruProxyApi.Stage}/"