Skip to content

Commit 500b5ae

Browse files
committed
Fix the deployment
1 parent 158e289 commit 500b5ae

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

app.py renamed to api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ def cats():
88

99
@app.route("/dogs/<id>")
1010
def dog(id):
11-
return "Dog"
11+
return "Dog"
12+
13+
@app.route("/health")
14+
def health():
15+
return { "status": "Success" }

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"license": "ISC",
1111
"dependencies": {
1212
"serverless": "^2.64.1",
13-
"serverless-python-requirements": "^5.1.1"
13+
"serverless-python-requirements": "^5.1.1",
14+
"serverless-wsgi": "^2.0.2"
1415
}
1516
}

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pytest
2-
Flask==1.0.2
2+
Flask
3+
requests

serverless.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,46 @@ provider:
2424
# - "Ref" : "setupname"
2525
# - '/*'
2626

27+
28+
29+
2730
functions:
2831
api:
2932
handler: wsgi_handler.handler
3033
events:
3134
- http: ANY /
3235
- http: ANY /{proxy+}
3336
handler:
34-
handler: handler.handler
37+
handler: handler.hello
3538
timeout: 300
3639
memorySize: 512
3740
events:
3841
- schedule: cron(0/15 18-21 ? * * *)
42+
warm_up:
43+
handler: warm_up.handler
44+
timeout: 300
45+
memorySize: 512
46+
events:
47+
- schedule: cron(0/5 * ? * * *)
48+
environment:
49+
BASE_URL: { "Fn::Join" : ["", [" https://", { "Ref" : "ApiGatewayRestApi" }, ".execute-api.${self:custom.region}.amazonaws.com/${self:custom.stage}" ] ] }
3950

4051
plugins:
4152
- serverless-python-requirements
4253
- serverless-wsgi
4354

4455
custom:
56+
stage: ${opt:stage, self:provider.stage}
57+
region: ${opt:region, self:provider.region}
4558
pythonRequirements:
4659
dockerizePip: true
4760
wsgi:
4861
app: api.app
4962

63+
package:
64+
patterns:
65+
- '!node_modules/**'
66+
5067
# resources:
5168
# Resources:
5269
# tableName:

warm_up.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
import json
4+
import requests
5+
6+
BASE_URL = os.environ.get("BASE_URL")
7+
8+
def handler(event, context):
9+
health_url = f"{BASE_URL}/health"
10+
11+
resp = requests.get(health_url).json()
12+
13+
return {
14+
"BaseURL": health_url,
15+
"HealthResponse": resp
16+
}

0 commit comments

Comments
 (0)