-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudformation.yml
More file actions
268 lines (248 loc) · 6.97 KB
/
cloudformation.yml
File metadata and controls
268 lines (248 loc) · 6.97 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
AWSTemplateFormatVersion: 2010-09-09
Description: >-
Cards of Keyforge backend template
Parameters:
GithubHash:
Type: String
Resources:
# Lambda functions
GetCards:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: 'cards-keyforge'
S3Key: !Sub
- "functions/getcards-${GH}.zip"
- { GH: !Ref GithubHash }
Description: fetch card
FunctionName: getcards
Handler: getcards/main
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: go1.x
Timeout: 60
MemorySize: 512
AGWLambdaPermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref GetCards
Principal: apigateway.amazonaws.com
SourceArn: !Join
- ''
- - 'arn:aws:execute-api:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- ':'
- !Ref KeyforgeApi
- /*
ImportTTSDeck:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: 'cards-keyforge'
S3Key: !Sub
- "functions/importttsdeck-${GH}.zip"
- { GH: !Ref GithubHash }
Description: fetch tts deck
FunctionName: importttsdeck
Handler: importttsdeck/main
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: go1.x
Timeout: 60
MemorySize: 512
ImportTTSDeckPermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref ImportTTSDeck
Principal: apigateway.amazonaws.com
SourceArn: !Join
- ''
- - 'arn:aws:execute-api:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- ':'
- !Ref KeyforgeApi
- /*
RandomVaultDeck:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: 'cards-keyforge'
S3Key: !Sub
- "functions/randomvaultdeck-${GH}.zip"
- { GH: !Ref GithubHash }
Description: fetch vault random deck
FunctionName: randomvaultdeck
Handler: randomvaultdeck/main
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: go1.x
Timeout: 60
MemorySize: 512
RandomVaultDeckPermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref RandomVaultDeck
Principal: apigateway.amazonaws.com
SourceArn: !Join
- ''
- - 'arn:aws:execute-api:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- ':'
- !Ref KeyforgeApi
- /*
# Roles
LambdaExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- apigateway.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: DynamoDBAccessPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ReadOnly
Effect: Allow
Action:
- dynamodb:BatchGet*
- dynamodb:DescribeTable
- dynamodb:Get*
- dynamodb:Query
- dynamodb:Scan
Resource:
- !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/cards-*"
- !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/sets-*"
- PolicyName: S3AccessPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: s3:*
Resource:
- arn:aws:s3:::cards-keyforge
- arn:aws:s3:::cards-keyforge/*
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
ApiGatewayCloudWatchLogsRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: ApiGatewayLogsPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:DescribeLogGroups'
- 'logs:DescribeLogStreams'
- 'logs:PutLogEvents'
- 'logs:GetLogEvents'
- 'logs:FilterLogEvents'
Resource: '*'
# API GW configuration
KeyforgeApi:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: Cards of Keyforge API
EndpointConfiguration:
Types:
- REGIONAL
Description: Keyforge cards database API
FailOnWarnings: false
Body:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: !Sub
- "s3://cards-keyforge/openapi/openapi-${GH}.yaml"
- { GH: !Ref GithubHash }
ApiGatewayAccount:
Type: 'AWS::ApiGateway::Account'
Properties:
CloudWatchRoleArn: !GetAtt
- ApiGatewayCloudWatchLogsRole
- Arn
KeyforgeApiStage:
DependsOn:
- ApiGatewayAccount
Type: 'AWS::ApiGateway::Stage'
Properties:
DeploymentId: !Ref ApiDeployment
MethodSettings:
- DataTraceEnabled: true
HttpMethod: '*'
LoggingLevel: INFO
ResourcePath: /*
RestApiId: !Ref KeyforgeApi
StageName: LATEST
ApiDeployment:
Type: 'AWS::ApiGateway::Deployment'
DependsOn:
- KeyforgeApi
Properties:
RestApiId: !Ref KeyforgeApi
StageName: prod
ApiCustomDomain:
Type: AWS::ApiGateway::DomainName
Properties:
DomainName: api.cardsofkeyforge.com
EndpointConfiguration:
Types:
- REGIONAL
RegionalCertificateArn: arn:aws:acm:eu-north-1:329814883837:certificate/e980974a-5f35-4944-b61f-0745c96cdd10
SecurityPolicy: TLS_1_2
ApiMappings:
Type: AWS::ApiGatewayV2::ApiMapping
Properties:
ApiId: !Ref KeyforgeApi
DomainName: !Ref ApiCustomDomain
Stage: prod
ApiRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: Z00673343JUANBEQK3AUL
Name: api.cardsofkeyforge.com
ResourceRecords:
- !GetAtt ApiCustomDomain.RegionalDomainName
TTL: '300'
Type: CNAME
Outputs:
RootUrl:
Description: Root URL of the API gateway
Value: !Join
- ''
- - 'https://'
- !Ref KeyforgeApi
- .execute-api.
- !Ref 'AWS::Region'
- .amazonaws.com
GetCards:
Description: New function files
Value: !Sub
- functions/getcards-${GH}.zip
- { GH: !Ref GithubHash }