-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
262 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file is auto generated by SAM CLI build command | ||
|
||
[function_build_definitions.447f7c9f-164f-4a26-bf6a-38da6b6910b6] | ||
codeuri = "/Users/cycrpto/Desktop/tuk_sandol_team/sandol" | ||
runtime = "python3.11" | ||
architecture = "x86_64" | ||
handler = "app.handler" | ||
manifest_hash = "" | ||
packagetype = "Zip" | ||
functions = ["FastApiFunction"] | ||
|
||
[layer_build_definitions] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"resource": "/{proxy+}", | ||
"path": "/", | ||
"httpMethod": "GET", | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"queryStringParameters": {}, | ||
"pathParameters": { | ||
"proxy": "/" | ||
}, | ||
"stageVariables": null, | ||
"requestContext": { | ||
"resourcePath": "/{proxy+}", | ||
"httpMethod": "GET", | ||
"path": "/prod/" | ||
}, | ||
"body": null, | ||
"isBase64Encoded": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"resource": "/{proxy+}", | ||
"path": "/meal/view", | ||
"httpMethod": "POST", | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"queryStringParameters": {}, | ||
"pathParameters": { | ||
"proxy": "meal/view" | ||
}, | ||
"stageVariables": null, | ||
"requestContext": { | ||
"resourcePath": "/{proxy+}", | ||
"httpMethod": "POST", | ||
"path": "/prod/meal/view" | ||
}, | ||
"body": "{\"intent\":{\"id\":\"viqkzodj54puyo8ai5e6m49w\",\"name\":\"블록 이름\"},\"userRequest\":{\"timezone\":\"Asia/Seoul\",\"params\":{\"ignoreMe\":\"true\"},\"block\":{\"id\":\"viqkzodj54puyo8ai5e6m49w\",\"name\":\"블록 이름\"},\"utterance\":\"발화 내용\",\"lang\":null,\"user\":{\"id\":\"702912\",\"type\":\"accountId\",\"properties\":{}}},\"bot\":{\"id\":\"5e0f180affa74800014bd33d\",\"name\":\"봇 이름\"},\"action\":{\"name\":\"u0o68ejcea\",\"clientExtra\":null,\"params\":{\"meal\":\"view\"},\"id\":\"lwnhtra9gidojk68b6xr41o4\",\"detailParams\":{\"meal\":{\"origin\":\"view\",\"value\":\"view\",\"groupName\":\"\"}}}}", | ||
"isBase64Encoded": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Resources: | ||
FastApiFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: app.handler | ||
Runtime: python3.11 | ||
CodeUri: s3://sandol-deploy-bucket/773a22c99daca4bf37a9bcfe7c23d54f | ||
MemorySize: 128 | ||
Timeout: 300 | ||
Policies: | ||
- AWSLambdaBasicExecutionRole | ||
Environment: | ||
Variables: | ||
ENV: prod | ||
Events: | ||
ApiEvent: | ||
Type: Api | ||
Properties: | ||
Path: /{proxy+} | ||
Method: ANY | ||
Metadata: | ||
SamResourceId: FastApiFunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# More information about the configuration file can be found here: | ||
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html | ||
version = 0.1 | ||
|
||
[default] | ||
[default.global.parameters] | ||
stack_name = "untitled" | ||
|
||
[default.build.parameters] | ||
parallel = true | ||
|
||
[default.validate.parameters] | ||
lint = true | ||
|
||
[default.deploy.parameters] | ||
capabilities = "CAPABILITY_IAM" | ||
confirm_changeset = true | ||
#resolve_s3 = true | ||
resolve_image_repos = true | ||
|
||
[default.package.parameters] | ||
#resolve_s3 = true | ||
|
||
[default.sync.parameters] | ||
watch = true | ||
|
||
[default.local_start_api.parameters] | ||
warm_containers = "EAGER" | ||
|
||
[default.local_start_lambda.parameters] | ||
warm_containers = "EAGER" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Use the official Python image from the Docker Hub | ||
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11 | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy the requirements.txt file and install dependencies | ||
COPY requirements.txt /app/ | ||
RUN pip install --no-cache-dir -r /app/requirements.txt | ||
|
||
# Copy the entire 'sandol' directory to the working directory | ||
COPY . /app | ||
|
||
# Expose port 80 | ||
EXPOSE 80 | ||
|
||
# Command to run the FastAPI application | ||
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
"""Sandol의 메인 애플리케이션 파일입니다.""" | ||
from fastapi import FastAPI, HTTPException, Request, status # noqa: F401 # pylint: disable=W0611 | ||
from fastapi.responses import JSONResponse # noqa: F401 | ||
|
||
from sandol.api_server.meal import meal_api | ||
from sandol.api_server.utils import error_message | ||
from sandol.api_server.kakao.response import KakaoResponse | ||
|
||
from fastapi import FastAPI, Request | ||
from fastapi.responses import JSONResponse | ||
from mangum import Mangum | ||
from api_server.meal import meal_api | ||
from api_server.utils import error_message | ||
from api_server.kakao.response import KakaoResponse | ||
|
||
app = FastAPI() | ||
app.include_router(meal_api) | ||
|
||
|
||
@app.exception_handler(Exception) | ||
async def http_exception_handler(request: Request, exc: Exception): # pylint: disable=W0613 | ||
async def http_exception_handler(request: Request, exc: Exception): | ||
return JSONResponse( | ||
KakaoResponse().add_component(error_message(exc)).get_dict() | ||
) | ||
|
||
|
||
@app.get("/") | ||
async def root(): | ||
"""루트 페이지입니다.""" | ||
return "Hello Sandol" | ||
return {"test": "Hello Sandol"} | ||
|
||
handler = Mangum(app) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Resources: | ||
FastApiFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: app.handler | ||
Runtime: python3.11 | ||
CodeUri: ./sandol | ||
MemorySize: 128 | ||
Timeout: 300 | ||
Policies: | ||
- AWSLambdaBasicExecutionRole | ||
Environment: | ||
Variables: | ||
ENV: "prod" | ||
Events: | ||
ApiEvent: | ||
Type: Api | ||
Properties: | ||
Path: /{proxy+} | ||
Method: ANY |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
from hello_world import app | ||
|
||
|
||
@pytest.fixture() | ||
def apigw_event(): | ||
""" Generates API GW Event""" | ||
|
||
return { | ||
"body": '{ "test": "body"}', | ||
"resource": "/{proxy+}", | ||
"requestContext": { | ||
"resourceId": "123456", | ||
"apiId": "1234567890", | ||
"resourcePath": "/{proxy+}", | ||
"httpMethod": "POST", | ||
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", | ||
"accountId": "123456789012", | ||
"identity": { | ||
"apiKey": "", | ||
"userArn": "", | ||
"cognitoAuthenticationType": "", | ||
"caller": "", | ||
"userAgent": "Custom User Agent String", | ||
"user": "", | ||
"cognitoIdentityPoolId": "", | ||
"cognitoIdentityId": "", | ||
"cognitoAuthenticationProvider": "", | ||
"sourceIp": "127.0.0.1", | ||
"accountId": "", | ||
}, | ||
"stage": "prod", | ||
}, | ||
"queryStringParameters": {"foo": "bar"}, | ||
"headers": { | ||
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", | ||
"Accept-Language": "en-US,en;q=0.8", | ||
"CloudFront-Is-Desktop-Viewer": "true", | ||
"CloudFront-Is-SmartTV-Viewer": "false", | ||
"CloudFront-Is-Mobile-Viewer": "false", | ||
"X-Forwarded-For": "127.0.0.1, 127.0.0.2", | ||
"CloudFront-Viewer-Country": "US", | ||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | ||
"Upgrade-Insecure-Requests": "1", | ||
"X-Forwarded-Port": "443", | ||
"Host": "1234567890.execute-api.us-east-1.amazonaws.com", | ||
"X-Forwarded-Proto": "https", | ||
"X-Amz-Cf-Id": "aaaaaaaaaae3VYQb9jd-nvCd-de396Uhbp027Y2JvkCPNLmGJHqlaA==", | ||
"CloudFront-Is-Tablet-Viewer": "false", | ||
"Cache-Control": "max-age=0", | ||
"User-Agent": "Custom User Agent String", | ||
"CloudFront-Forwarded-Proto": "https", | ||
"Accept-Encoding": "gzip, deflate, sdch", | ||
}, | ||
"pathParameters": {"proxy": "/examplepath"}, | ||
"httpMethod": "POST", | ||
"stageVariables": {"baz": "qux"}, | ||
"path": "/examplepath", | ||
} | ||
|
||
|
||
def test_lambda_handler(apigw_event, mocker): | ||
|
||
ret = app.lambda_handler(apigw_event, "") | ||
data = json.loads(ret["body"]) | ||
|
||
assert ret["statusCode"] == 200 | ||
assert "message" in ret["body"] | ||
assert data["message"] == "hello world" |
This file was deleted.
Oops, something went wrong.