Repository navigation
Expand file tree
/
Copy pathtemplate.yaml
More file actions
1668 lines (1601 loc) · 60.6 KB
/
Copy pathtemplate.yaml
File metadata and controls
1668 lines (1601 loc) · 60.6 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
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Code-configured serverless automation runner
Parameters:
AwsAssumableRoleArns:
Type: CommaDelimitedList
Default: arn:aws:iam::387546586013:role/dapier-mailchimp-backup
AllowedPattern: 'arn:aws(-us-gov|-cn)?:iam::[0-9]{12}:role/[A-Za-z0-9+=,.@_/-]+'
Description: IAM roles operators may configure for provider access
DomainName:
Type: String
Default: dapier.dtcdev.click
DomainCertificateArn:
Type: String
HostedZoneId:
Type: String
Default: Z05963572WVWFHDQZH5NE
HtmlRendererImageUri:
Type: String
DatamailerInboundBucketName:
Type: String
Default: relay-sandbox-817685572750-eu-west-1-inbound-mail
LegacyInboundMailBucketName:
Type: String
Default: datamailer-sandbox-817685572750-inbound-mail
Description: >
Legacy datamailer raw bucket that still receives dtcdev.click inbound
mail from the us-east-1 SES receipt rule; its objects publish through
EmailIngressFunction until the relay cutover retires the bucket.
LegacyInboundEmailTopicArn:
Type: String
Default: arn:aws:sns:us-east-1:817685572750:datamailer-sandbox-inbound-email-events
Description: >
Datamailer SNS topic the us-east-1 SES receipt rule still publishes
inbound events to; allowed alongside the pinned topic so mail keeps
flowing until the relay cutover retires the legacy chain.
InboundEmailTopicArn:
Type: String
Default: arn:aws:sns:eu-west-1:817685572750:relay-sandbox-inbound-email-events
DataOpsEmailDocumentsBucket:
Type: String
Default: dataops-v1-emaildocumentsbucket-1dbv70hrd4al
Description: >
DataOps intake documents bucket; the worker stages files under its
transfer/ prefix because the intake verifies each document's S3 source
AuthBaseUrl:
Type: String
Default: https://auth.dtcdev.click
AuthClientId:
Type: String
AuthCliClientId:
Type: String
Default: ''
Description: DTC shared-auth public client ID for the dapier CLI (empty disables CLI token issuance)
AuthIssuer:
Type: String
AuthJwksUrl:
Type: String
OperatorEmails:
Type: String
Default: ''
Description: Comma-separated DTC accounts allowed to administer connections (empty means any signed-in DTC account)
OperatorSubjects:
Type: String
Default: ''
Description: Comma-separated stable DTC subjects allowed to administer connections
GmailScopes:
Type: String
Default: ''
Description: >
Extra Gmail OAuth scopes (GMAIL_SCOPES) added to the grant of any
Google connection that touches Gmail, comma- or whitespace-separated
full URLs or short names (gmail.modify); empty grants only the
connector's declared gmail.readonly and gmail.send
TriggerEmailDomain:
Type: String
Default: dtcdev.click
Description: Domain for operator-created email trigger addresses
EmailSender:
Type: String
Default: no-reply@dtcdev.click
Description: From address for email_send workflow actions (must be SES-verified)
NotifyEmail:
Type: String
Default: alexey.s.grigoriev@gmail.com
Description: >
Operator inbox for failed-run notices, CloudWatch alarms, and the
daily error digest. Distinct from EmailSender, which is the SES
From identity and is not a mailbox anyone reads.
EmailSendRegion:
Type: String
Default: us-east-1
Description: SES region with the verified completion-email sender identity
GithubWorkflowsTokenSecret:
Type: String
Default: ''
Description: >
Secrets Manager secret name holding a GitHub token (Contents: read/write
on the workflows repo). Set to let the console designer commit
workflows/*.yaml straight to the repo; empty disables designer saves.
SesNotificationTopics:
Type: String
Default: ''
Description: >
Comma-separated SNS TopicArns the SES feedback hook accepts
(SES_NOTIFICATION_TOPICS allowlist); empty accepts any topic — set
the configuration set's feedback destination topics in production
SesConfigurationSet:
Type: String
Default: ''
Description: >
SES configuration set attached to workflow email sends
(SES_CONFIGURATION_SET) — the switch that makes SES report bounce and
complaint feedback at all; create the set with an event destination
whose SNS topic subscribes https://<domain>/hooks/ses-notifications,
then list that topic in SesNotificationTopics. Empty sends untagged.
BackupAlertEmail:
Type: String
Default: alexey.s.grigoriev@gmail.com
Description: Recipient of the DynamoDB backup failure email
Conditions:
HasGithubWorkflowsToken: !Not [!Equals [!Ref GithubWorkflowsTokenSecret, '']]
Globals:
Function:
Timeout: 30
MemorySize: 256
Tracing: Active
Environment:
Variables:
AWS_ASSUMABLE_ROLE_ARNS: !Join [",", !Ref AwsAssumableRoleArns]
S3_RUNTIME_UPLOAD_BUCKETS: !Ref ZoomTranscriptsBucket
EVENT_QUEUE_URL: !Ref EventQueue
CONNECTIONS_TABLE: !Ref ConnectionsTable
CREDENTIALS_TABLE: !Ref CredentialsTable
CURSORS_TABLE: !Ref CursorsTable
EXECUTIONS_TABLE: !Ref ExecutionsTable
GRANTS_TABLE: !Ref GrantsTable
TASK_USAGE_TABLE: !Ref TaskUsageTable
PAID_API_USAGE_TABLE: !Ref PaidApiUsageTable
STORAGE_TABLE: !Ref StorageTable
DIGESTS_TABLE: !Ref DigestsTable
AUDIT_TABLE: !Ref AuditTable
RENDER_QUEUE_URL: !Ref RenderQueue
RENDER_ARTIFACTS_BUCKET: !Ref RenderArtifactsBucket
DATAOPS_EMAIL_DOCUMENTS_BUCKET: !Ref DataOpsEmailDocumentsBucket
AUTH_BASE_URL: !Ref AuthBaseUrl
AUTH_CLIENT_ID: !Ref AuthClientId
AUTH_CLI_CLIENT_ID: !Ref AuthCliClientId
AUTH_CALLBACK_URL: !Sub https://${DomainName}/auth/callback
AUTH_LOGOUT_URL: !Sub https://${DomainName}/
OAUTH_CALLBACK_URL: !Sub https://${DomainName}/oauth/callback
# Extra Gmail scopes (connectors.gmail GMAIL_SCOPES) beyond the
# declared gmail.readonly/gmail.send; empty keeps the declaration.
GMAIL_SCOPES: !Ref GmailScopes
AUTH_ISSUER: !Ref AuthIssuer
AUTH_JWKS_URL: !Ref AuthJwksUrl
OPERATOR_EMAILS: !Ref OperatorEmails
OPERATOR_SUBJECTS: !Ref OperatorSubjects
TRIGGER_EMAIL_DOMAIN: !Ref TriggerEmailDomain
EMAIL_FROM_TABLE: !Ref EmailFromTable
HOST_TASKS_TABLE: !Ref HostTasksTable
HOST_QUEUE_URL: !Ref HostQueue
DAPIER_EMAIL_REGION: !Ref EmailSendRegion
DAPIER_NOTIFY_EMAIL: !Ref NotifyEmail
HOOK_TRIGGERS_TABLE: !Ref HookTriggersTable
TRIGGER_INBOX_TABLE: !Ref TriggerInboxTable
SCHEDULE_TRIGGERS_TABLE: !Ref ScheduleTriggersTable
POLL_TRIGGERS_TABLE: !Ref PollTriggersTable
PUBLISHED_WORKFLOWS_TABLE: !Ref PublishedWorkflowsTable
API_TOKENS_TABLE: !Ref ApiTokensTable
DEVICE_SESSIONS_TABLE: !Ref DeviceSessionsTable
HOOKS_BASE_URL: !Sub https://${DomainName}
Resources:
Api:
Type: AWS::Serverless::HttpApi
Properties:
CorsConfiguration:
AllowOrigins: ['*']
# Bearer token: GET /internal/ops/status is read by a browser-hosted
# console, so its Authorization header has to survive the preflight.
AllowHeaders: [content-type, x-dropbox-signature, authorization]
AllowMethods: [GET, POST]
Domain:
DomainName: !Ref DomainName
CertificateArn: !Ref DomainCertificateArn
EndpointConfiguration: REGIONAL
Route53:
HostedZoneId: !Ref HostedZoneId
EvaluateTargetHealth: false
# JavaScript code steps run on an embedded V8 (py_mini_racer). Its wheel is
# manylinux_2_27-only, which SAM's PythonPipBuilder refuses to cross-resolve
# for arm64, so it ships as a prebuilt layer — `make layer` produces the zip
# under .aws-sam/layers-src/, which SAM's repo copy skips — rather than a
# requirements.txt entry. Attached only to the functions that can execute a
# chain: the API (test-run with execute=true) and the worker (real runs).
JsRuntimeLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: dapier-js-runtime
Description: py_mini_racer (embedded V8) for JavaScript code steps
ContentUri: .aws-sam/layers-src/js-runtime.zip
CompatibleRuntimes:
- python3.12
CompatibleArchitectures:
- arm64
RetentionPolicy: Delete
# The API's execution role, explicit and named. The implicit role this
# replaces accumulated inline policy documents deploy after deploy until
# its total crossed IAM's 10240-byte cap — from then on every PutRolePolicy
# failed with ServiceLimitExceeded, the role drifted from the template
# (the connections table's dynamodb grants vanished; every connections
# route answered 500), and no deploy could repair it. A new role starts
# with an empty budget. The statements below consolidate the previous
# per-table policy documents (identical actions, identical tables —
# DynamoDBCrudPolicy/DynamoDBReadPolicy spelled out) into a handful of
# documents, leaving years of headroom under the cap. If this role ever
# fills again, the repair is the same: a new logical id here mints a
# fresh role on the next deploy.
ApiExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: {Service: lambda.amazonaws.com}
Action: sts:AssumeRole
# The managed policies SAM attaches to an implicit execution role:
# function logs and X-Ray tracing. Managed policies never count
# against the inline-policy budget.
ManagedPolicyArns:
- !Sub arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- !Sub arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
Policies:
# Named inline documents (an explicit role takes raw policy
# documents, not SAM policy templates). Same grants the implicit
# role carried, consolidated into a handful of documents.
- PolicyName: dapier-api-assume-configured-roles
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: sts:AssumeRole
Resource: !Ref AwsAssumableRoleArns
- PolicyName: dapier-api-enqueue-work
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: sqs:SendMessage
Resource:
- !GetAtt EventQueue.Arn
- !GetAtt DropboxQueue.Arn
- PolicyName: dapier-api-provider-secrets
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: secretsmanager:GetSecretValue
Resource:
- !Ref YouTubeWebhookSecret
- !Ref DapierAdminSecret
- !Sub 'arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:dapier/dataops-*'
- !If
- HasGithubWorkflowsToken
- PolicyName: dapier-api-github-token-read
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: secretsmanager:GetSecretValue
Resource: !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${GithubWorkflowsTokenSecret}*
- !Ref AWS::NoValue
- PolicyName: dapier-api-dataops-intake-stage
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: s3:PutObject
Resource: !Sub 'arn:aws:s3:::${DataOpsEmailDocumentsBucket}/transfer/*'
- PolicyName: dapier-api-transcript-upload
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: s3:PutObject
Resource: !Sub '${ZoomTranscriptsBucket.Arn}/*'
# Every table the API reads and writes at full CRUD, one document.
# The per-table DynamoDBCrudPolicy documents carried exactly these
# actions (streams reads included for parity with the SAM policy).
- PolicyName: dapier-api-dynamodb-crud
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [dynamodb:BatchGetItem, dynamodb:BatchWriteItem,
dynamodb:ConditionCheckItem, dynamodb:DeleteItem,
dynamodb:DescribeTable, dynamodb:GetItem,
dynamodb:GetRecords, dynamodb:GetShardIterator,
dynamodb:Query, dynamodb:Scan, dynamodb:PutItem,
dynamodb:UpdateItem]
Resource:
- !GetAtt ConnectionsTable.Arn
- !GetAtt ExecutionsTable.Arn
# The runs-by-run-id GSI behind every run detail read
# (DynamoDBCrudPolicy granted <table>/index/* implicitly).
- !Sub '${ExecutionsTable.Arn}/index/*'
- !GetAtt GrantsTable.Arn
- !GetAtt AuditTable.Arn
- !GetAtt EmailFromTable.Arn
- !GetAtt HostTasksTable.Arn
- !GetAtt HookTriggersTable.Arn
- !GetAtt ApiTokensTable.Arn
- !GetAtt DeviceSessionsTable.Arn
- !GetAtt ScheduleTriggersTable.Arn
- !GetAtt PollTriggersTable.Arn
- !GetAtt PublishedWorkflowsTable.Arn
- !GetAtt StorageTable.Arn
- !GetAtt DigestsTable.Arn
# The zoom webhook intake records refused deliveries here
# (triggers.inbox.record/ignore) — writes, not just reads.
- !GetAtt TriggerInboxTable.Arn
# Read-only tables: cursor failure counts, the usage rollup
# (DynamoDBReadPolicy, one document).
- PolicyName: dapier-api-dynamodb-read
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [dynamodb:BatchGetItem, dynamodb:ConditionCheckItem,
dynamodb:DescribeTable, dynamodb:GetItem,
dynamodb:GetRecords, dynamodb:GetShardIterator,
dynamodb:Query, dynamodb:Scan]
Resource:
- !GetAtt CursorsTable.Arn
- !GetAtt TaskUsageTable.Arn
- !GetAtt PaidApiUsageTable.Arn
# Inline decisions and OpenRouter health probes run on the API.
- Effect: Allow
Action: [dynamodb:PutItem]
Resource: !GetAtt PaidApiUsageTable.Arn
# Operator teardown and authenticated hook retry claims share this
# table. Keep writes within trigger cursor/seen keys.
- PolicyName: dapier-api-cursor-scoped-writes
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [dynamodb:PutItem, dynamodb:UpdateItem, dynamodb:DeleteItem]
Resource: !GetAtt CursorsTable.Arn
Condition:
ForAllValues:StringLike:
dynamodb:LeadingKeys: ['poll#*', 'seen#poll#*', 'seen#hook#*']
- PolicyName: dapier-api-credentials-store
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [dynamodb:GetItem, dynamodb:PutItem]
Resource: !GetAtt CredentialsTable.Arn
# SendMessage belongs in this same statement: a separate policy for
# one action once pushed the previous role over the cap and wedged
# the stack in rollback. API-side paths enqueue host tasks directly
# (workflows test --execute, redo rows built outside a running
# flow); a denied send strands the HostTasks row queued forever
# with no message to lease.
- PolicyName: dapier-api-host-queue-lease
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [sqs:ReceiveMessage, sqs:DeleteMessage,
sqs:ChangeMessageVisibility, sqs:SendMessage]
Resource: !GetAtt HostQueue.Arn
- PolicyName: dapier-api-send-email
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [ses:SendEmail, ses:SendRawEmail]
Resource: '*'
- PolicyName: dapier-api-trigger-rules
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [events:PutRule, events:PutTargets, events:DeleteRule,
events:RemoveTargets, events:DescribeRule]
Resource:
- !Sub arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/dapier-schedule-*
- !Sub arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/dapier-poll-*
# host-jobs/attachment streams a claimed job's stored trigger
# attachments to the lease-holding worker over HTTPS, straight from
# the inbound mail bucket; oversized replay rehydrates a clipped
# trigger from the raw email copy its s3 pointer names.
- PolicyName: dapier-api-read-inbound-buckets
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [s3:GetObject, s3:ListBucket]
Resource:
- !Sub arn:aws:s3:::${DatamailerInboundBucketName}
- !Sub arn:aws:s3:::${DatamailerInboundBucketName}/*
- !Sub arn:aws:s3:::${LegacyInboundMailBucketName}
- !Sub arn:aws:s3:::${LegacyInboundMailBucketName}/*
- !Sub arn:aws:s3:::${MailBucket}
- !Sub arn:aws:s3:::${MailBucket}/*
# Designer/CLI execution tests run file-read steps in the API process.
# Stage and read their bytes just as the worker does.
- PolicyName: dapier-api-test-worker-connections
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [lambda:InvokeFunction]
Resource: !GetAtt WorkerFunction.Arn
- PolicyName: dapier-api-render-artifacts
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: [s3:GetObject, s3:PutObject]
Resource: !Sub '${RenderArtifactsBucket.Arn}/*'
IngressFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: src.dapier.api.router.handler
Runtime: python3.12
Architectures: [arm64]
Layers:
- Ref: JsRuntimeLayer
Role: !GetAtt ApiExecutionRole.Arn
Environment:
Variables:
YOUTUBE_WEBHOOK_SECRET_ID: !Ref YouTubeWebhookSecret
# The save path subscribes/unsubscribes WebSub topics on designer
# saves, toggles, and deletes (designer_store._sync_youtube).
YOUTUBE_CALLBACK_URL: !Sub https://${DomainName}/hooks/youtube
# TopicArn allowlist for the SES feedback hook
# (triggers.intake.ses_notifications); empty accepts any topic.
SES_NOTIFICATION_TOPICS: !Ref SesNotificationTopics
ADMIN_SECRET_ID: !Ref DapierAdminSecret
DAPIER_EMAIL_SENDER: !Ref EmailSender
GITHUB_WORKFLOWS_TOKEN_SECRET: !Ref GithubWorkflowsTokenSecret
WORKER_FUNCTION_ARN: !GetAtt WorkerFunction.Arn
DROPBOX_QUEUE_URL: !Ref DropboxQueue
Events:
Root:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /, Method: GET}
PublicHome:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /about, Method: GET}
PrivacyPolicy:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /privacy, Method: GET}
TermsOfService:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /terms, Method: GET}
ConsoleWorkflows:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /workflows, Method: GET}
ConsoleTemplates:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /templates, Method: GET}
# Workflow deep links (/workflows/<id>) serve the console shell; the
# client router resolves the workflow.
ConsoleWorkflowDetail:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: '/workflows/{proxy+}', Method: GET}
ConsoleConnections:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /connections, Method: GET}
ConsoleEmails:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /emails, Method: GET}
ConsoleAgents:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /agents, Method: GET}
ConsoleWorkers:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /workers, Method: GET}
ConsoleCredentials:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /credentials, Method: GET}
ConsoleTokens:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /tokens, Method: GET}
ConsoleUsers:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /users, Method: GET}
ConsoleRuns:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /runs, Method: GET}
ConsoleInbox:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /inbox, Method: GET}
ConsoleStorage:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /storage, Method: GET}
ConsoleUsage:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /usage, Method: GET}
ConsoleCosts:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /costs, Method: GET}
ConsoleAudit:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /audit, Method: GET}
ConsoleSchedules:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /schedules, Method: GET}
ConsoleTriggers:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /triggers, Method: GET}
# One greedy route for every static asset; the console Lambda's
# allowlist (router._static) decides what is actually served.
ConsoleAssets:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: '/assets/{proxy+}', Method: GET}
DesignerView:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /designer, Method: GET}
# The designer app shell under /designer/app, framed by the console's
# /designer view; the router._static allowlist decides what is served.
DesignerEmbed:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: '/designer/{proxy+}', Method: GET}
# The CLI device-pairing page (dapier auth login).
DevicePairing:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /device, Method: GET}
AdminApi:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: '/api/admin/{proxy+}', Method: ANY}
AgentApi:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: '/api/agent/{proxy+}', Method: ANY}
OAuthCallback:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /oauth/callback, Method: GET}
AuthLogin:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /auth/login, Method: GET}
AuthCallback:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /auth/callback, Method: GET}
AuthError:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /auth/error, Method: GET}
AuthLogout:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /auth/logout, Method: GET}
Health:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /health, Method: GET}
# Public, read-only action/trigger/logic catalog (registry.catalog());
# the gateway needs the explicit route or it 404s before the router.
Catalog:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /api/catalog, Method: GET}
# The taskdeck status contract the cross-project console polls.
# Bearer-gated, and answered by the router before any admin gate.
OpsStatus:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: '/internal/ops/status', Method: GET}
CustomHook:
Type: HttpApi
Properties:
ApiId: !Ref Api
Path: '/hooks/custom/{source}'
Method: POST
DropboxGet:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /hooks/dropbox, Method: GET}
DropboxPost:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /hooks/dropbox, Method: POST}
YouTubeGet:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /hooks/youtube, Method: GET}
YouTubePost:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /hooks/youtube, Method: POST}
SesNotificationsGet:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /hooks/ses-notifications, Method: GET}
SesNotificationsPost:
Type: HttpApi
Properties: {ApiId: !Ref Api, Path: /hooks/ses-notifications, Method: POST}
ZoomRecordingHook:
Type: HttpApi
Properties:
ApiId: !Ref Api
Path: '/hooks/zoom/{proxy+}'
Method: POST
WebhookTriggerHook:
Type: HttpApi
Properties:
ApiId: !Ref Api
Path: '/hooks/webhook/{proxy+}'
Method: POST
TelegramTriggerHook:
Type: HttpApi
Properties:
ApiId: !Ref Api
Path: '/hooks/telegram/{proxy+}'
Method: POST
# Standalone (not inline) because the grant exists only when the token
# secret is configured; AWS::NoValue inside the function's Policies list
# does not survive SAM's template transform.
DesignerGithubTokenPolicy:
Type: AWS::IAM::Policy
Condition: HasGithubWorkflowsToken
Properties:
PolicyName: dapier-designer-github-token-read
Roles: [!Ref ApiExecutionRole]
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: secretsmanager:GetSecretValue
Resource: !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${GithubWorkflowsTokenSecret}*
EmailIngressFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: dapier.triggers.intake.email_ingress.handler
Runtime: python3.12
Architectures: [arm64]
Environment:
Variables:
# Raw objects in the legacy datamailer bucket publish the relay
# inbound-email contract (the worker rehydrates body and stages
# attachments from the raw_mime pointer); MailBucket objects keep
# the original rich envelope.
LEGACY_INBOUND_BUCKET: !Ref LegacyInboundMailBucketName
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt EventQueue.QueueName
- S3ReadPolicy:
BucketName: !Sub ${AWS::StackName}-mail-${AWS::AccountId}
- S3ReadPolicy:
BucketName: !Ref LegacyInboundMailBucketName
Events:
MailStored:
Type: S3
Properties:
Bucket: !Ref MailBucket
Events: s3:ObjectCreated:*
YouTubeSubscriptionFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: src.dapier.triggers.intake.youtube_subscriptions.handler
Runtime: python3.12
Architectures: [arm64]
Environment:
Variables:
YOUTUBE_CALLBACK_URL: !Sub https://${DomainName}/hooks/youtube
YOUTUBE_WEBHOOK_SECRET_ID: !Ref YouTubeWebhookSecret
Policies:
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Ref YouTubeWebhookSecret
# all_workflows reads the managed definitions plus operator triggers.
- DynamoDBReadPolicy:
TableName: !Ref PublishedWorkflowsTable
- DynamoDBReadPolicy:
TableName: !Ref HookTriggersTable
- DynamoDBReadPolicy:
TableName: !Ref ScheduleTriggersTable
- DynamoDBReadPolicy:
TableName: !Ref PollTriggersTable
Events:
Renewal:
Type: Schedule
Properties:
Schedule: rate(4 days)
Enabled: true
YouTubeWebhookSecret:
Type: AWS::SecretsManager::Secret
Properties:
Description: WebSub callback signing secret for Dapier YouTube notifications
GenerateSecretString:
PasswordLength: 48
ExcludePunctuation: true
DapierAdminSecret:
Type: AWS::SecretsManager::Secret
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
Name: !Sub ${AWS::StackName}/admin
Description: Signing key for Dapier console session cookies
GenerateSecretString:
SecretStringTemplate: '{"username":"admin"}'
GenerateStringKey: password
PasswordLength: 24
ExcludePunctuation: true
WorkerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: src.dapier.engine.worker.handler
Runtime: python3.12
Architectures: [arm64]
Layers:
- Ref: JsRuntimeLayer
Timeout: 60
MemorySize: 512
Environment:
Variables:
YOUTUBE_WEBHOOK_SECRET_ID: !Ref YouTubeWebhookSecret
CONNECTIONS_TABLE: !Ref ConnectionsTable
DAPIER_EMAIL_SENDER: !Ref EmailSender
# Configuration set attached to every workflow send
# (engine.actions.email) so SES reports bounce/complaint feedback
# into the ses-notifications hook; empty sends untagged.
SES_CONFIGURATION_SET: !Ref SesConfigurationSet
# Staging bucket for attachment parts rehydrated from Relay's
# slim inbound events (connectors.ingress._stage_attachments).
MAIL_BUCKET: !Ref MailBucket
TASK_USAGE_TABLE: !Ref TaskUsageTable
PAID_API_USAGE_TABLE: !Ref PaidApiUsageTable
STORAGE_TABLE: !Ref StorageTable
DIGESTS_TABLE: !Ref DigestsTable
Policies:
- Statement:
Effect: Allow
Action: sts:AssumeRole
Resource: !Ref AwsAssumableRoleArns
- Statement:
# Feeds EmailEventsQuietAlarm: one datapoint per email event the
# engine consumes, so twelve quiet hours page the alarm topic.
Effect: Allow
Action: [cloudwatch:PutMetricData]
Resource: '*'
- AWSSecretsManagerGetSecretValuePolicy: {SecretArn: '*'}
# Outbound identity for verified Anthropic LLM connections. Only the worker
# may mint these tokens; the Anthropic rule pins this role's exact ARN.
- Statement:
Sid: WorkerAnthropicIdentityToken
Effect: Allow
Action: [sts:GetWebIdentityToken]
Resource: '*'
Condition:
ForAllValues:StringEquals:
sts:IdentityTokenAudience: [https://api.anthropic.com]
'Null':
sts:IdentityTokenAudience: 'false'
StringEquals:
sts:SigningAlgorithm: RS256
NumericLessThanEquals:
sts:DurationSeconds: 900
- Statement:
Effect: Allow
Action: [ses:SendEmail, ses:SendRawEmail]
Resource: '*'
- Statement:
Effect: Allow
Action: [dynamodb:GetItem]
Resource: !GetAtt CredentialsTable.Arn
# Provider tokens expire during unattended runs. The worker persists
# version-conditional refreshes, but cannot edit operator credentials.
- Statement:
Sid: WorkerOAuthCredentialRefresh
Effect: Allow
Action: [dynamodb:PutItem]
Resource: !GetAtt CredentialsTable.Arn
Condition:
ForAllValues:StringLike:
dynamodb:LeadingKeys: ["oauth#*"]
- Statement:
Effect: Allow
Action: [dynamodb:PutItem]
Resource: !GetAtt PaidApiUsageTable.Arn
- DynamoDBCrudPolicy:
TableName: !Ref TaskUsageTable
- Statement:
Effect: Allow
Action: [dynamodb:GetItem, dynamodb:PutItem, dynamodb:DeleteItem,
dynamodb:Query]
Resource: !GetAtt StorageTable.Arn
- Statement:
Effect: Allow
Action: [dynamodb:GetItem, dynamodb:PutItem, dynamodb:DeleteItem,
dynamodb:UpdateItem, dynamodb:Query]
Resource: !GetAtt DigestsTable.Arn
- DynamoDBReadPolicy:
TableName: !Ref ConnectionsTable
- DynamoDBReadPolicy:
TableName: !Ref HookTriggersTable
- DynamoDBCrudPolicy:
TableName: !Ref TriggerInboxTable
# Crud, not Read: each fire is noted on its schedule's history.
- DynamoDBCrudPolicy:
TableName: !Ref ScheduleTriggersTable
- DynamoDBReadPolicy:
TableName: !Ref PollTriggersTable
- DynamoDBReadPolicy:
TableName: !Ref PublishedWorkflowsTable
- DynamoDBCrudPolicy:
TableName: !Ref CursorsTable
# A run parked on a long delay re-enters through the event queue
# (worker._enqueue_resume): the worker itself enqueues the parked
# continuation, hop by hop for waits past SQS's 15-minute cap.
- SQSSendMessagePolicy:
QueueName: !GetAtt EventQueue.QueueName
- SQSSendMessagePolicy:
QueueName: !GetAtt RenderQueue.QueueName
- SQSSendMessagePolicy:
QueueName: !GetAtt HostQueue.QueueName
- DynamoDBCrudPolicy:
TableName: !Ref HostTasksTable
- DynamoDBReadPolicy:
TableName: !Ref EmailFromTable
- DynamoDBCrudPolicy:
TableName: !Ref ExecutionsTable
- S3CrudPolicy:
BucketName: !Ref RenderArtifactsBucket
- Statement:
Effect: Allow
Action: s3:PutObject
Resource: !Sub '${ZoomTranscriptsBucket.Arn}/*'
- S3CrudPolicy:
BucketName: !Ref DataOpsEmailDocumentsBucket
- S3ReadPolicy:
BucketName: !Ref DatamailerInboundBucketName
- S3ReadPolicy:
BucketName: !Ref LegacyInboundMailBucketName
- S3CrudPolicy:
BucketName: !Ref MailBucket
Events:
Queue:
Type: SQS
Properties:
Queue: !GetAtt EventQueue.Arn
BatchSize: 10
FunctionResponseTypes: [ReportBatchItemFailures]
# Standalone (not inline) because schedule rules are created and deleted at
# runtime; the permission is provisioned once for the whole rule family so
# trigger saves only ever call the Events API.
ScheduleInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref WorkerFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !Sub arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/dapier-schedule-*
# Same bargain as ScheduleInvokePermission, for the poll trigger rule family.
PollInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref WorkerFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn: !Sub arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/dapier-poll-*
DropboxResolverFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: src.dapier.triggers.intake.dropbox_resolver.handler
Runtime: python3.12
Architectures: [arm64]
Timeout: 120
MemorySize: 256
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt EventQueue.QueueName
- DynamoDBCrudPolicy:
TableName: !Ref ConnectionsTable
- DynamoDBCrudPolicy:
TableName: !Ref CursorsTable
- Statement:
Effect: Allow
Action: [dynamodb:GetItem, dynamodb:PutItem]
Resource: !GetAtt CredentialsTable.Arn
Events:
Notifications:
Type: SQS
Properties:
Queue: !GetAtt DropboxQueue.Arn
BatchSize: 5
FunctionResponseTypes: [ReportBatchItemFailures]
# No Lambda subscribes. dapier worker long-polls this queue.
HostQueue:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 120
RedrivePolicy:
deadLetterTargetArn: !GetAtt HostDeadLetterQueue.Arn
maxReceiveCount: 5
HostDeadLetterQueue:
Type: AWS::SQS::Queue
EventQueue:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 180
RedrivePolicy:
deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
maxReceiveCount: 5
EventQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues: [!Ref EventQueue]
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AllowInboundEmailEvents
Effect: Allow
Principal: {Service: sns.amazonaws.com}
Action: sqs:SendMessage
Resource: !GetAtt EventQueue.Arn
Condition:
ArnEquals:
aws:SourceArn:
- !Ref InboundEmailTopicArn
- !Ref LegacyInboundEmailTopicArn
DeadLetterQueue:
Type: AWS::SQS::Queue
AlarmTopic:
Type: AWS::SNS::Topic
# Email intake has no queue backlog to alarm on when it breaks upstream:
# nothing arrives, so every queue metric reads zero and healthy. The
# worker emits one EmailEventsReceived datapoint per email event it
# consumes; twelve quiet hours page the operator.
EmailEventsQuietAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: >
No email event reached the workflow engine for 12 hours — email
intake is dark somewhere between SES receipt, the raw-mail bucket,
the intake Lambda, and the event queue.
Namespace: Dapier/Triggers
MetricName: EmailEventsReceived
Statistic: Sum
Period: 3600
EvaluationPeriods: 12
Threshold: 1
ComparisonOperator: LessThanThreshold
TreatMissingData: breaching
AlarmActions: [!Ref AlarmTopic]
OKActions: [!Ref AlarmTopic]
AlarmNotifyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: src.dapier.alarm_notify.handler
Runtime: python3.12
Architectures: [arm64]
Timeout: 30
MemorySize: 128
Environment:
Variables:
DAPIER_EMAIL_SENDER: !Ref EmailSender
Policies:
- Statement:
Effect: Allow
Action: [ses:SendEmail]
Resource: '*'
Events:
Alarm:
Type: SNS
Properties:
Topic: !Ref AlarmTopic
DropboxQueue:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 600
RedrivePolicy:
deadLetterTargetArn: !GetAtt DropboxDeadLetterQueue.Arn
maxReceiveCount: 5