-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
139 lines (126 loc) · 3.25 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
service: questions-api
frameworkVersion: '3'
useDotenv: true
plugins:
- serverless-plugin-typescript
- serverless-dynamodb-local
- serverless-offline
- serverless-plugin-resource-tagging
provider:
name: aws
runtime: nodejs18.x
region: eu-west-2
timeout: 30
memorySize: 256
logRetentionInDays: 90
environment:
DYNAMODB_QUESTIONS_TABLE: ${sls:stage}-${self:service}-${env:QUESTIONS_TABLE}
S3_FILES_BUCKET: ${sls:stage}-${self:service}-files
apiGateway:
shouldStartNameWithService: true
stackTags:
ENVIRONMENT: "${sls:stage}"
PROJECT: "${self:service}"
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- "Fn::GetAtt": [ QuestionsDynamoDbTable, Arn ]
- "Fn::Join": ['/', ["Fn::GetAtt": [ QuestionsDynamoDbTable, Arn ], 'index', 'CategoryIdIndex']]
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
Resource:
Fn::Join:
- ''
- - 'arn:aws:s3:::'
- Ref: S3FilesBucket
- '/*'
functions:
create:
handler: src/handlers/create.create
events:
- http:
path: questions
method: post
cors: true
list:
handler: src/handlers/list.list
events:
- http:
path: questions
method: get
cors: true
get:
handler: src/handlers/get.get
events:
- http:
path: questions/{id}
method: get
cors: true
update:
handler: src/handlers/update.update
events:
- http:
path: questions/{id}
method: put
cors: true
upload:
handler: src/handlers/upload.getSignedUrl
events:
- http:
path: questions/{id}/start-upload
method: put
cors: true
download:
handler: src/handlers/download.getSignedUrl
events:
- http:
path: questions/{id}/download
method: get
cors: true
resources:
Resources:
QuestionsDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: categoryId
AttributeType: N
- AttributeName: createdAt
AttributeType: N
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
- IndexName: CategoryIdIndex
KeySchema:
- AttributeName: categoryId
KeyType: HASH
- AttributeName: createdAt
KeyType: RANGE
Projection:
ProjectionType: 'ALL'
TableName: ${self:provider.environment.DYNAMODB_QUESTIONS_TABLE}
S3FilesBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: ${self:provider.environment.S3_FILES_BUCKET}
custom:
logLevelMap:
prod: info
staging: info
logLevel: ${self:custom.logLevelMap.${sls:stage}, 'debug'}