-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
181 lines (172 loc) · 5.41 KB
/
template.yaml
File metadata and controls
181 lines (172 loc) · 5.41 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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: >
A microservice to generate waveforms
Check out https://github.com/firstcoders/stems-player-documentation/wiki
for more information.
Conditions:
CreateBucket: !Not [!Equals [!Ref ExistingBucket, true]]
Parameters:
# todo more validation
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
LogLevel:
Type: String
Description: The log level
Default: 'error'
AllowedValues:
- debug
- info
- error
StageName:
Type: String
Description: The api gateway stage name
Default: 'prd'
BucketName:
Type: String
Description: The bucket where to store the waveform data cache
ExistingBucket:
Type: String
Description: Whether to create the waveform bucket
AllowedValues:
- true
- false
Default: false
CORSAllowedOrigins:
Type: String
Description: The allowed origin header value to return
Default: ''
AudiowaveformLayerArn:
Type: String
Description: The arn of the lambda layer containing audiowaveform static binaries
AllowedAudioOrigins:
Type: CommaDelimitedList
Description: Comma-delimited list of origins from which the service can fetch audio
Default: '*'
AuthorizerArn:
Type: String
Description: The ARN of a lambda authorizer
S3FolderPrefix:
Type: String
Description: A prefix under which the generated files will be stored
Default: 'waveform-srv'
Globals:
Api:
OpenApiVersion: 3.0.1
Function:
Timeout: 30
Runtime: nodejs18.x
MemorySize: 256
CodeUri: src
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
WAVEFORM_BUCKET_NAME: !Ref BucketName
CORS_ALLOWED_ORIGINS: !Ref CORSAllowedOrigins
AUDIOWAVEFORM_BIN_PAH: /opt/bin/audiowaveform
ALLOWED_AUDIO_ORIGINS: !Join [',', !Ref AllowedAudioOrigins]
S3_FOLDER_PREFIX: !Ref S3FolderPrefix
Resources:
ServiceApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref StageName
EndpointConfiguration:
Type: REGIONAL
# https://github.com/aws/serverless-application-model/releases/tag/v1.46.0
# https://github.com/aws/serverless-application-model/pull/2298
ApiKeySourceType: AUTHORIZER
Auth:
DefaultAuthorizer: BearerTokenAuthorizer
AddDefaultAuthorizerToCorsPreflight: false
Authorizers:
BearerTokenAuthorizer:
FunctionArn: !Ref AuthorizerArn
ReauthorizeEvery: 300
Cors:
AllowMethods: "'POST, GET'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"
MaxAge: "'86400'"
GatewayResponses:
DEFAULT_4XX:
ResponseParameters:
Headers:
Access-Control-Expose-Headers: "'*'"
Access-Control-Allow-Origin: "'*'"
DEFAULT_5XX:
ResponseParameters:
Headers:
Access-Control-Expose-Headers: "'*'"
Access-Control-Allow-Origin: "'*'"
GetWaveformFunction:
Type: AWS::Serverless::Function
Properties:
Description: Gets waveform data based on a audio file provided by a URL
Handler: handlers/getWaveform.handler
Layers:
- !Ref AudiowaveformLayerArn
Events:
GetWaveform:
Type: Api
Properties:
RestApiId: !Ref ServiceApi
Path: /waveform
Method: get
Policies:
- S3CrudPolicy:
BucketName: !Ref BucketName
Metadata:
BuildMethod: esbuild
BuildProperties:
Format: esm
OutExtension:
- .js=.mjs
Target: 'es2020'
Sourcemap: false
EntryPoints:
- handlers/getWaveform.js
External:
- '@aws-sdk'
Banner:
- js=import { createRequire } from 'module'; const require = createRequire(import.meta.url);
WaveformBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Condition: CreateBucket
Properties:
BucketName: !Ref BucketName
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
Outputs:
ApiId:
Description: 'The API Gateway id'
Value: !Ref ServiceApi
ServiceApi:
Description: 'API Gateway endpoint URL'
Value: !Sub 'https://${ServiceApi}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/'
ServiceDomain:
Description: 'API Gateway domain'
Value: !Sub '${ServiceApi}.execute-api.${AWS::Region}.amazonaws.com'
GetWaveformFunctionArn:
Description: The ARN of the getwaveform function
Value: !GetAtt GetWaveformFunction.Arn
GetWaveformFunctionRoleArn:
Description: The ARN of the getwaveform function role
Value: !GetAtt GetWaveformFunctionRole.Arn
Metadata:
AWS::ServerlessRepo::Application:
Name: fc-audio-waveform-service
Description: >
A serverless microservice to generate waveforms based on a audio file provided by a URL
Author: Team First Coders
ReadmeUrl: README.md
SpdxLicenseId: AGPL-3.0-or-later
LicenseUrl: LICENSE
Labels: ['layer', 'lambda', 'serverless', 'waveform']
HomePageUrl: https://github.com/firstcoders/audio-waveform-service
SourceCodeUrl: https://github.com/firstcoders/audio-waveform-service
SemanticVersion: 1.0.0 # overwritten by sam publish cli command