-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
412 lines (372 loc) · 11.9 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
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Noteworthy
Parameters:
CognitoDomain:
Type: String
Description: A name for the Cognito Domain
S3Bucket:
Type: String
Description: Parameter to specify the S3 Bucket to use for deployment
FrontendDeployment:
Default: remote
Type: String
AllowedValues:
- local
- remote
ConstraintDescription: Must specify 'local' or 'remote' for FrontendDeployment.
Conditions:
DeployCloudFront: !Equals
- !Ref FrontendDeployment
- remote
Globals:
Function:
Timeout: 20
Api:
Cors:
AllowMethods: "'GET,POST,PUT,DELETE,OPTIONS'"
AllowHeaders: "'content-type,authorization'"
AllowOrigin: "'*'"
Auth:
DefaultAuthorizer: CognitoAuthorizer
AddDefaultAuthorizerToCorsPreflight: false
Authorizers:
CognitoAuthorizer:
UserPoolArn: !GetAtt UserPool.Arn
BinaryMediaTypes:
- 'multipart/form-data'
Resources:
#-----------------------------------------------------
# Cognito Configuration for user management
#-----------------------------------------------------
UserPool:
Type: AWS::Cognito::UserPool
Properties:
AccountRecoverySetting:
RecoveryMechanisms:
- Name: verified_email
Priority: 1
UsernameAttributes:
- email
UsernameConfiguration:
CaseSensitive: false
AutoVerifiedAttributes:
- email
UserPoolName: !Sub ${CognitoDomain}-user-pool
Schema:
- Name: email
AttributeDataType: String
Mutable: false
Required: true
- Name: name
AttributeDataType: String
Mutable: true
Required: true
UserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
UserPoolId: !Ref UserPool
AllowedOAuthFlowsUserPoolClient: true
CallbackURLs:
- http://localhost:8000
- !If
- DeployCloudFront
- !Sub "https://${CloudfrontDistribution.DomainName}"
- !Ref "AWS::NoValue"
LogoutURLs:
- http://localhost:8000
- !If
- DeployCloudFront
- !Sub "https://${CloudfrontDistribution.DomainName}"
- !Ref "AWS::NoValue"
AllowedOAuthFlows:
- code
- implicit
AllowedOAuthScopes:
- phone
- email
- openid
- profile
SupportedIdentityProviders:
- COGNITO
PreventUserExistenceErrors: ENABLED
UserPoolDomain:
Type: AWS::Cognito::UserPoolDomain
Properties:
Domain: !Ref CognitoDomain
UserPoolId: !Ref UserPool
#-----------------------------------------------------
# CloudFront Configuration
#-----------------------------------------------------
CloudFrontOriginAccessIdentity:
Type: 'AWS::CloudFront::CloudFrontOriginAccessIdentity'
Condition: DeployCloudFront
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: 'Serverless frontend website'
CloudfrontDistribution:
Type: "AWS::CloudFront::Distribution"
Condition: DeployCloudFront
Properties:
DistributionConfig:
Comment: "Cloudfront distribution for serverless website"
DefaultRootObject: "index.html"
Enabled: true
HttpVersion: http2
PriceClass: PriceClass_100
# List of origins that Cloudfront will connect to
Origins:
- Id: s3-website
DomainName: !Sub "${S3Bucket}.s3.us-east-2.amazonaws.com"
OriginPath: /static
S3OriginConfig:
# Restricting Bucket access through an origin access identity
OriginAccessIdentity:
Fn::Sub: 'origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}'
# To connect the CDN to the origins you need to specify behaviours
DefaultCacheBehavior:
# Compress resources automatically ( gzip )
Compress: 'true'
AllowedMethods:
- GET
- HEAD
- OPTIONS
ForwardedValues:
QueryString: false
TargetOriginId: s3-website
ViewerProtocolPolicy : redirect-to-https
CachePolicyId: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad
S3BucketPolicy:
Type: AWS::S3::BucketPolicy
Condition: DeployCloudFront
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
# Restricting access to cloudfront only.
Statement:
-
Effect: Allow
Action: 's3:GetObject'
Resource:
- !Sub "arn:aws:s3:::${S3Bucket}/*"
Principal:
AWS: !Sub "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${CloudFrontOriginAccessIdentity}"
#-----------------------------------------------------
# Role/Permissions/Policy Configuration
#-----------------------------------------------------
AccessRole:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaRole'
- 'arn:aws:iam::aws:policy/AWSLambdaExecute'
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: 'WriteToCloudWatch'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- cloudwatch:PutMetricData
Resource: '*'
- PolicyName: 'AccessNotesTable'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: dynamodb:*
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/notes"
- PolicyName: 'AccessTranscriptionsTable'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: dynamodb:*
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/transcriptions"
- PolicyName: 'AccessTranscribe'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: transcribe:*
Resource: '*'
- PolicyName: 'AccessS3BucketTranscribeOutputs'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: s3:*
Resource: '*'
#-----------------------------------------------------
# Lambda Functions Configuration
#-----------------------------------------------------
GetNotesLambda:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt AccessRole.Arn
CodeUri: noteworthyServiceLambda
Handler: com.nashss.se.noteworthy.lambda.GetNotesLambda::handleRequest
Runtime: java11
Architectures:
- x86_64
MemorySize: 512
Environment:
Variables:
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
Events:
Noteworthy:
Type: Api
Properties:
Path: /notes
Method: get
CreateNoteLambda:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt AccessRole.Arn
CodeUri: noteworthyServiceLambda
Handler: com.nashss.se.noteworthy.lambda.CreateNoteLambda::handleRequest
Runtime: java11
Architectures:
- x86_64
MemorySize: 512
Environment:
Variables:
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
Events:
Noteworthy:
Type: Api
Properties:
Path: /notes
Method: post
UpdateNoteLambda:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt AccessRole.Arn
CodeUri: noteworthyServiceLambda
Handler: com.nashss.se.noteworthy.lambda.UpdateNoteLambda::handleRequest
Runtime: java11
Architectures:
- x86_64
MemorySize: 512
Environment:
Variables:
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
Events:
Noteworthy:
Type: Api
Properties:
Path: /notes
Method: put
DeleteNoteLambda:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt AccessRole.Arn
CodeUri: noteworthyServiceLambda
Handler: com.nashss.se.noteworthy.lambda.DeleteNoteLambda::handleRequest
Runtime: java11
Architectures:
- x86_64
MemorySize: 512
Environment:
Variables:
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
Events:
Noteworthy:
Type: Api
Properties:
Path: /notes
Method: delete
TranscribeAudioLambda:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt AccessRole.Arn
CodeUri: noteworthyServiceLambda
Handler: com.nashss.se.noteworthy.lambda.TranscribeAudioLambda::handleRequest
Runtime: java11
Architectures:
- x86_64
MemorySize: 512
Timeout: 300
Environment:
Variables:
JAVA_TOOL_OPTIONS: -XX:+TieredCompilation -XX:TieredStopAtLevel=1
Events:
Noteworthy:
Type: Api
Properties:
Path: /notes/voice
Method: post
#-----------------------------------------------------
# S3 Bucket for Transcribe Outputs
#-----------------------------------------------------
TranscribeOutputBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: "nss-s3-c04-u7-noteworthy-cito.mcclure-transcribe-output"
#-----------------------------------------------------
# DynamoDB Configuration
#-----------------------------------------------------
NotesTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "email"
AttributeType: "S"
- AttributeName: "dateCreated"
AttributeType: "S"
KeySchema:
- AttributeName: "email"
KeyType: "HASH"
- AttributeName: "dateCreated"
KeyType: "RANGE"
BillingMode: "PAY_PER_REQUEST"
TableName: "notes"
TranscriptionsTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "transcriptionId"
AttributeType: "S"
KeySchema:
- AttributeName: "transcriptionId"
KeyType: "HASH"
BillingMode: "PAY_PER_REQUEST"
TableName: "transcriptions"
#-----------------------------------------------------
# The outputs defined below will be printed
# to the screen after a successful deploy
#-----------------------------------------------------
Outputs:
CognitoUserPoolId:
Value: !Ref UserPool
Description: "The Cognito User Pool ID (COGNITO_USER_POOL_ID)."
CognitoUserPoolClientId:
Value: !Ref UserPoolClient
Description: "The Cognito User Pool Client ID (COGNITO_USER_POOL_CLIENT_ID)."
CognitoDomain:
Value: !Sub "${CognitoDomain}.auth.us-east-2.amazoncognito.com"
Description: "The Cognito Domain (COGNITO_DOMAIN)."
ApiBaseUrl:
Description: "API Gateway endpoint base URL for Prod stage (API_BASE_URL)."
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
CognitoRedirectSignin:
Description: "The URL of the deployed front-end application (COGNITO_REDIRECT_SIGNIN)."
Value: !Sub "https://${CloudfrontDistribution.DomainName}"
Condition: DeployCloudFront
CognitoRedirectSignout:
Description: "The URL of the deployed front-end application (COGNITO_REDIRECT_SIGNOUT)."
Value: !Sub "https://${CloudfrontDistribution.DomainName}"
Condition: DeployCloudFront