Steven C
commited on
Commit
•
9245d19
1
Parent(s):
e868a55
Deploy to Lambda with Serverless framework
Browse files- .gitignore +2 -0
- .tool-versions +1 -0
- Dockerfile +21 -0
- package-lock.json +18 -0
- package.json +5 -0
- requirements.txt +2 -2
- serverless.yml +46 -0
.gitignore
CHANGED
@@ -1 +1,3 @@
|
|
1 |
__pycache__
|
|
|
|
|
|
1 |
__pycache__
|
2 |
+
.serverless
|
3 |
+
node_modules
|
.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
nodejs 18.14.2
|
Dockerfile
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
###########
|
2 |
+
# BUILDER #
|
3 |
+
###########
|
4 |
+
FROM public.ecr.aws/lambda/python:3.10 as builder
|
5 |
+
|
6 |
+
RUN pip3 install --upgrade pip
|
7 |
+
|
8 |
+
COPY requirements.txt .
|
9 |
+
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
|
10 |
+
|
11 |
+
#########
|
12 |
+
# FINAL #
|
13 |
+
#########
|
14 |
+
FROM public.ecr.aws/lambda/python:3.10
|
15 |
+
RUN pip3 install --upgrade pip
|
16 |
+
|
17 |
+
COPY --from=builder ${LAMBDA_TASK_ROOT} ${LAMBDA_TASK_ROOT}
|
18 |
+
|
19 |
+
COPY . ${LAMBDA_TASK_ROOT}
|
20 |
+
|
21 |
+
CMD [ "handler.lambda_handle" ]
|
package-lock.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "text_captcha_breaker",
|
3 |
+
"lockfileVersion": 3,
|
4 |
+
"requires": true,
|
5 |
+
"packages": {
|
6 |
+
"": {
|
7 |
+
"devDependencies": {
|
8 |
+
"serverless-plugin-warmup": "^8.3.0"
|
9 |
+
}
|
10 |
+
},
|
11 |
+
"node_modules/serverless-plugin-warmup": {
|
12 |
+
"version": "8.3.0",
|
13 |
+
"resolved": "https://registry.npmjs.org/serverless-plugin-warmup/-/serverless-plugin-warmup-8.3.0.tgz",
|
14 |
+
"integrity": "sha512-FBPPfY6CFdg/BAbvR+UrgHUFNgkUsQxXApSUVwoBqoaLH7amc2aCUYxYncJaD+kRLHTD4WKB0VC7QuyfUPJ+XQ==",
|
15 |
+
"dev": true
|
16 |
+
}
|
17 |
+
}
|
18 |
+
}
|
package.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"devDependencies": {
|
3 |
+
"serverless-plugin-warmup": "^8.3.0"
|
4 |
+
}
|
5 |
+
}
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
torch==1.11.0
|
2 |
torchvision==0.12.0
|
3 |
-
onnx==1.
|
4 |
-
onnxruntime==1.
|
5 |
Pillow==10.0.0
|
|
|
1 |
torch==1.11.0
|
2 |
torchvision==0.12.0
|
3 |
+
onnx==1.16.0
|
4 |
+
onnxruntime==1.16.*
|
5 |
Pillow==10.0.0
|
serverless.yml
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
org: eagle
|
2 |
+
app: text-captcha
|
3 |
+
service: text-captcha
|
4 |
+
|
5 |
+
frameworkVersion: "3"
|
6 |
+
useDotenv: true
|
7 |
+
|
8 |
+
# Note: We can set region and stag from commandline
|
9 |
+
# `$ serverless deploy --region us-east-1 --stage production`
|
10 |
+
provider:
|
11 |
+
# architecture: arm64
|
12 |
+
name: aws
|
13 |
+
region: ${opt:region, 'ap-northeast-1'}
|
14 |
+
stage: ${opt:stage, 'development'}
|
15 |
+
runtime: python3.10
|
16 |
+
logRetentionInDays: 30
|
17 |
+
ecr:
|
18 |
+
images:
|
19 |
+
appimage:
|
20 |
+
path: ./
|
21 |
+
|
22 |
+
functions:
|
23 |
+
lambda_function:
|
24 |
+
# handler: handler.lambda_function
|
25 |
+
image:
|
26 |
+
name: appimage
|
27 |
+
timeout: 90
|
28 |
+
memorySize: 4096
|
29 |
+
environment:
|
30 |
+
# On Lambda, the default location is not writable. Only the "/tmp" folder is writable. Therefore, we need to set the cache location inside "/tmp".
|
31 |
+
TORCH_HOME: /tmp/.ml_cache
|
32 |
+
# TRANSFORMERS_CACHE: /tmp/.ml_cache/huggingface
|
33 |
+
custom:
|
34 |
+
warmup:
|
35 |
+
MLModelWarmer:
|
36 |
+
enabled: true
|
37 |
+
events:
|
38 |
+
- schedule: rate(4 minutes)
|
39 |
+
concurrency: ${env:WARMER_CONCURRENCY, 2}
|
40 |
+
verbose: false
|
41 |
+
timeout: 100
|
42 |
+
payload:
|
43 |
+
source: KEEP_LAMBDA_WARM
|
44 |
+
|
45 |
+
plugins:
|
46 |
+
- serverless-plugin-warmup
|