I have covered many different questions just like this on here and have still not come to a conclusion of what the problem is.
I have two API's Classroom API Invites API
Both API's use FastAPI with Magnum for the handler. I am using SAM CLI to generate the build and deploy locally via docker. The Classrooms API works and runs just fine locally. There is no issue with the build, running locally, ect. I copied the working Classrooms-API and rebuilt the Invites-API and try running the same exact way. I am getting the below issue. I am struggling to understand what the problem is because it's an exact replica of a working example
user@my-device-name invites-api % sam local start-api
Mounting Function at http://127.0.0.1:3000$default [X-AMAZON-APIGATEWAY-ANY-METHOD]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2022-04-18 19:56:23 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Invoking app.handler (python3.9)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-python3.9:rapid-1.46.0-x86_64.
Mounting /Users/user/Documents/Projects/prj/apis/invites-api/.aws-sam/build/Function as /var/task:ro,delegated inside runtime container
START RequestId: 77cc785c-1499-4575-8bbc-0d60d49a01ca Version: $LATEST
Traceback (most recent call last): Unable to import module 'app': No module named 'app'
END RequestId: 77cc785c-1499-4575-8bbc-0d60d49a01ca
REPORT RequestId: 77cc785c-1499-4575-8bbc-0d60d49a01ca Init Duration: 0.88 ms Duration: 521.27 ms Billed Duration: 522 ms Memory Size: 128 MB Max Memory Used: 128 MB
No Content-Type given. Defaulting to 'application/json'.
Classroom API structure
classroom-api/
/src
/app
/models, controllers, schemas, ect
__init__.py <-- handler is defined here
requirements.txt
template.yaml
Classroom __init__.py
import time
from mangum import Mangum
from fastapi import FastAPI, Request
from fastapi.exceptions import RequestValidationError
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from app.controller.api import api_router
app = FastAPI(title="Classrooms API", root_path="/api/v1", openapi_url="/openapi.json")
... (app exceptions and middleware defined)
app.include_router(api_router)
handler = Mangum(app)
Classroom template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Sam Template
Globals:
Function:
Timeout: 30
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
FunctionName: "Classrooms-API-V1"
MemorySize: 128
CodeUri: src
Handler: app.handler
Runtime: python3.9
Events:
Api:
Type: HttpApi
Properties:
ApiId: !Ref Api
Api:
Type: AWS::Serverless::HttpApi
Outputs:
ApiUrl:
Description: URL of your API endpoint
Value:
Fn::Sub: 'https://${Api}.execute-api.${AWS::Region}.${AWS::URLSuffix}/'
Invites API structure
invites-api/
/src
/app
/models, controllers, schemas, ect
__init__.py <-- handler is defined here
requirements.txt
template.yaml
Invites API __init__.py
import time
from mangum import Mangum
from fastapi import FastAPI, Request
from fastapi.exceptions import RequestValidationError
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from app.controller.api import api_router
app = FastAPI(title="Invites API", root_path="/api/v1", openapi_url="/openapi.json")
... (app exceptions and middleware defined)
app.include_router(api_router)
handler = Mangum(app)
Invites API template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Sam Template
Globals:
Function:
Timeout: 30
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
FunctionName: "Invite-API-V1"
MemorySize: 128
CodeUri: src
Handler: app.handler
Runtime: python3.9
Events:
Api:
Type: HttpApi
Properties:
ApiId: !Ref Api
Api:
Type: AWS::Serverless::HttpApi
Outputs:
ApiUrl:
Description: URL of your API endpoint
Value:
Fn::Sub: 'https://${Api}.execute-api.${AWS::Region}.${AWS::URLSuffix}/'