-
Notifications
You must be signed in to change notification settings - Fork 12
/
serverless-uncompiled.yml
1884 lines (1675 loc) · 53.9 KB
/
serverless-uncompiled.yml
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
service: ${{self:custom.service}}
frameworkVersion: ">=1.5.0 <2.0.0"
plugins:
- prepare-offline
# - serverless-resources-env
- serverless-plugin-tracing
# - serverless-pseudo-parameters
# - serverless-sam
# - serverless-apigw-binary
- serverless-plugin-aws-alerts
# - serverless-plugin-common-excludes
- serverless-plugin-log-retention
# - serverless-dynamodb-autoscaling
# - serverless-s3-encryption
# - serverless-plugin-split-stacks
# - serverless-plugin-warmup
# - serverless-plugin-typescript
# - print
# - warmup
# - serverless-dynamodb-ttl
# - serverless-plugin-write-env-vars
# - serverless-plugin-include-dependencies
# - serverless-dynamodb-local
# - serverless-dynamodb-local
# - serverless-s3-local
- serverless-iot-local
- init-local
- "@tradle/serverless-offline"
- pre-deploy
# - serverless-offline-scheduler
package:
# artifactDirectoryName: serverless/${{self:service}}/${{self:provider.stage}}/artifacts
include:
- conf
- data
- serverless-interpolated.yml
exclude:
- src/**
- vars.json
- logs/**
- "*.log"
- "*.rdb"
- ".*"
- loadtesting/**
- myswagger.json
- myidentity.json
- lib/test/**
- lib/scripts/**
- conf/**
- certs/**
- org/**
- docker/**
- docs/**
- codebuild/**
- node_modules/**/*.ts
- node_modules/**/*.d.ts
- node_modules/**/test/*
- node_modules/**/tests/*
- node_modules/chokidar/**
- node_modules/fsevents/**
- node_modules/canvas/**
- "node_modules/@tradle/gen-samples/**"
- node_modules/lambda-ghostscript/**/doc/**
- node_modules/lambda-ghostscript/**/examples/**
- node_modules/lambda-ghostscript/**/man/**
- node_modules/moment/min/**
- node_modules/moment/src/**
- node_modules/caniuse-lite/data/features
- node_modules/caniuse-lite/data/regions
- node_modules/aes-js/~/**
- node_modules/node-gs/tests/**
- package-lock.json
- clienttest/
- .localstack/**
custom:
vars: ${{file(./vars.json), file(./default-vars.json)}}
version: ${{file(./lib/version.json)}}
defaults: ${{file(./default-vars.json)}}
# move these to vars.json when this issue is fixed:
# https://github.com/serverless/serverless/issues/3740
service: ${{self:custom.vars.service, self:custom.defaults.service}}
stage: ${{opt:stage, self:custom.vars.stage, self:custom.defaults.stage}}
# stage: dev
region: ${{opt:region, self:custom.vars.region, self:custom.defaults.region}}
profile: ${{opt:profile, self:custom.vars.profile, self:custom.defaults.profile}}
stackName: ${{self:service}}-${{self:custom.stage}}
versionFunctions: ${{self:custom.vars.versionFunctions, self:custom.defaults.versionFunctions}}
deploymentBucket: ${{file(./lib/cli/get-stack-parameter.js):parameterExistingDeploymentBucket}}
blockchain: ${{self:custom.vars.blockchain, self:custom.defaults.blockchain}}
corda: ${{self:custom.vars.corda, self:custom.defaults.corda}}
# providerConf: &providerConf
# ${{file(./src/in-house-bot/conf/provider.json)}}
# org: ${{self:custom.vars.org, self:custom.defaults.org}}
# logging: ${{self:custom.vars.logging, self:custom.defaults.logging}}
# copied from vars.json
# blockchain: ${{self:custom.vars.blockchain}}
# thresholdBillingAlarm: ${{self:custom.vars.thresholdBillingAlarm, self:custom.defaults.thresholdBillingAlarm}}
thresholdThrottlingAlarm: ${{self:custom.vars.thresholdThrottlingAlarm, self:custom.defaults.thresholdThrottlingAlarm}}
thresholdErrorsAlarm: ${{self:custom.vars.thresholdErrorsAlarm, self:custom.defaults.thresholdErrorsAlarm}}
thresholdInvocationsAlarm: ${{self:custom.vars.thresholdInvocationsAlarm, self:custom.defaults.thresholdInvocationsAlarm}}
thresholdDurationAlarm: ${{self:custom.vars.thresholdDurationAlarm, self:custom.defaults.thresholdDurationAlarm}}
# stage: ${{opt:stage, self:custom.vars.stage, self:custom.defaultStage}}
# region: ${{opt:region, self:custom.vars.region}}
# prefixes
prefix: ${{self:service}}-${{self:custom.stage}}-
# regionalPrefix: ${{self:service}}-${{self:custom.stage}}-${{self:custom.region}}-
# prefixRole: ${{self:custom.regionalPrefix}}
# maybe during info/auth, the server can send back the prefix
# prefixIOTTopic: ${{self:service}}-
# iotParentTopic: ${{self:custom.stackName}}
# prefixSNSTopic: ${{self:custom.prefix}}
prefixSQS: ${{self:custom.prefix}}
# apigateway
# adhere to serverless framework format
# apiGateway: ${{self:custom.stage}}-${{self:service}}
# versions
versionSQL: "2016-03-23"
s3TemplatesPath: ${{self:custom.version.templatesPath}}
# sns
# billingAlarmTopic: ${{self:custom.prefixSNSTopic}}BillingAlarmNotification
# throttlingAlarmTopic: ${{self:custom.prefixSNSTopic}}ThrottlingAlarmNotification
# invocationsAlarmTopic: ${{self:custom.prefixSNSTopic}}InvocationAlarmNotification
# invocationErrorsAlarmTopic: ${{self:custom.prefixSNSTopic}}InvocationErrorsAlarmNotification
alertNotifications:
- protocol: email
endpoint:
Ref: OrgAdminEmail
# Fn::FindInMap: ["org", "contact", "adminEmail"]
alerts:
stages:
- dev
dashboards: true
topics:
# ok:
# topic: ${{self:custom.prefix}}alerts-ok
# notifications: ${{self:custom.alertNotifications}}
alarm:
topic: ${{self:custom.prefix}}alerts-alarm
notifications: ${{self:custom.alertNotifications}}
# insufficientData:
# topic: ${{self:custom.prefix}}alerts-insufficientData
# notifications: ${{self:custom.alertNotifications}}
definitions:
functionErrors:
period: 60
threshold: ${{self:custom.thresholdErrorsAlarm}}
functionThrottles:
period: 60
threshold: ${{self:custom.thresholdThrottlingAlarm}}
functionInvocations:
period: 60
threshold: ${{self:custom.thresholdInvocationsAlarm}}
functionDuration:
period: 60
threshold: ${{self:custom.thresholdDurationAlarm}}
alarms:
# - functionErrors
# - functionThrottles
# - functionInvocations
# - functionDuration
# sqs
deadLetterQueueName: ${{self:custom.prefixSQS}}dead-letter-queue
tables:
# presence: ${{self:custom.prefix}}presence
# seals: ${{self:custom.prefix}}seals
# pubkeys: ${{self:custom.prefix}}pubkeys
# messages: ${{self:custom.prefix}}messages
events: ${{self:custom.prefix}}events
# pushsubscribers: ${{self:custom.prefix}}pushsubscribers
# users: ${{self:custom.prefix}}users
# friends: ${{self:custom.prefix}}friends
# conf: ${{self:custom.prefix}}conf
# kv: ${{self:custom.prefix}}kv
# backlinks: ${{self:custom.prefix}}backlinks
# defaultScaleInOut: &defaultScaleInOut
# scaleOut: 0
# scaleIn: 60
# # auto-scaled tables that serve as buckets for multiple models each
# defaultCapacityRead: &defaultCapacityRead
# read:
# minimum: 5 # Minimum read capacity
# maximum: 100 # Maximum read capacity
# usage: 0.70 # Targeted usage percentage
# <<: *defaultScaleInOut
# defaultCapacityWrite: &defaultCapacityWrite
# write:
# minimum: 5 # Minimum read capacity
# maximum: 100 # Maximum read capacity
# usage: 0.5 # Targeted usage percentage
# <<: *defaultScaleInOut
# defaultCapacity: &defaultCapacity
# <<: *defaultCapacityRead
# <<: *defaultCapacityWrite
# tableBuckets:
# count: 1
# read:
# minimum: 10 # Minimum read capacity
# maximum: 500 # Maximum read capacity
# usage: 0.70 # Targeted usage percentage
# <<: *defaultScaleInOut
# write:
# minimum: 10 # Minimum read capacity
# maximum: 500 # Maximum write capacity
# usage: 0.5 # Targeted usage percentage
# <<: *defaultScaleInOut
# dynamodb-autoscaling:
# role: AutoScalingDynamoDBRole
# capacities:
# # bucket-x table scaling is added in compile script
# - table: EventsTable
# write:
# minimum: 5 # Minimum write capacity
# maximum: 100 # Maximum write capacity
# usage: 0.5 # Targeted usage percentage
# <<: *defaultScaleInOut
cors:
origin: '*'
headers:
- Content-Type
- Content-Encoding
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
- X-Amz-User-Agent
- X-Tradle-Sig
- X-Tradle-Auth
- cache
allowCredentials: false
"@tradle/serverless-offline": ${{self:custom.vars.serverless-offline, self:custom.defaults.serverless-offline}}
serverless-iot-local: ${{self:custom.vars.serverless-iot-local, self:custom.defaults.serverless-iot-local}}
# reinitializeOnConfChanged: ${{self:custom.vars.reinitializeOnConfChanged, self:custom.defaults.reinitializeOnConfChanged}}
# serverless-dynamodb-local settings
# dynamodb:
# start:
# port: 4569
# # migrate: true
# inMemory: true
# # use dockerized dynamodb from localstack
# noStart: true
# # tables:
# # - ${{self:custom.prefix}}events
# # - ${{self:custom.prefix}}bucket-0
# serverless-s3-local settings
# s3:
# host: 0.0.0.0
# port: 4572
# # directory: /tmp
# buckets:
# - ${{self:custom.prefix}}objectsbucket
# - ${{self:custom.prefix}}secretsbucket
# - ${{self:custom.prefix}}privateconfbucket
# - ${{self:custom.prefix}}fileuploadbucket
# - ${{self:custom.prefix}}logsbucket
# cors: false
# # use dockerized s3 from localstack
# noStart: true
# create: false
# s3-encryption:
# buckets:
# SecretsBucket:
# SSEAlgorithm: AES256
logRetentionInDays: 1
# daysBeforeLogsGoToGlacier: 7
# issue2233WorkaroundKey: issue2233WorkaroundKey
# defaultKMSKeyId: ${{self:custom.regionalPrefix}}default-key
# tradleStackPrefix: tdl-tradle-ltd-${{self:stage}}-
# tradleStackRegion: us-east-1
# updatesTopicName: ${{self:custom.tradleStackPrefix}}updates-announcements
# secrets: ${{file(secrets.${opt:stage, self:provider.stage}}.yml)}
# dynamodb:
# start:
# port: 8000
# inMemory: true
# migration: true
# migration:
# dir: offline/migrations
provider:
# avoid some bugs in serverless
versionFunctions: ${{self:custom.versionFunctions}}
tracing: true
# https://github.com/serverless/serverless/issues/4312#issuecomment-331946882
variableSyntax: "\\${{([ ~:a-zA-Z0-9._\\'\",\\-\\/\\(\\)]+?)}}"
name: aws
runtime: nodejs14.x
nodeVersion: 'v14.x.x'
profile: ${{self:custom.profile}}
stage: ${{self:custom.stage}}
region: ${{self:custom.region}}
removeOldDeployments: false
memorySize: 512
timeout: 60
# deploymentBucket: io.tradle.${{self:custom.stage}}.deploys
# deploymentBucket: ${{self:custom.vars.deploymentBucket, self:custom.defaultVars.deploymentBucket}}
deploymentBucket: ${{self:custom.deploymentBucket}}
environment:
NODE_OPTIONS: "--no-warnings --no-deprecation"
# enable long stack traces
BLUEBIRD_DEBUG: 1
# IOT_TOPIC_PREFIX: ${{self:custom.prefixIOTTopic}}
STACK_NAME:
Ref: AWS::StackName
BLOCKCHAIN:
Ref: BlockchainNetwork
SEALING_MODE:
Ref: SealingMode
SEAL_BATCHING_PERIOD:
Ref: SealBatchingPeriodInMinutes
CORDA_API_URL: ${{self:custom.corda.apiUrl}}
CORDA_API_KEY: ${{self:custom.corda.apiKey}}
DEBUG: ${{self:custom.vars.debug.filter, self:custom.defaults.debug.filter}}
DEBUG_LEVEL: ${{self:custom.vars.debug.level, self:custom.defaults.debug.level}}
DEBUG_FORMAT: ${{self:custom.vars.debug.format, self:custom.defaults.debug.format}}
# SERVERLESS_PREFIX: ${{self:custom.prefix}}
# STACK_STAGE: ${{self:custom.stage}}
# SERVERLESS_SERVICE_NAME: ${{self:service}}
STACK_STAGE:
Ref: Stage
NO_TIME_TRAVEL: false # allow time-travel messages for now
ENABLE_XRAY:
Ref: EnableTracing
R_STACK:
Ref: AWS::StackId
R_BUCKET_Objects:
Fn::GetAtt: Buckets.Outputs.Objects
R_BUCKET_Secrets:
Fn::GetAtt: Buckets.Outputs.Secrets
R_BUCKET_FileUpload:
Fn::GetAtt: Buckets.Outputs.FileUpload
R_BUCKET_Logs:
Fn::GetAtt: Buckets.Outputs.Logs
R_BUCKET_PrivateConf:
Fn::GetAtt: Buckets.Outputs.PrivateConf
R_BUCKET_ServerlessDeployment:
Fn::GetAtt: Buckets.Outputs.Deployment
R_KEY_DefaultEncryption:
Fn::GetAtt: Keys.Outputs.EncryptionKey
R_TABLE_Events:
Fn::GetAtt: Tables.Outputs.Events
R_TABLE_Bucket0:
Fn::GetAtt: Tables.Outputs.Bucket0
R_RESTAPI_ApiGateway:
Fn::GetAtt: Source.Outputs.ApiGatewayRestApi
R_ROLE_IotClient:
Fn::GetAtt: IAM.Outputs.IotClientRole
# this is used only for pr9ovisioned scaling
R_ROLE_AutoScalingDynamoDB:
Fn::GetAtt: IAM.Outputs.AutoScalingDynamoDBRole
R_TOPIC_AdminAlerts:
Ref: AwsAlertsAlarm
IOT_ENDPOINT:
Fn::GetAtt: Discovery.Outputs.IotEndpoint
apiKeys:
- Fn::Sub: 'issue2233WorkaroundKey1-${AWS::StackName}'
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:CreateTable
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:BatchWriteItem
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource:
- Fn::Join:
- ''
- - Fn::Sub: 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/'
- Fn::GetAtt: Tables.Outputs.Events
- Fn::Join:
- ''
- - Fn::Sub: 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/'
- Fn::GetAtt: Tables.Outputs.Events
- '/index/*'
- Fn::Join:
- ''
- - Fn::Sub: 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/'
- Fn::GetAtt: Tables.Outputs.Bucket0
- Fn::Join:
- ''
- - Fn::Sub: 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/'
- Fn::GetAtt: Tables.Outputs.Bucket0
- '/index/*'
- Effect: Allow
Action:
# so lambdas can list resources in their stack
- cloudformation:ListStackResources
- CloudFormation:DescribeStacks
# need to get own template to generate a child deployment template
- cloudformation:GetTemplate
- cloudformation:UpdateTerminationProtection
# - cloudformation:UpdateStack
Resource:
Fn::Sub: 'arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AWS::StackName}/*'
# - Effect: Allow
# Action:
# Resource:
# Ref: AWS::StackId
# allow lambdas to update themselves / each other
- Effect: Allow
Action:
- lambda:UpdateFunctionConfiguration
- lambda:ListFunctions
# This action does not support resource-level permissions
Resource: "*"
# allow lambdas to call each other
# TODO: make this more fine grained
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
- lambda:AddPermission
- lambda:GetPolicy
Resource: "*"
- Effect: Allow
Action:
- lambda:GetFunctionConfiguration
Resource:
- Fn::Sub: 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-*'
# allow access to bucket
# TODO: give access only to the lambdas that need it
- Effect: Allow
Action:
# needed to get NoSuchKey error instead of AccessDenied for non-existent items
# https://forums.aws.amazon.com/thread.jspa?threadID=56531
- s3:ListBucket
- s3:PutBucketReplication
- s3:PutBucketVersioning
- s3:GetBucketPolicy
# needed to create regional deployment buckets
- s3:CreateBucket
# # needed to enable bucket encryption
# - s3:PutEncryptionConfiguration
Resource:
# Fn::Join:
# - ''
# - - "arn:aws:s3:::"
# - Ref: AWS::StackName
# - "-*"
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Objects
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Secrets
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.PrivateConf
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.FileUpload
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Logs
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Deployment
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Ref: AWS::StackName
# needed to manipulate regional buckets
- '-deploymentbucket-*'
# same purpose as previous, for backwards compat
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Ref: AWS::StackName
# needed to manipulate regional buckets
- '-serverlessdeploymentbucket-*'
- Effect: Allow
Action:
- s3:PutObject
# needed to create an object with public-read
- s3:PutObjectAcl
- s3:GetObject
Resource:
# Fn::Join:
# - ''
# - - "arn:aws:s3:::"
# - Ref: AWS::StackName
# - "-*/*"
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Objects
- '/*'
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Secrets
- '/*'
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.PrivateConf
- '/*'
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.FileUpload
- '/*'
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Logs
- '/*'
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Fn::GetAtt: Buckets.Outputs.Deployment
- '/*'
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Ref: AWS::StackName
# needed to manipulate regional buckets
- '-deploymentbucket-*/*'
# same purpose as previous, for backwards compat
- Fn::Join:
- ''
- - "arn:aws:s3:::"
- Ref: AWS::StackName
# needed to manipulate regional buckets
- '-serverlessdeploymentbucket-*/*'
# - Effect: Allow
# Action:
# - s3:DeleteObject
# - s3:DeleteObjectVersion
# Resource:
# # currently only needed to delete terms and conditions
# - Fn::Join:
# - ""
# - - "arn:aws:s3:::"
# - Fn::GetAtt: Buckets.Outputs.PrivateConf
# - "/conf/*"
- Effect: Allow
Action:
- s3:GetBucketLocation
- s3:ListAllMyBuckets
Resource: "arn:aws:s3:::*"
- Effect: Allow
Action:
- sns:AddPermission
- sns:CreateTopic
- sns:DeleteTopic
- sns:Publish
- sns:Subscribe
- sns:Unsubscribe
- sns:ListSubscriptions
- sns:ListSubscriptionsByTopic
- sns:GetTopicAttributes
- sns:SetTopicAttributes
Resource: "*"
# Iot
- Effect: Allow
Action: ["iot:Connect", "iot:Subscribe", "iot:Publish", "iot:Receive", "iot:DescribeEndpoint"]
Resource: "*"
# gen Iot temp credentials (lambda: preauth)
- Effect: Allow
Action:
- sts:AssumeRole
Resource:
- Fn::GetAtt: IAM.Outputs.IotClientRole
- Effect: Allow
Action:
- xray:PutTraceSegments
- xray:PutTelemetryRecords
Resource: "*"
- Effect: Allow
Sid: AllowCloudFrontUpdateDistribution
Action:
- cloudfront:updateDistribution
Resource: "*"
# - Effect: Allow
# Action:
# - apigateway:GET
# - apigateway:PUT
# Resource:
# Fn::Join:
# - ""
# - - "arn:aws:apigateway:"
# - Ref: AWS::Region
# - "::/restapis/"
# - Ref: ApiGatewayRestApi
# - "/*"
# - Effect: Allow
# Action:
# - apigateway:POST
# Resource:
# Fn::Join:
# - ""
# - - "arn:aws:apigateway:"
# - Ref: AWS::Region
# - "::/restapis/"
# - Ref: ApiGatewayRestApi
- Effect: Allow
Action:
- ses:SendEmail
- ses:SendRawEmail
- ses:GetIdentityVerificationAttributes
Resource: "*"
- Effect: Allow
Action:
- cloudwatch:PutMetricAlarm
- cloudwatch:DescribeAlarms
- cloudwatch:DescribeAlarmsForMetric
Resource: '*'
- Effect: Allow
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource:
- Fn::GetAtt: Keys.Outputs.EncryptionKeyArn
- Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:GenerateDataKey
Resource:
- Fn::If:
- DoEncryptBuckets
- Fn::GetAtt: Keys.Outputs.BucketEncryptionKeyArn
- Ref: AWS::NoValue
- Effect: Allow
Action:
- textract:*
Resource: '*'
- Effect: Allow
Action:
- athena:*
Resource: '*'
- Effect: Allow
Action:
- glue:*
Resource: '*'
# - Effect: Allow
# Action:
# - 'ssm:GetParameter*'
# - 'ssm:PutParameter*'
# Resource:
# - 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/tradle/${{self:custom.prefix}}*'
# - Effect: Allow
# Action:
# # TODO: narrow this down
# # look out for error: "The specified log group does not exist"
# - logs:*
# # - logs:PutSubscriptionFilter
# # - logs:DeleteSubscriptionFilter
# Resource: "*"
functions:
# httpRouter:
# handler: lib/in-house-bot/lambda/http/router.handler
# memorySize: 1024
# events:
# - http:
# # this matches any path, the token 'ANY' doesn't mean anything special
# path: /{any+}
# method: get
# cors: ${{self:custom.cors}}
# - http:
# # this matches any path, the token 'ANY' doesn't mean anything special
# path: /{any+}
# method: post
# cors: ${{self:custom.cors}}
# - http:
# # this matches any path, the token 'ANY' doesn't mean anything special
# path: /{any+}
# method: put
# cors: ${{self:custom.cors}}
# 1. generates temporary credentials (STS) for new connections,
# and assumes IotClientRole on them
# 2. creates an unauthenticated session,
# generates a challenge to be signed (verified in /auth)
preauth:
handler: lib/in-house-bot/lambda/http/preauth.handler
memorySize: 1024
events:
- http:
path: preauth
method: post
cors: ${{self:custom.cors}}
# 1. validates the challenge response
# 2. marks the session as authenticated
auth:
handler: lib/in-house-bot/lambda/http/auth.handler
memorySize: 1024
events:
- http:
path: auth
method: post
cors: ${{self:custom.cors}}
inbox:
handler: lib/in-house-bot/lambda/http/inbox.handler
memorySize: 1024
events:
- http:
path: inbox
method: put
cors: ${{self:custom.cors}}
- http:
path: inbox
method: post
cors: ${{self:custom.cors}}
# delivery-retry:
# handler: lib/in-house-bot/lambda/delivery-retry.handler
# memorySize: 128
# timeout: 60
# events:
# - schedule:
# rate: rate(1 minute)
# enabled: true
# triggered when an internal bot requests a message range (inbound messages)
# inbox:
# handler: lib/lambda/inbox.handler
# memorySize: 1024
# events:
# - iot:
# sql: "SELECT * as data, topic() as topic FROM 'messages/get'"
# triggered when a client requests a message range (outbound messages)
# outbox:
# handler: lib/lambda/outbox.handler
# memorySize: 1024
# events:
# - iot:
# sql: "SELECT * as data, topic() as topic FROM '+/restore'"
# environment:
# DEBUG: tradle:*
# handles IoT (MQTT) connections post-authentication
# updates presence in PresenceTable
oniotlifecycle:
handler: lib/in-house-bot/lambda/mqtt/oniotlifecycle.handler
events:
# - iot:
# sql: "SELECT * as data, topic() as topic FROM '$aws/events/#' WHERE startswith(clientId, '${{self:custom.iotClientIdPrefix}}')"
# sqlVersion: ${{self:custom.versionSQL}}
# - iot:
# sql: "SELECT * as data, topic() as topic FROM '$aws/events/presence/connected/#' WHERE startswith(clientId, '${{self:custom.iotClientIdPrefix}}')"
# sqlVersion: ${{self:custom.versionSQL}}
# - iot:
# sql: "SELECT * as data, topic() as topic FROM '$aws/events/presence/disconnected/#' WHERE startswith(clientId, '${{self:custom.iotClientIdPrefix}}')"
# sqlVersion: ${{self:custom.versionSQL}}
- iot:
sql:
Fn::Sub: "SELECT * as data, topic() as topic FROM '$aws/events/subscriptions/subscribed/#' WHERE startswith(clientId, '${AWS::StackName}-')"
sqlVersion: ${{self:custom.versionSQL}}
- iot:
sql:
Fn::Sub: "SELECT * as data, topic() as topic FROM '$aws/events/presence/disconnected/#' WHERE startswith(clientId, '${AWS::StackName}-')"
sqlVersion: ${{self:custom.versionSQL}}
# - iot:
# sql: "SELECT * as data, topic() as topic FROM '$aws/events/subscriptions/subscribed/#' WHERE startswith(clientId, '${{self:custom.iotClientIdPrefix}}')"
# sqlVersion: ${{self:custom.versionSQL}}
# - iot:
# sql: "SELECT * as data, topic() as topic FROM '$aws/events/presence/disconnected/#' WHERE startswith(clientId, '${{self:custom.iotClientIdPrefix}}')"
# sqlVersion: ${{self:custom.versionSQL}}
alarms:
- functionErrors
- functionThrottles
- functionInvocations
# onconnect:
# handler: lib/in-house-bot/lambda/mqtt/onconnect.handler
# events:
# - iot:
# sql: "SELECT * FROM '$aws/events/presence/connected/#'"
# sqlVersion: ${{self:custom.versionSQL}}
# alarms:
# - functionErrors
# - functionThrottles
# - functionInvocations
# triggered when a client sends a message
#
# validates, stores in MessagesTable, in ObjectsBucker (for now),
# and passes off to bot engine
onmessage:
handler: lib/in-house-bot/lambda/mqtt/onmessage.handler
memorySize: 1024
# SERVERLESS_PREFIX: ${{self:custom.prefix}}
# STACK_STAGE: ${{self:custom.stage}}
# SERVERLESS_SERVICE_NAME: ${{self:service}}
events:
- iot:
sql:
Fn::Sub: "SELECT encode(*, 'base64') as data, clientid() as clientId, topic() as topic FROM '${AWS::StackName}/+/pub/outbox'"
sqlVersion: ${{self:custom.versionSQL}}
alarms:
- functionErrors
- functionThrottles
- functionInvocations
# same as onmessage, but can handle larger payloads
# MQTT is limited to 128KB, HTTP to 6MB
# onmessage_http:
# handler: lib/in-house-bot/lambda/http/onmessage.handler
# memorySize: 1024
# events:
# - http:
# path: message
# method: put
# - http:
# path: message
# method: post
# alarms:
# - functionErrors
# - functionThrottles
# - functionInvocations
# performs service discovery - builds a map of logical->physical ids
# and writes that map to the environment variables of all other lambdas
# setenvvars:
# handler: lib/lambda/setenvvars.handler
# # hack to enable discovery own function's own stack
# description:
# Ref: AWS::StackId
# initializes provider identity
# generates a new identity and keys, and other misc crap
# init:
# handler: lib/lambda/init.handler
# memorySize: 256
# timeout: 300
# alarms:
# - functionErrors
# - functionThrottles
# - functionInvocations
# setstyle:
# handler: lib/lambda/setstyle.handler
# memorySize: 128
# alarms:
# - functionErrors
# - functionThrottles
# - functionInvocations
# precreate-tables:
# handler: lib/lambda/precreate-tables.handler
# memorySize: 128
# timeout: 300
# Blockchain
# bitcoin faucet (surprise!)
# distributes testnet coins from local funds
# faucet_bitcoin:
# handler: lib/lambda/faucet-bitcoin.withdraw
# gets funds from a bitcoin testnet faucet
# recharge_bitcoin:
# handler: lib/lambda/recharge-bitcoin.handler
# events:
# - schedule:
# rate: rate(10 minutes)
# enabled: false
# get funds from ethereum testnet faucet
# (doesn't work on rinkeby, and doesn't work well on ropsten)
# recharge_ethereum:
# handler: lib/lambda/recharge-ethereum.handler
# events:
# - schedule:
# rate: rate(10 minutes)
# enabled: false
# writes pending transactions to the blockchain
jobScheduler:
handler: lib/in-house-bot/lambda/job-scheduler.handler
memorySize: 256
timeout: 30
events:
- schedule:
rate: rate(1 minute)
# alarms:
# - functionErrors
# # - functionThrottles
# # - functionInvocations
genericJobRunner:
handler: lib/in-house-bot/lambda/job-runner.handler
memorySize: 1024
timeout: 900
alarms:
- functionErrors
- functionInvocations
# polls the status of unconfirmed blockchain transactions
# pollchain:
# handler: lib/in-house-bot/lambda/pollchain.handler
# memorySize: 256
# timeout: 300
# # events:
# # - schedule:
# # rate: rate(10 minutes)
# # # enabled: false
# alarms:
# - functionErrors
# # - functionThrottles
# # - functionInvocations
# # environment:
# # ENCRYPTION_KEY: ${{self:custom.secrets.SESSION_KEY}}
# # EMAIL_SERVICE_API_KEY: ${{self:custom.secrets.EMAIL_SERVICE_API_KEY}}
# check-failed-seals:
# handler: lib/in-house-bot/lambda/check-failed-seals.handler
# memorySize: 256
# timeout: 60
# # events:
# # - schedule:
# # rate: rate(17 minutes)
# # # enabled: false
# alarms: