-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
105 lines (98 loc) · 2.92 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
# Welcome to serverless. Read the docs
# https://serverless.com/framework/docs/
# Serverless.yml is the configuration the CLI
# uses to deploy your code to your provider of choice
# The `service` block is the name of the service
service: serverless-urls
plugins:
- serverless-dynamodb-local
- serverless-offline
- serverless-stack-output
custom:
tableName: 'urls-table-${self:provider.stage}'
dynamodb:
# If you only want to use DynamoDB Local in some stages, declare them here
stages:
- dev
start:
port: 8000
inMemory: true
migrate: true
seed: true
convertEmptyValues: true
output:
file: .build/stack.json
# The `provider` block defines where your service will be deployed
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'dev'}
region: eu-west-2
environment:
URLS_TABLE: ${self:custom.tableName} # RC: Added ENV Variables to avoid hardcoded table names
AWS_DEPLOY_REGION: ${self:provider.region}
imRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:PutItem
- dynamodb:GetItem
Resource:
# RC: Removed hardcoded table ARN and replaced by cloud formation Intrinsic Function Reference.
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html
- { "Fn::GetAtt": ["UrlsDynamoDBTable", "Arn" ] }
- { "Fn::Join": [ "/", [
{ "Fn::GetAtt": ["UrlsDynamoDBTable", "Arn" ] }, "index", "ShortCodeIndex"
]]}
# The `functions` block defines what code to deploy
functions:
createUrl: # RC: Changed the name of this function to match the handler for naming convention uniformity
handler: createUrl.run
events:
- http:
path: url # RC: Changed the path to follow REST best practices
method: post
getUrl:
handler: getUrl.run
events:
- http:
path: url/{shortCode}
method: get
statistics:
handler: getStatistics.run
events:
- http:
path: statistics/{shortCode}
method: get
resources:
Resources:
UrlsDynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: ${self:custom.tableName}
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
-
AttributeName: shortCode
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
GlobalSecondaryIndexes:
-
IndexName: ShortCodeIndex
KeySchema:
-
AttributeName: shortCode
KeyType: HASH
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1