-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.yml
199 lines (190 loc) · 4.76 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Description: A REST API that sends commands to the CI Christmas Tree
Transform:
- 'AWS::Serverless-2016-10-31'
Parameters:
IoTTopic:
Type: String
Description: The name of the topic to allow the API to publish to (this should be the same one the Pi is listening)
Default: mytree
Resources:
IamRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: ci-api-role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: ci-api-iot-publish
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- iot:Publish
Resource:
- !Sub arn:aws:iot:${AWS::Region}:${AWS::AccountId}:topic/${IoTTopic}
- PolicyName: ci-api-cloudwatch-publish
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:PutLogEvents
- logs:CreateLogStream
- logs:TagLogGroup
- logs:PutLogEvents
- logs:CreateLogGroup
Resource: "*"
CreateBuild:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'ci-api-create-build'
Environment:
Variables:
topic: !Ref IoTTopic
Runtime: python3.7
CodeUri: app
Handler: build.create
Description: Create Build
Timeout: 10
Events:
GET:
Type: Api
Properties:
Path: /build/{buildId}/create
Method: get
Role: !GetAtt IamRole.Arn
DependsOn:
- IamRole
CreateBuildPost:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'ci-api-create-build-post'
Environment:
Variables:
topic: !Ref IoTTopic
Runtime: python3.7
CodeUri: app
Handler: build.post_create
Description: Create Build
Timeout: 10
Events:
POST:
Type: Api
Properties:
Path: /build/create
Method: post
Role: !GetAtt IamRole.Arn
DependsOn:
- IamRole
SucceedBuild:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'ci-api-succeed-build'
Environment:
Variables:
topic: !Ref IoTTopic
Runtime: python3.7
CodeUri: app
Handler: build.succeed
Description: Succeed Build
Timeout: 10
Events:
GET:
Type: Api
Properties:
Path: /build/{buildId}/succeed
Method: get
Role: !GetAtt IamRole.Arn
DependsOn:
- IamRole
SucceedBuildPost:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'ci-api-succeed-build-post'
Environment:
Variables:
topic: !Ref IoTTopic
Runtime: python3.7
CodeUri: app
Handler: build.post_succeed
Description: Succeed Build
Timeout: 10
Events:
POST:
Type: Api
Properties:
Path: /build/succeed
Method: post
Role: !GetAtt IamRole.Arn
DependsOn:
- IamRole
FailBuild:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'ci-api-fail-build'
Environment:
Variables:
topic: !Ref IoTTopic
Runtime: python3.7
CodeUri: app
Handler: build.fail
Description: Fail Build
Timeout: 10
Events:
GET:
Type: Api
Properties:
Path: /build/{buildId}/fail
Method: get
Role: !GetAtt IamRole.Arn
DependsOn:
- IamRole
FailBuildPost:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'ci-api-fail-build-post'
Environment:
Variables:
topic: !Ref IoTTopic
Runtime: python3.7
CodeUri: app
Handler: build.post_fail
Description: Fail Build
Timeout: 10
Events:
GET:
Type: Api
Properties:
Path: /build/fail
Method: post
Role: !GetAtt IamRole.Arn
DependsOn:
- IamRole
ResetBuild:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'ci-api-reset-build'
Environment:
Variables:
topic: !Ref IoTTopic
Runtime: python3.7
CodeUri: app
Handler: build.reset
Description: Reset Tree
Timeout: 10
Events:
GET:
Type: Api
Properties:
Path: /reset
Method: get
Role: !GetAtt IamRole.Arn
DependsOn:
- IamRole