-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·73 lines (56 loc) · 1.97 KB
/
main.py
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
#!/usr/bin/env python3
import atexit
from contextlib import asynccontextmanager
import aiobotocore.session
import uvicorn
from fastapi import FastAPI
import app.clients
import app.exception_handling
import app.logging
import settings
from app.api.v1 import avatars as avatars_v1
from app.api.v1 import clan_icons as clan_icons_v1
from app.api.v1 import profile_backgrounds as profile_backgrounds_v1
@asynccontextmanager
async def lifespan(asgi_app: FastAPI):
session = aiobotocore.session.get_session()
async with (
session.create_client(
service_name="s3",
region_name=settings.AWS_S3_REGION,
aws_access_key_id=settings.AWS_S3_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_S3_SECRET_ACCESS_KEY,
endpoint_url=settings.AWS_S3_ENDPOINT_URL,
) as app.clients.s3_client,
session.create_client(
service_name="rekognition",
region_name=settings.AWS_REKOGNITION_REGION,
aws_access_key_id=settings.AWS_REKOGNITION_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_REKOGNITION_SECRET_ACCESS_KEY,
endpoint_url=settings.AWS_REKOGNITION_ENDPOINT_URL,
) as app.clients.rekognition_client,
):
yield
asgi_app = FastAPI(lifespan=lifespan)
@asgi_app.get("/_health")
async def health():
return {"status": "ok"}
asgi_app.include_router(avatars_v1.router)
asgi_app.include_router(clan_icons_v1.router)
asgi_app.include_router(profile_backgrounds_v1.router)
def main() -> int:
app.logging.configure_logging()
app.exception_handling.hook_exception_handlers()
atexit.register(app.exception_handling.unhook_exception_handlers)
uvicorn.run(
"main:asgi_app",
reload=settings.CODE_HOTRELOAD,
server_header=False,
date_header=False,
host=settings.APP_HOST,
port=settings.APP_PORT,
access_log=False,
)
return 0
if __name__ == "__main__":
raise SystemExit(main())