-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserverless.yml
115 lines (107 loc) · 3.12 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
# For full config options, check the docs:
# docs.serverless.com
service: rating-service
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: ">=1.1.0 <2.0.0"
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, file(serverless.env.yml):stage}
region: ${opt:region, file(serverless.env.yml):region}
profile: ${opt:profile, file(serverless.env.yml):profile}
project: rating-service
memorySize: 256 # MB
timeout: 10 # Seconds
cfLogs: true,
environment:
SERVERLESS_PROJECT: ${self:provider.project}
SERVERLESS_REGION: ${self:provider.region}
SERVERLESS_STAGE: ${self:provider.stage}
RATING_TABLE: ${self:service}-${self:provider.stage}-rating
RATING_TABLE_INDEX_CONTENT_ID: content_id_index
iamRoleStatements:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:DeleteLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:${self:provider.region}:*:*
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- Fn::GetAtt:
- RatingTable
- Arn
- arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.RATING_TABLE}/index/${self:provider.environment.RATING_TABLE_INDEX_CONTENT_ID}
package:
exclude:
- node_modules/**
- test/**
resources:
Resources:
RatingTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete # ensure to change to Retain once in prod. Otherwise, the DB will start fresh on every deploy
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
-
AttributeName: contentId
AttributeType: N
KeySchema:
-
AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.RATING_TABLE}
GlobalSecondaryIndexes:
-
IndexName: ${self:provider.environment.RATING_TABLE_INDEX_CONTENT_ID}
KeySchema:
-
AttributeName: contentId
KeyType: HASH
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
functions:
create-rating:
handler: handler/rating.create
timeout: 6
events:
- http:
path: rating
method: POST
cors: true
get-rating-by-content:
handler: handler/rating.getRatingByContent
timeout: 10
memory: 512
events:
- http:
path: rating/content/{contentId}
method: GET
cors: true
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
serverless-offline:
port: 4000
plugins:
- serverless-offline
- serverless-webpack