-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.yaml
93 lines (85 loc) · 3.04 KB
/
template.yaml
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
# This is the SAM template that represents the architecture of your serverless application
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html
# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: 2010-09-09
Description: >-
scaling-broccoli
# Transform section specifies one or more macros that AWS CloudFormation uses to process your template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html
Transform:
- AWS::Serverless-2016-10-31
Parameters:
MaximumSize:
Type: Number
Default: 1000
Description: '(Required) Maximum number of player ranked.'
ConstraintDescription: 'Required. Must be an integer.'
LeadersSize:
Type: Number
Default: 10
Description: '(Required) Number of player returned in the leaderboard.'
ConstraintDescription: 'Required. Must be an integer.'
# Resources declares the AWS resources that you want to include in the stack
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
Resources:
# Each Lambda function is defined by properties:
# https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
getLeaderboard:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/get-leaderboard.getLeaderboard
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 100
Description: Get leaderboard a player position if uuid is provided
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref LeaderboardTable
Environment:
Variables:
LEADERBOARD_TABLE: !Ref LeaderboardTable
MAXIMUM_SIZE: !Ref MaximumSize
LEADERS_SIZE: !Ref LeadersSize
Events:
Api:
Type: Api
Properties:
Path: /{uuid}
Method: GET
updateLeaderboardFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/update-leaderboard.updateLeaderboard
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 100
Description: Update leaderboard with a score and return it
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref LeaderboardTable
Environment:
Variables:
LEADERBOARD_TABLE: !Ref LeaderboardTable
MAXIMUM_SIZE: !Ref MaximumSize
LEADERS_SIZE: !Ref LeadersSize
Events:
Api:
Type: Api
Properties:
Path: /
Method: POST
LeaderboardTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: id
Type: String
Outputs:
WebEndpoint:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"