@@ -19,15 +19,13 @@ Parameters:
19
19
Type : String
20
20
21
21
Resources :
22
- # AWS SAM doesn't support `Transform` in nested templates, we includes all children into main template
23
- # see https://github.com/awslabs/serverless-application-model/issues/90
24
22
# #########################
25
- # SNSStack
23
+ # SNS
26
24
# #########################
27
25
GitHubEventSNSTopic :
28
26
Type : " AWS::SNS::Topic"
29
27
# #########################
30
- # IAMStack
28
+ # IAM
31
29
# #########################
32
30
GitHubIAMUser :
33
31
Type : " AWS::IAM::User"
@@ -44,7 +42,7 @@ Resources:
44
42
Properties :
45
43
UserName : !Ref GitHubIAMUser
46
44
# #########################
47
- # GitHubWebhookStack
45
+ # GitHubWebhook(CustomResource)
48
46
# #########################
49
47
GitHubWebhookCustomResourceRole :
50
48
Type : " AWS::IAM::Role"
@@ -87,7 +85,7 @@ Resources:
87
85
Type : " Custom::GitHubWebhook"
88
86
Properties :
89
87
ServiceToken : !GetAtt GitHubWebhookCustomResource.Arn
90
- # Define all variables to re-create via `make deploy` when parameters have changed
88
+ # Define all variables to re-create GitHub's webhook configuration via `make deploy` when parameters have changed
91
89
GITHUB_TOKEN : !Ref GitHubPersonalAccessToken
92
90
GITHUB_REPOSITORY_URL : !Ref GitHubRepositoryUrl
93
91
GITHUB_TARGET_RESOURCE : !Ref GitHubTargetResource
@@ -96,7 +94,7 @@ Resources:
96
94
SNS_REGION : !Ref "AWS::Region"
97
95
SNS_TOPIC : !Ref GitHubEventSNSTopic
98
96
# #########################
99
- # LambdaStack
97
+ # Lambda (BuildStateNotifier)
100
98
# #########################
101
99
LambdaExecutionRole :
102
100
Type : " AWS::IAM::Role"
@@ -118,53 +116,36 @@ Resources:
118
116
- " logs:CreateLogStream"
119
117
- " logs:PutLogEvents"
120
118
Resource : " arn:aws:logs:*:*:*"
121
- - Effect : Allow
122
- Action :
123
- - " codebuild:StartBuild"
124
- - " codebuild:BatchGetBuilds"
125
- Resource : !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:project/${CodeBuildProjectName}"
126
- BuildDispatcher :
119
+ BuildStateNotifier :
127
120
Type : " AWS::Serverless::Function"
128
121
Properties :
129
122
Role : !GetAtt LambdaExecutionRole.Arn
130
123
Handler : index.handler
131
124
Runtime : nodejs6.10
132
- CodeUri : ./src/functions/build-dispatcher
133
- Timeout : 10
134
- MemorySize : 128
135
- Environment :
136
- Variables :
137
- CODEBUILD_PROJECT_REGION : !Ref CodeBuildRegion
138
- CODEBUILD_PROJECT_NAME : !Ref CodeBuildProjectName
139
- GITHUB_TOKEN : !Ref GitHubPersonalAccessToken
140
- GITHUB_REPOSITORY_URL : !Ref GitHubRepositoryUrl
141
- BuildResultExporter :
142
- Type : " AWS::Serverless::Function"
143
- Properties :
144
- Role : !GetAtt LambdaExecutionRole.Arn
145
- Handler : index.handler
146
- Runtime : nodejs6.10
147
- CodeUri : ./src/functions/build-result-exporter
148
- Timeout : 10
149
- MemorySize : 128
150
- BuildResultNotifier :
151
- Type : " AWS::Serverless::Function"
152
- Properties :
153
- Role : !GetAtt LambdaExecutionRole.Arn
154
- Handler : index.handler
155
- Runtime : nodejs6.10
156
- CodeUri : ./src/functions/build-result-notifier
125
+ CodeUri : ./src/functions/build-state-notifier
157
126
Timeout : 10
158
127
MemorySize : 128
159
128
Environment :
160
129
Variables :
161
130
CODEBUILD_PROJECT_REGION : !Ref CodeBuildRegion
162
131
GITHUB_TOKEN : !Ref GitHubPersonalAccessToken
163
132
GITHUB_REPOSITORY_URL : !Ref GitHubRepositoryUrl
133
+ Events :
134
+ CodeBuildStatusChange :
135
+ Type : CloudWatchEvent
136
+ Properties :
137
+ Pattern :
138
+ source :
139
+ - " aws.codebuild"
140
+ detail-type :
141
+ - !Sub " CodeBuild Build State Change"
142
+ detail :
143
+ project-name :
144
+ - !Ref CodeBuildProjectName
164
145
# #########################
165
- # StepFunctionsStack
146
+ # Lambda (WebhookHandler)
166
147
# #########################
167
- SFLambdaExecutionRole :
148
+ WebhookHandlerExecutionRole :
168
149
Type : " AWS::IAM::Role"
169
150
Properties :
170
151
AssumeRolePolicyDocument :
@@ -175,7 +156,7 @@ Resources:
175
156
Service : lambda.amazonaws.com
176
157
Action : " sts:AssumeRole"
177
158
Policies :
178
- - PolicyName : !Sub "${CodeBuildProjectName}-sf-lambda -execution-role"
159
+ - PolicyName : !Sub "${CodeBuildProjectName}-webhook-handler -execution-role"
179
160
PolicyDocument :
180
161
Statement :
181
162
- Effect : Allow
@@ -185,12 +166,13 @@ Resources:
185
166
- " logs:PutLogEvents"
186
167
Resource : " arn:aws:logs:*:*:*"
187
168
- Effect : Allow
188
- Action : " states:StartExecution"
189
- Resource : !Ref BuildStateMachine
169
+ Action :
170
+ - " codebuild:StartBuild"
171
+ Resource : !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:project/${CodeBuildProjectName}"
190
172
GitHubWebhookHandler :
191
173
Type : " AWS::Serverless::Function"
192
174
Properties :
193
- Role : !GetAtt SFLambdaExecutionRole .Arn
175
+ Role : !GetAtt WebhookHandlerExecutionRole .Arn
194
176
Handler : index.handler
195
177
Runtime : nodejs6.10
196
178
CodeUri : ./src/functions/github-webhook-handler
@@ -204,13 +186,14 @@ Resources:
204
186
Environment :
205
187
Variables :
206
188
DO_NOT_RUN : false
207
- STEP_FUNCTIONS_ARN : !Ref BuildStateMachine
208
189
CODEBUILD_PROJECT_REGION : !Ref CodeBuildRegion
190
+ CODEBUILD_PROJECT_NAME : !Ref CodeBuildProjectName
209
191
GITHUB_TOKEN : !Ref GitHubPersonalAccessToken
210
192
GITHUB_REPOSITORY_URL : !Ref GitHubRepositoryUrl
211
193
GITHUB_TARGET_RESOURCE : !Ref GitHubTargetResource
212
194
GITHUB_IGNORE_BRANCH_REGEX : !Ref GitHubIgnoreBranchRegex
213
195
BUILD_SKIPPED_BY : !Ref BuildSkippedBy
196
+ # We don't use followings anymore but they have to be kept as a workaround for an AWS SAM's bug? that CFn reports 'Circular dependency error' while updating the stack to modify the WebhookHandler's execution role.
214
197
StatesExecutionRole :
215
198
Type : " AWS::IAM::Role"
216
199
Properties :
@@ -228,7 +211,7 @@ Resources:
228
211
PolicyDocument :
229
212
Version : " 2012-10-17"
230
213
Statement :
231
- - Effect : Allow
214
+ - Effect : Deny
232
215
Action :
233
216
- " lambda:InvokeFunction"
234
217
Resource : " *"
@@ -238,37 +221,11 @@ Resources:
238
221
DefinitionString : !Sub
239
222
|-
240
223
{
241
- " StartAt " : " Dispatch Build " ,
224
+ " StartAt " : " Wait 10 Seconds " ,
242
225
" States " : {
243
- " Dispatch Build " : {
244
- " Type " : " Task" ,
245
- " Resource " : " ${BuildDispatcher.Arn}" ,
246
- " Next " : " Wait 10 Seconds"
247
- },
248
226
" Wait 10 Seconds " : {
249
227
" Type " : " Wait" ,
250
228
" Seconds " : 10,
251
- " Next " : " Export Build Result"
252
- },
253
- " Export Build Result " : {
254
- " Type " : " Task" ,
255
- " Resource " : " ${BuildResultExporter.Arn}" ,
256
- " Next " : " Test If Build Finished"
257
- },
258
- " Test If Build Finished " : {
259
- " Type " : " Choice" ,
260
- " Choices " : [
261
- {
262
- " Variable " : " $.buildComplete" ,
263
- " BooleanEquals " : true,
264
- " Next " : " Notify Build Result"
265
- }
266
- ],
267
- " Default " : " Wait 10 Seconds"
268
- },
269
- " Notify Build Result " : {
270
- " Type " : " Task" ,
271
- " Resource " : " ${BuildResultNotifier.Arn}" ,
272
229
" End " : true
273
230
}
274
231
}
0 commit comments