-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
138 lines (129 loc) · 3.79 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
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: Dynamic Scheduler
Parameters:
EventBusName:
Type: String
Description: "The event bus name to connect the integration to"
Default: "default"
Globals:
Function:
Runtime: "nodejs16.x"
CodeUri: "./src"
Timeout: 6
Tracing: Active
Environment:
Variables:
EVENT_BUS_NAME: !Ref EventBusName
EVENT_SOURCE: !Sub "com.${AWS::StackName}"
Resources:
ScheduleTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref AWS::StackName
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: "id"
AttributeType: "S"
KeySchema:
- AttributeName: "id"
KeyType: "HASH"
StartFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-start"
Handler: events/start.handler
Environment:
Variables:
STATE_MACHINE_ARN: !Ref SchedulerStateMachine
TABLE_NAME: !Ref ScheduleTable
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref ScheduleTable
- EventBridgePutEventsPolicy:
EventBusName: !Ref EventBusName
- Statement:
- Effect: Allow
Action:
- states:DescribeExecution
- states:StopExecution
- states:StartExecution
Resource: '*'
Events:
EventReceived:
Type: EventBridgeRule
Properties:
EventBusName: !Ref EventBusName
Pattern:
source:
- !Sub "com.${AWS::StackName}"
detail-type:
- "Schedule Start"
TickFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-tick"
Handler: events/tick.handler
Environment:
Variables:
STATE_MACHINE_ARN: !Ref SchedulerStateMachine
TABLE_NAME: !Ref ScheduleTable
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref ScheduleTable
- EventBridgePutEventsPolicy:
EventBusName: !Ref EventBusName
- Statement:
- Effect: Allow
Action:
- states:StartExecution
Resource: '*'
Events:
EventReceived:
Type: EventBridgeRule
Properties:
EventBusName: !Ref EventBusName
Pattern:
source:
- !Sub "org.${AWS::StackName}"
detail-type:
- "Schedule Tick"
StopFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-stop"
Handler: events/stop.handler
Environment:
Variables:
STATE_MACHINE_ARN: !Ref SchedulerStateMachine
TABLE_NAME: !Ref ScheduleTable
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref ScheduleTable
- EventBridgePutEventsPolicy:
EventBusName: !Ref EventBusName
- Statement:
- Effect: Allow
Action:
- states:DescribeExecution
- states:StopExecution
Resource: '*'
Events:
EventReceived:
Type: EventBridgeRule
Properties:
EventBusName: !Ref EventBusName
Pattern:
detail-type:
- "Schedule Stop"
SchedulerStateMachine:
Type: AWS::Serverless::StateMachine
Properties:
Name: !Ref AWS::StackName
DefinitionUri: states/scheduler.asl.yaml
DefinitionSubstitutions:
EventBusName: !Ref EventBusName
EventSource: !Sub "org.${AWS::StackName}"
Policies:
- EventBridgePutEventsPolicy:
EventBusName: !Ref EventBusName