Skip to content

Commit

Permalink
Lambda 전용 Docker 말아 올리도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kkanggu committed Dec 25, 2023
1 parent 41d77d1 commit 68177c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 135 deletions.
26 changes: 3 additions & 23 deletions .github/workflows/deploy-ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ name: Deploy to Amazon ECS CI/CD
on:
push:
branches:
- main
- feat/lambda-docker

env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: dev-daitssu-crawl
ECS_SERVICE: dev-daitssu-crawler
ECS_CLUSTER: dev-daitssu
ECS_TASK_DEFINITION: task-definition.json # set this to the path to your Amazon ECS task definition
# # file, e.g. .aws/task-definition.json
CONTAINER_NAME: dev-daitssu-crawl
ECR_REPOSITORY: dev-daitssu-crawl-lambda
CONTAINER_NAME: dev-daitssu-crawl-lambda
# containerDefinitions section of your task definition

jobs:
Expand Down Expand Up @@ -58,19 +54,3 @@ jobs:
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ COPY ./ /app/

RUN pip install -r requirements.txt

CMD ["python", "server.py"]
CMD ["python", "lambda_function.py"]
54 changes: 32 additions & 22 deletions server.py → lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
from fastapi import FastAPI
import uvicorn
import json
from model.req_models import *

app = FastAPI (
title="Daitssu Crawl Server",
description="다잇슈 크롤링 서버 api 문서입니다.",
version="1.0.0"
)
async def lambda_handler(event, context):
body = json.loads(event['body'])
function_name = body['function']

@app.post("/smart-campus/crawling")
async def smart_campus_controller(smart_campus_req: SmartCampusReq):
match function_name:
case "smart-campus_auth":
user_info = body['value']
result = auth_controller(user_info)
case "smart_campus":
smart_campus_req = body['value']
result = smart_campus_controller(smart_campus_req)
case "fun_system":
result = fun_system_controller()
case "ssu_catch":
result = ssu_catch_controller()
case "notice_computer":
result = computer_department_controller()
case _:
result = "Function not found"

return {
'statusCode': 200,
'body': result
}

async def auth_controller(user_info: UserInfo):
"""
현재 정상 이용 가능합니다.
"""
from smart_campus.smart_campus import smart_campus_crawling
result = smart_campus_crawling(smart_campus_req.token, smart_campus_req.student_id)
from smart_campus.auth_token import get_auth_token
result = get_auth_token(user_info)
return result

@app.post("/smart-campus/auth")
async def auth_controller(user_info: UserInfo):
async def smart_campus_controller(smart_campus_req: SmartCampusReq):
"""
현재 정상 이용 가능합니다.
"""
from smart_campus.auth_token import get_auth_token
result = get_auth_token(user_info)
from smart_campus.smart_campus import smart_campus_crawling
result = smart_campus_crawling(smart_campus_req.token, smart_campus_req.student_id)
return result

@app.get("/fun-system")

async def fun_system_controller():
"""
현재 정상 이용 가능합니다.
Expand All @@ -35,7 +50,6 @@ async def fun_system_controller():
result = fun_system_crawling()
return result

@app.get("/notice/ssu-catch")
async def ssu_catch_controller():
"""
현재 정상 이용 가능합니다.
Expand All @@ -44,14 +58,10 @@ async def ssu_catch_controller():
result = ssu_catch_crawling()
return result

@app.get("/notice/computer")
async def computer_department_controller():
"""
현재 정상 이용 가능합니다.
"""
from notice.computer import computer_department_crawling
result = computer_department_crawling()
return result

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)
89 changes: 0 additions & 89 deletions task-definition.json

This file was deleted.

0 comments on commit 68177c4

Please sign in to comment.