-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
145 lines (130 loc) · 4.63 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
frameworkVersion: "^2.11.1"
service: bibliophile
provider:
name: aws
runtime: python3.6
stage: dev
region: us-west-1
# The `readShelf` function will read and write from the `shelvedBooks` table
iamRoleStatements:
- Effect: "Allow"
Action:
- "dynamodb:Query"
- "dynamodb:Scan"
- "dynamodb:GetItem"
- "dynamodb:PutItem"
- "dynamodb:UpdateItem"
- "dynamodb:DeleteItem"
Resource:
{
"Fn::Join":
[
":",
[
"arn:aws:dynamodb:us-west-1",
{ Ref: "AWS::AccountId" },
"table/shelvedBooks",
],
],
}
# Opt in to version 3 behavior eagerly
# https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
apiGateway:
shouldStartNameWithService: true
package:
exclude:
# Exclude everything by default
# We only want to release a few modules, *not* the frontend, dev config, etc.
- "./**"
include:
# Include just the functions themselves, *not* tests
- "lambda_functions/*py"
# Package the license & readme for good measure
- "LICENSE.md"
- "README.md"
custom:
pythonRequirements:
# When deploying the image for the lambda function, use a Docker container.
# This is required because certain dependencies (`xml` & `grequests`) are C-based.
# We must compile some binaries and cannot simply publish Python source
dockerizePip: true
# Instead of looking at `requirements.txt`, generate that file using `poetry export`
usePoetry: true
customDomain:
domainName: "api.dcain.me"
certificateName: "dcain.me"
# All functions deployed to the domain name will be prefixed with this path.
# (For example, we'll have a function at https://api.dcain.me/bibliophile/read_shelf)
basePath: "bibliophile"
stage: ${self:provider.stage}
createRoute53Record: true
dynamodb:
stages:
- ${self:provider.stage}
functions:
readShelf:
handler: lambda_functions.read_shelf.handler
memorySize: 256
timeout: 30
events:
- http:
path: read_shelf
method: post
# We call this method on api.dcain.me from biblio.dcain.me
# We need to allow cross-origin requests for POSTs.
cors: true
environment:
GOODREADS_DEV_KEY: "${env:GOODREADS_DEV_KEY}"
searchCatalog:
handler: lambda_functions.search_catalog.handler
memorySize: 256
timeout: 30
events:
- http:
path: search_catalog
method: post
# We call this method on api.dcain.me from biblio.dcain.me
# We need to allow cross-origin requests for POSTs.
cors: true
resources:
Resources:
# The below YAML is just CloudFormation syntax
# Read more: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html
shelvedBooksTable:
# Reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
Type: AWS::DynamoDB::Table
Properties:
TableName: shelvedBooks
# This table should be relatively rarely used.
# Instead of paying to provision, just pay by the request.
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: userAndShelf
AttributeType: S
KeySchema:
- AttributeName: userAndShelf
KeyType: HASH
# The Goodreads API specifically requests that (most) data not be stored more than 24 hours.
# Because this tool is meant to store data from my own account, I could *probably* cache indefinitely.
# However, err on the side of caution.
#
# From https://www.goodreads.com/api/terms
#
# > You may store information obtained from the Goodreads API for up to
# # 24 hours. Goodreads needs the ability to modify, remove, and update
# > the order of our data, which caching would prevent. An exception to
# > this rule is if the data is from your own account or the
# > OAuth-authenticated users account, in which case the data may be
# > stored permanently.
TimeToLiveSpecification:
AttributeName: ttl
Enabled: true
plugins:
# This plugin allows us to include Python dependencies in the lambda function
# See `pythonRequirements`
- serverless-python-requirements
# This allows us to put the lambda functions behind a publicly accessible domain
# (We can invoke `api.dcain.me/<RouteName>` directly)
# See `customDomain`
- serverless-domain-manager
- serverless-dynamodb-local