-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
153 lines (139 loc) · 3.97 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
146
147
148
149
150
151
152
153
org: photonadmin
app: photonranch
service: ptrdata
plugins:
- serverless-dotenv-plugin
- serverless-plugin-existing-s3
- serverless-python-requirements
package:
patterns:
- '!venv/**'
- '!node_modules/**'
- '!notebooks/**'
- '!__pycache__/**'
- '!.pytest_cache/**'
- '!.env'
- '!database.ini'
- '!lambda_tests.txt'
- '!lambda_service/tests/**'
custom:
# This is to reduce the size of the deployment
pythonRequirements:
dockerizePip: non-linux
dockerFile: serverless-deploy-helpers/Dockerfile
strip: false
slim: true
noDeploy:
- pytest
- pytest-env
provider:
name: aws
region: us-east-1
runtime: python3.7
lambdaHashingVersion: 20201221
environment:
REGION: ${self:provider.region}
BUCKET_NAME: photonranch-001
EXPIRATION_TABLE: data-expiration-tracker
UPLOADS_LOG_TABLE: recent-uploads-log
UPLOADS_LOG_TTL_HOURS: 48
INFO_IMAGES_TABLE: info-images
INFO_IMAGES_TTL_HOURS: 48
JPG_THUMBNAIL_HEIGHT_PX: 128
iam:
role:
name: ptrdata-default-iam-role
statements:
- Effect: Allow
Action:
- s3:GetBucketNotification
- s3:PutBucketNotification
- s3:ListBucket
- s3:DeleteObject
- s3:GetObject
- s3:PutObject
Resource:
- "arn:aws:s3:::${self:provider.environment.BUCKET_NAME}"
- "arn:aws:s3:::${self:provider.environment.BUCKET_NAME}/*"
- Effect: Allow
Action:
- ssm:GetParameter
Resource: "arn:aws:ssm:${self:provider.region}:*:parameter/*"
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:GetItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:Scan
- dynamodb:Query
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource:
Fn::Join:
- ""
- - "arn:aws:dynamodb:"
- ${self:provider.region}
- ":*:*"
- Effect: Allow
Action:
- sqs:SendMessage
- sqs:GetQueueUrl
Resource:
- "arn:aws:sqs:${self:provider.region}:*:*"
functions:
insert_data:
handler: lambda_service/insert_data.handle_s3_object_created
layers:
- arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-SQLAlchemy:18
- arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-Pillow:10
events:
- s3:
bucket: ${self:provider.environment.BUCKET_NAME}
event: s3:ObjectCreated:*
rules:
- prefix: data/
existing: true
insertInfoImage:
handler: lambda_service/info_images.handle_info_image_created
events:
- s3:
bucket: ${self:provider.environment.BUCKET_NAME}
event: s3:ObjectCreated:*
rules:
- prefix: info-images/
existing: true
removeExpiredData:
handler: lambda_service/expirations.remove_expired_data_handler
events:
- stream:
type: dynamodb
batchSize: 1
arn:
Fn::GetAtt:
- dataExpirationTracker
- StreamArn
resources:
Resources:
dataExpirationTracker:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.EXPIRATION_TABLE}
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
KeySchema:
- AttributeName: pk
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TimeToLiveSpecification:
AttributeName: expiration_timestamp_s
Enabled: true
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES