-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
124 lines (110 loc) · 3.43 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: instawat
provider:
name: aws
runtime: python2.7
region: us-east-1
# Set up IAM authorization for the Lambda functions. They get full access
# to the S3 bucket and DynamoDB table.
iamRoleStatements:
- Effect: Allow
Action:
- "*"
Resource:
- "arn:aws:s3:::${self:custom.bucket}/*"
- "arn:aws:dynamodb:*:*:table/instawat"
- "arn:aws:dynamodb:*:*:table/instawat/*"
# These environment variables are from the Python code to determine the
# S3 bucket and DynamoDB table to use for storage.
environment:
BUCKET_NAME: ${self:custom.bucket}
TABLE_NAME: instawat
# The serverless-wsgi plugin allows us to use Flask for the web app.
plugins:
- serverless-wsgi
# Exclude anything you do not need. A smaller package bundle means less latency
# on cold invocation.
package:
exclude:
- images/**
- node_modules/**
functions:
# PART 1: APP
app:
handler: wsgi.handler
events:
- http: ANY /
# PART 2: DOWNLOADER
downloader:
timeout: 30
handler: downloader.handler
events:
- stream:
# Listen for stream events when new items are added to DynamoDB.
type: dynamodb
# Limit the number of events to process per invocation.
batchSize: 10
arn:
Fn::GetAtt:
- InstawatTable
- StreamArn
# PART 3: THE WATIFIER
watifier:
# We'll give it some more memory/CPU as it does a bit more work.
memorySize: 512
timeout: 30
handler: watifier.handler
events:
- s3:
# This statement also creates the S3 bucket.
bucket: ${self:custom.bucket}
rules:
# Only trigger events for originals, otherwise watified photos
# would be watified, double-watified photos would be triple-watified
# and all hell would break loose.
# Your AWS bill would suffer, at the very least.
- prefix: original/
custom:
# The name of the bucket must be provided on the CLI as --bucket_name.
bucket: ${opt:bucket_name}
wsgi:
app: app.app
# This section is pretty hairy, blame CloudFormation.
resources:
Resources:
# Create a table in DynamoDB.
InstawatTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: instawat
# A list of the attributes that will be used for indexes.
AttributeDefinitions:
- AttributeName: url
AttributeType: S
- AttributeName: created_at_date
AttributeType: S
- AttributeName: created_at_time
AttributeType: N
# The url is the primary key.
KeySchema:
- AttributeName: url
KeyType: HASH
# We want to show a list of the latest wats created today. For
# this purpose, we will need a GSI that sorts by timestamp.
GlobalSecondaryIndexes:
- IndexName: created_at-index
KeySchema:
- AttributeName: created_at_date
KeyType: HASH
- AttributeName: created_at_time
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
# Stream new items to the downloader.
StreamSpecification:
StreamViewType: NEW_IMAGE