-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
serverless.yml
124 lines (118 loc) · 3.58 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
service: catalogist
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: false
disableDefaultEndpoint: true
authorizers:
Authorizer:
functionName: Authorizer
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, 'jdhop8dyn98aHJGa873hljajs'} # 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
tableName: ${self:service}-${self:provider.stage}
aws:
databaseArn: arn:aws:dynamodb:${aws:region}:${self:custom.config.awsAccountNumber}:table/${self:custom.config.tableName}
apiGatewayCachingTtl:
prod: 30
dev: 0
test: 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:
Authorizer:
handler: src/infrastructure/authorizers/Authorizer.handler
description: ${self:service} authorizer
environment:
API_KEY: ${self:custom.config.apiKey}
CreateRecord:
handler: src/infrastructure/adapters/web/CreateRecord.handler
description: Create record
events:
- httpApi:
method: POST
path: /record
authorizer:
name: Authorizer
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:PutItem
Resource: ${self:custom.aws.databaseArn}
environment:
REGION: ${aws:region}
TABLE_NAME: ${self:custom.config.tableName}
GetRecord:
handler: src/infrastructure/adapters/web/GetRecord.handler
description: Get record
events:
- httpApi:
method: GET
path: /record
authorizer:
name: Authorizer
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:Query
Resource: ${self:custom.aws.databaseArn}
environment:
REGION: ${aws:region}
TABLE_NAME: ${self:custom.config.tableName}
resources:
Resources:
# DynamoDB configuration
CatalogistTable:
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
BillingMode: PAY_PER_REQUEST
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true