-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.yml
More file actions
310 lines (285 loc) · 8.67 KB
/
Copy pathstack.yml
File metadata and controls
310 lines (285 loc) · 8.67 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
---
# Validate this template with
#
# aws cloudformation validate-template --template-body "file://$(pwd)/stack.yml"
AWSTemplateFormatVersion: 2010-09-09
Parameters:
GithubOauthToken:
Description: |-
Oauth Token, see
http://docs.aws.amazon.com/codepipeline/latest/userguide/troubleshooting.html#troubleshooting-gs2
Type: String
NoEcho: true
GithubRepoOwner:
Description: Username (eg. 'brianto')
Type: String
GithubRepoName:
Description: Repository (eg. 'rekt')
Type: String
Default: rekt
GithubRepoBranch:
Description: Branch (eg. 'master')
Type: String
Default: master
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Github Repository
Parameters:
- GithubRepoOwner
- GithubRepoName
- GithubRepoBranch
- GithubOauthToken
ParameterLabels:
GithubRepoOwner:
default: Owner
GithubRepoName:
default: Repository
GithubRepoBranch:
default: Branch
GithubOauthToken:
default: Oauth Token
Outputs:
RektWebsiteURL:
Description: Website URL
Value: !GetAtt WebsiteBucket.WebsiteURL
Resources:
ReviewsTable:
Type: AWS::DynamoDB::Table
Properties:
KeySchema:
- AttributeName: id
KeyType: HASH
AttributeDefinitions:
- AttributeName: id
AttributeType: S
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
# TODO maybe add GSI for monthly queries
CommentsTable:
Type: AWS::DynamoDB::Table
Properties:
KeySchema:
- AttributeName: review
KeyType: HASH
- AttributeName: id
KeyType: RANGE
AttributeDefinitions:
- AttributeName: review
AttributeType: S
- AttributeName: id
AttributeType: S
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
# API is populated on first (CodePipeline) build
# This is only a placeholder until then
Api:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Ref AWS::StackName
Description: Backend API
MockGetMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref Api
ResourceId: !GetAtt Api.RootResourceId
HttpMethod: GET
AuthorizationType: NONE
Integration:
Type: MOCK
ApiDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId: !Ref Api
DependsOn:
- MockGetMethod
ApiStage:
Type: AWS::ApiGateway::Stage
Properties:
StageName: api
RestApiId: !Ref Api
DeploymentId: !Ref ApiDeployment
PipelineArtifactsBucket:
Type: AWS::S3::Bucket
Properties: {}
WebsiteBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
WebsiteBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref WebsiteBucket
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: "*"
Action: s3:GetObject
Resource: !Sub arn:aws:s3:::${WebsiteBucket}/*
Build:
Type: AWS::CodeBuild::Project
Properties:
Name: !Ref AWS::StackName
ServiceRole: !Ref DeployerRole
Source:
Type: CODEPIPELINE
Artifacts:
Type: CODEPIPELINE
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Type: LINUX_CONTAINER
Image: aws/codebuild/nodejs:7.0.0
EnvironmentVariables:
- Name: REKT_API_NAME
Value: !Ref AWS::StackName
- Name: REKT_API_ID
Value: !Ref Api
- Name: REKT_API_GATEWAY_ENDPOINT
Value: !Sub ${Api}.execute-api.${AWS::Region}.amazonaws.com
- Name: REKT_API_GATEWAY_STAGE
Value: !Ref ApiStage
- Name: REKT_WEBSITE_BUCKET
Value: !Ref WebsiteBucket
- Name: REKT_SERVICER_ARN
Value: !GetAtt ServicerRole.Arn
- Name: REKT_CREATE_REVIEW_LAMBDA_ARN
Value: !GetAtt CreateReviewLambda.Arn
- Name: REKT_GET_REVIEW_LAMBDA_ARN
Value: !GetAtt GetReviewLambda.Arn
TimeoutInMinutes: 30
DeployerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service:
- codebuild.amazonaws.com
- codepipeline.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSCodePipelineFullAccess
- arn:aws:iam::aws:policy/AWSCodeBuildDeveloperAccess
Policies:
- PolicyName: !Sub ${AWS::StackName}-deployer
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Resource: !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/${AWS::StackName}:*
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- Effect: Allow
Resource: !Sub arn:aws:s3:::${AWS::StackName}-*
Action:
- s3:PutObject
- s3:GetObject
- s3:GetObjectVersion
- Effect: Allow
Resource: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-*
Action: lambda:UpdateFunctionCode
- Effect: Allow
Resource: !Sub arn:aws:apigateway:${AWS::Region}::/restapis/${Api}
Action: apigateway:PUT
- Effect: Allow
Resource: !Sub arn:aws:apigateway:${AWS::Region}::/restapis/${Api}/deployments
Action: apigateway:POST
ServicerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service:
- lambda.amazonaws.com
- apigateway.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: !Sub ${AWS::StackName}-servicer
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: lambda:InvokeFunction
Resource: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-*
- Effect: Allow
Resource: !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${AWS::StackName}-*
Action:
- dynamodb:Query
- dynamodb:GetItem
- dynamodb:PutItem
CreateReviewLambda:
Type: AWS::Lambda::Function
Properties:
Runtime: nodejs4.3
Role: !GetAtt ServicerRole.Arn
Handler: CreateReview.handler
Environment:
Variables:
REKT_REVIEWS_TABLE: !Ref ReviewsTable
Code:
ZipFile: // Not Implemented
GetReviewLambda:
Type: AWS::Lambda::Function
Properties:
Runtime: nodejs4.3
Role: !GetAtt ServicerRole.Arn
Handler: GetReview.handler
Environment:
Variables:
REKT_REVIEWS_TABLE: !Ref ReviewsTable
Code:
ZipFile: // Not Implemented
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: !Ref AWS::StackName
RoleArn: !GetAtt DeployerRole.Arn
RestartExecutionOnUpdate: Yes
ArtifactStore:
Type: S3
Location: !Ref PipelineArtifactsBucket
Stages:
- Name: Source
Actions:
- Name: Download
ActionTypeId:
Category: Source
Owner: ThirdParty
Provider: GitHub
Version: 1
Configuration:
Owner: !Ref GithubRepoOwner
Repo: !Ref GithubRepoName
Branch: !Ref GithubRepoBranch
OAuthToken: !Ref GithubOauthToken
OutputArtifacts:
- Name: !Sub ${AWS::StackName}-source
- Name: Build
Actions:
- Name: Frontend
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: 1
Configuration:
ProjectName: !Ref Build
InputArtifacts:
- Name: !Sub ${AWS::StackName}-source
OutputArtifacts:
- Name: !Sub ${AWS::StackName}-dist