-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
145 lines (139 loc) · 4.61 KB
/
serverless.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
service: gitmetrix
provider:
name: aws
runtime: nodejs20.x
architecture: arm64
stage: ${opt:stage, 'prod'}
region: ${opt:region, 'eu-north-1'}
memorySize: ${opt:memory, 1024}
timeout: ${opt:timeout, 10}
logRetentionInDays: ${opt:logRetentionInDays, 7}
versionFunctions: false
httpApi:
cors: true
#disableDefaultEndpoint: true
authorizers:
AuthorizerAdd:
functionName: AuthorizerAdd
resultTtlInSeconds: ${self:custom.config.aws.apiGatewayCachingTtl.${self:provider.stage}, '0'}
identitySource:
- $request.querystring.authorization
type: request
enableSimpleResponses: true
AuthorizerGet:
functionName: AuthorizerGet
resultTtlInSeconds: ${self:custom.config.aws.apiGatewayCachingTtl.${self:provider.stage}, '0'}
identitySource:
- $request.header.Authorization
type: request
enableSimpleResponses: true
deploymentBucket:
blockPublicAccess: true
maxPreviousDeploymentArtifacts: 5
serverSideEncryption: AES256
stackTags:
Usage: ${self:service}
tags:
Usage: ${self:service}
apiGateway:
minimumCompressionSize: 1024
plugins:
- serverless-esbuild
- serverless-offline
- serverless-iam-roles-per-function
package:
individually: true
custom:
config:
apiKey: ${opt:apiKey, '6d0bf792-ad5a-49af-9ff5-78fbc15a3e8a'} # Add your desired valid API key here or use the default
awsAccountNumber: ${opt:awsAccountNumber, '123412341234'} # Set this to your value if you want to use a fallback value
maxDateRange: ${opt:maxDateRange, '30'}
maxLifeInDays: ${opt:maxLifeInDays, '90'}
tableName: ${self:service}-${self:provider.stage}
aws:
databaseArn: arn:aws:dynamodb:${aws:region}:${self:custom.config.awsAccountNumber}:table/${self:custom.config.tableName}
apiGatewayCachingTtl:
prod: ${opt:apiGatewayCachingTtlProd, '30'}
dev: ${opt:apiGatewayCachingTtlDev, '0'}
test: ${opt:apiGatewayCachingTtlTest, '0'}
apiGatewayCachingTtlValue: ${self:custom.aws.apiGatewayCachingTtl.${self:provider.stage}, self:custom.aws.apiGatewayCachingTtl.test} # See: https://forum.serverless.com/t/api-gateway-custom-authorizer-caching-problems/4695
esbuild:
bundle: true
minify: true
functions:
AuthorizerAdd:
handler: src/infrastructure/authorizers/Authorizer.handler
description: ${self:service} authorizer for adding metrics
environment:
API_KEY: ${self:custom.config.apiKey}
AuthorizerGet:
handler: src/infrastructure/authorizers/Authorizer.handler
description: ${self:service} authorizer for getting metrics
environment:
API_KEY: ${self:custom.config.apiKey}
AddMetrics:
handler: src/infrastructure/adapters/web/AddMetrics.handler
description: Add a metric into Gitmetrix
events:
- httpApi:
method: POST
path: /metrics
authorizer:
name: AuthorizerAdd
iamRoleStatements:
- Effect: 'Allow'
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
Resource: ${self:custom.aws.databaseArn}
environment:
REGION: ${aws:region}
TABLE_NAME: ${self:custom.config.tableName}
MAX_DATE_RANGE: ${self:custom.config.maxDateRange}
MAX_LIFE_IN_DAYS: ${self:custom.config.maxLifeInDays}
GetMetrics:
handler: src/infrastructure/adapters/web/GetMetrics.handler
description: Get metrics from Gitmetrix
events:
- httpApi:
method: GET
path: /metrics
authorizer:
name: AuthorizerGet
iamRoleStatements:
- Effect: 'Allow'
Action:
- dynamodb:PutItem
- dynamodb:Query
Resource: ${self:custom.aws.databaseArn}
environment:
REGION: ${aws:region}
TABLE_NAME: ${self:custom.config.tableName}
MAX_DATE_RANGE: ${self:custom.config.maxDateRange}
resources:
Resources:
# DynamoDB
GitmetrixTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
TableName: ${self:custom.config.tableName}
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
- AttributeName: sk
AttributeType: S
KeySchema:
- AttributeName: pk
KeyType: HASH
- AttributeName: sk
KeyType: RANGE
TimeToLiveSpecification:
AttributeName: expiresAt
Enabled: true
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
BillingMode: PAY_PER_REQUEST
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true