From d83d239c1454113bdcfa6c0b7bcfaec4b8408b98 Mon Sep 17 00:00:00 2001 From: Mostafa Kamal Date: Sun, 26 May 2024 01:09:34 +0600 Subject: [PATCH] workflow --- .github/workflows/sls.yml | 29 +++++++++++++++++++++++++++++ fastapi_project/main.py | 4 ++-- lambda_handler.py | 4 ---- lamda_handler.py | 6 ++++++ requirements.txt | 3 ++- serverless.yml | 15 ++++++++------- 6 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/sls.yml delete mode 100644 lambda_handler.py create mode 100644 lamda_handler.py diff --git a/.github/workflows/sls.yml b/.github/workflows/sls.yml new file mode 100644 index 0000000..31c2937 --- /dev/null +++ b/.github/workflows/sls.yml @@ -0,0 +1,29 @@ +on: + push: + branches: + - master + workflow_dispatch: + # This allows the workflow to be manually triggered + +name: Deploy master branch + +jobs: + deploy: + name: deploy + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + # Deployment of your project + - name: serverless deploy + uses: suprgames/serverless-github-action@v1.77 + with: + command: deploy + args: -v + env: + # To link with your Serverless Framework account, equivalent to login + SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} + # The AWS Credentials + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/fastapi_project/main.py b/fastapi_project/main.py index bf5873a..9688d50 100755 --- a/fastapi_project/main.py +++ b/fastapi_project/main.py @@ -21,8 +21,8 @@ def create_application(): if load_sql_project == True: print("SQL_PROJECT is enabled") # Include additional routers if LOAD_SQL_PROJECT is enabled - from fastapi_project.api.v1 import user - application.include_router(user.router) + # from fastapi_project.api.v1 import user + # application.include_router(user.router) # Add CORS middleware # In production, replace the "*" with the actual frontend URL diff --git a/lambda_handler.py b/lambda_handler.py deleted file mode 100644 index 5910bcd..0000000 --- a/lambda_handler.py +++ /dev/null @@ -1,4 +0,0 @@ -from mangum import Mangum -from fastapi_project.main import app as fastapi_app - -handler = Mangum(fastapi_app) diff --git a/lamda_handler.py b/lamda_handler.py new file mode 100644 index 0000000..9bb59c9 --- /dev/null +++ b/lamda_handler.py @@ -0,0 +1,6 @@ +from mangum import Mangum +from fastapi_project.main import app + +handler = Mangum(app) + + diff --git a/requirements.txt b/requirements.txt index 4482b06..ecf54ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -fastapi python-dotenv sqlalchemy psycopg2-binary +fastapi +uvicorn mangum \ No newline at end of file diff --git a/serverless.yml b/serverless.yml index c4b503b..5ef57fd 100644 --- a/serverless.yml +++ b/serverless.yml @@ -1,21 +1,22 @@ -org: kintaro -app: demo-app-api -service: demo-app-api +org: code4mk +app: demo-app-api-fastapi +service: demo-app-api-fastapi frameworkVersion: '3' plugins: - serverless-python-requirements + - serverless-wsgi provider: name: aws - runtime: python3.9 - region: us-west-2 + runtime: python3.11 + region: us-east-1 functions: demo_app_fastapi: - handler: lambda_handler.handler + handler: lamda_handler.handler events: - http: path: /{proxy+} method: any - +