-
Notifications
You must be signed in to change notification settings - Fork 3
/
template.yml
274 lines (259 loc) · 7.84 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
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
AWSTemplateFormatVersion: '2010-09-09'
Description: >
Serverless Inquisitor, a simple app for testing latency
between client devices, API Gateway and Lambda functions
Transform: AWS::Serverless-2016-10-31
Parameters:
StageName:
Type: String
Default: "test"
Description: API Stage name
MemorySize:
Type: Number
Default: 128
MinValue: 128
MaxValue: 3008
Description: Memory limit for the test Lambda function
ProvisionedInstances:
Type: Number
Default: 0
Description: >
Number of provisioned instances of the test Lambda function. Leave as 0 for no provisioned instances.
Conditions:
ProvisionedInstancesSet: !Not [ !Equals [0, !Ref ProvisionedInstances]]
Resources:
RegionalRestApi:
Type: AWS::Serverless::Api
Properties:
EndpointConfiguration: Regional
StageName: !Ref StageName
Cors:
AllowCredentials: "'true'"
AllowMethods: "'GET,OPTIONS,POST'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
AllowOrigin: "'*'"
MaxAge: "'600'"
EdgeRestApi:
Type: AWS::Serverless::Api
Properties:
EndpointConfiguration: Edge
StageName: !Ref StageName
Cors:
AllowCredentials: "'true'"
AllowMethods: "'GET,OPTIONS,POST'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
AllowOrigin: "'*'"
MaxAge: "'600'"
ApiUsagePlan:
Type: 'AWS::ApiGateway::UsagePlan'
DependsOn:
- RegionalRestApiStage
- EdgeRestApiStage
Properties:
ApiStages:
- ApiId: !Ref RegionalRestApi
Stage: !Ref StageName
- ApiId: !Ref EdgeRestApi
Stage: !Ref StageName
Quota:
Limit: 10000
Period: DAY
Throttle:
BurstLimit: 2000
RateLimit: 1000
UsagePlanName: !Sub "${StageName}Plan"
ApiKey:
Type: 'AWS::ApiGateway::ApiKey'
DependsOn:
- RegionalRestApiStage
- EdgeRestApiStage
Properties:
Enabled: true
StageKeys:
- RestApiId: !Ref RegionalRestApi
StageName: !Ref StageName
- RestApiId: !Ref EdgeRestApi
StageName: !Ref StageName
UsagePlanKey:
Type: 'AWS::ApiGateway::UsagePlanKey'
Properties:
KeyId: !Ref ApiKey
KeyType: API_KEY
UsagePlanId: !Ref ApiUsagePlan
RegionalHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
StageName: !Ref StageName
CorsConfiguration:
AllowMethods:
- GET
- OPTIONS
- POST
AllowHeaders:
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
AllowOrigins:
- '*'
MaxAge: 600
SyncTestFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: lambda.handler
Runtime: nodejs12.x
CodeUri: sync-test-function
MemorySize: !Ref MemorySize
AutoPublishAlias: live
ProvisionedConcurrencyConfig:
!If
- ProvisionedInstancesSet
- ProvisionedConcurrentExecutions: !Ref ProvisionedInstances
- Ref: AWS::NoValue
Events:
RegionalApiGet:
Type: Api
Properties:
Method: get
Path: /regional
RestApiId: !Ref RegionalRestApi
RegionalApiPost:
Type: Api
Properties:
Method: post
Path: /regional
RestApiId: !Ref RegionalRestApi
EdgeApiGet:
Type: Api
Properties:
Method: get
Path: /edge
RestApiId: !Ref EdgeRestApi
EdgeApiPost:
Type: Api
Properties:
Method: post
Path: /edge
RestApiId: !Ref EdgeRestApi
RegionalApiKeyGet:
Type: Api
Properties:
Method: get
Path: /regional-key
RestApiId: !Ref RegionalRestApi
Auth:
ApiKeyRequired: true
RegionalHttpApiPost:
Type: HttpApi
Properties:
ApiId: !Ref RegionalHttpApi
Method: post
Path: /regional
RegionalHttpApiGet:
Type: HttpApi
Properties:
ApiId: !Ref RegionalHttpApi
Method: get
Path: /regional
IdentityPool:
Type: "AWS::Cognito::IdentityPool"
Properties:
AllowUnauthenticatedIdentities: true
CognitoUnAuthorizedRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Federated: "cognito-identity.amazonaws.com"
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud": !Ref IdentityPool
"ForAnyValue:StringLike":
"cognito-identity.amazonaws.com:amr": unauthenticated
Policies:
- PolicyName: "CognitoUnauthorizedPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "cognito-sync:*"
Resource: "*"
- Effect: "Allow"
Action: "lambda:InvokeFunction"
Resource:
- !Ref SyncTestFunction.Alias
IdentityPoolRoleMapping:
Type: "AWS::Cognito::IdentityPoolRoleAttachment"
Properties:
IdentityPoolId: !Ref IdentityPool
Roles:
authenticated: !GetAtt CognitoUnAuthorizedRole.Arn
unauthenticated: !GetAtt CognitoUnAuthorizedRole.Arn
WebsiteBucket:
Type: AWS::S3::Bucket
Properties:
WebsiteConfiguration:
IndexDocument: index.html
DeploymentLayer:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:375983427419:applications/deploy-to-s3
SemanticVersion: 2.4.2
SiteSource:
Type: AWS::Serverless::Function
Properties:
Layers:
- !GetAtt DeploymentLayer.Outputs.Arn
CodeUri: web-site/
AutoPublishAlias: live
Runtime: python3.6
Handler: deployer.resource_handler
Timeout: 600
Policies:
- S3FullAccessPolicy:
BucketName: !Ref WebsiteBucket
DeploymentResource:
Type: AWS::CloudFormation::CustomResource
Properties:
ServiceToken: !GetAtt SiteSource.Arn
Version: !Ref "SiteSource.Version"
TargetBucket: !Ref WebsiteBucket
Acl: 'public-read'
CacheControlMaxAge: 600
Substitutions:
FilePattern: "*.html"
Values:
StackId: !Ref AWS::StackId
Region: !Ref AWS::Region
IdentityPoolId: !Ref IdentityPool
ApiKeyId: !Ref ApiKey
RegionalApiUrl: !Sub "https://${RegionalRestApi}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/regional"
RegionalKeyApiUrl: !Sub "https://${RegionalRestApi}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/regional-key"
EdgeApiUrl: !Sub "https://${EdgeRestApi}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/edge"
RegionalHttpApiUrl: !Sub "https://${RegionalHttpApi}.execute-api.${AWS::Region}.amazonaws.com/${StageName}/regional"
SyncTestFunction: !Ref SyncTestFunction.Alias
AppVersion: 1.2.0
Outputs:
WebSiteUrl:
Value: !GetAtt WebsiteBucket.WebsiteURL
Metadata:
AWS::ServerlessRepo::Application:
Name: inquisitor
Description: >
Serverless Inquisitor, a simple app for testing latency
between client devices, API Gateway and Lambda functions
Author: Gojko Adzic
SpdxLicenseId: MIT
LicenseUrl: LICENSE.txt
ReadmeUrl: README-SAR.md
Labels: ['testing']
HomePageUrl: https://github.com/serverlesspub/inquisitor
SemanticVersion: 1.2.0
SourceCodeUrl: https://github.com/serverlesspub/inquisitor