*** ์๋์ฝ๋ค ํ๋กฌํํธ์์ ๊ฐ์ํ๊ฒฝ ๋ง๋ค๋ฉด์ flask์ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ค์ด ๋ฐ์์ค๋ค ***
conda create -n lambda_310 python=3.10
pip install flask flask-restful mysql-connector-python psycopg2-binary passlib flask-jwt-extended email-validator flask-uploads uuid numpy pandas scikit-learn==0.23.2
node.js ๋ค์ด๋ฐ๊ธฐ
Node.js — Run JavaScript Everywhere
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
nodejs.org
Severless ํ์๊ฐ์ ํ๊ธฐ
Serverless: Zero-Friction Serverless Apps On AWS Lambda & Beyond.
Easily build auto-scaling, low-overhead applications on AWS Lambda, API Gateway, DynamoDB, and other managed services with the Serverless Framework.
www.serverless.com
Github๋ก ํ์๊ฐ์ ํ์๋๋ฐ, google๋ก ํ์ฌ๋ ๋จ
Serverless Framework ์ค์น
- cmd(๋ช ๋ นํ๋กฌํํธ) ์คํํ๊ธฐ
cd๋ก ๊นํ๋ธ๋ก ๊ฒฝ๋ก์ด๋ํ ํ์ ์ค์น (๊ณต๋ฐฑ ์ฃผ์ํ๊ธฐ)
npm install -g serverless
์์์ ์์ฑํ ์ ์ ๋ฅผ Serverless์ ์ค์ ํ๋ค
cmd์์ Github ๊ฒฝ๋ก๋ก ์ด๋ํด์ค๋ค
serverless ๋ผ๊ณ ์ ๋ ฅํ๋ค
serverless
๋ฐฉํฅํค๋ก Flask API๋ก ์ด๋ํ๋ค
๋ก๊ทธ์ธ ์ ํ
https://codebunny99.tistory.com/104
AWS IAM ์ฌ์ฉ์ ์ถ๊ฐํ๊ณ ์ธ์ฆํค ์ป๋ ๋ฐฉ๋ฒ
IAM ์ฌ์ฉ์ ์ถ๊ฐ ์ ์ฑ ์๋ 8๊ฐ ์ฒดํฌ ์์ฑํ ์ฌ์ฉ์๋ก ๋ค์ด๊ฐ์ ์ก์ธ์ค ํค(์ธ์ฆ ํค) ๋ง๋ค๊ธฐ ์ฌ์ฉํ๊ธฐ์ ์ ํฉํ ์ก์ธ์ค ํค๋ฅผ ๊ณจ๋ผ์ค๋ค .csv ํ์ผ ๋ฐ์์ฃผ๊ธฐ -> ์๋ฃ ์ฌ
codebunny99.tistory.com
๋ค์ด๋ก๋ ๋ฐ์ .csv ํ์ผ์ ์ด์ด ์ ๋ ฅํ๋ค
Enter AWS Access Key ID >> ์์ ์ Aceess key ID
Enter AWS Secret Access Key ID >> ์์ ์ Secret Access key
VSCode ์ด๊ธฐ
๊นํ๋ธ ํด๋์ aws-recipe-server ํด๋๊ฐ ์์ฑ๋์๋ค. ์ด ํด๋๋ฅผ vscode๋ก ์ด์ด์ฃผ์
์๊น ๋ง๋ ๊ฐ์ํ๊ฒฝ์ผ๋ก ์ค์ ํด์ค๋ค.
VSCode ํฐ๋ฏธ๋ cmd ์ฐฝ์์ ์ค์นํ๊ธฐ
npm install serverless-wsgi --save-dev
serverless.yml ํ์ผ ๋งจ ์๋์ ์ถ๊ฐ(์ฝ์ )ํ๊ธฐ
package:
individually: true
exclude:
- node_modules/** # node_modules ํด๋์ ๊ทธ ํ์ ๋ชจ๋ ํ์ผ ๋ฐ ๋๋ ํ ๋ฆฌ ์ ์ธ
- .git/** # .git ํด๋์ ๊ทธ ํ์ ๋ชจ๋ ํ์ผ ๋ฐ ๋๋ ํ ๋ฆฌ ์ ์ธ
- tests/** # tests ํด๋์ ๊ทธ ํ์ ๋ชจ๋ ํ์ผ ๋ฐ ๋๋ ํ ๋ฆฌ ์ ์ธ
include:
- src/** # src ํด๋์ ๊ทธ ํ์ ๋ชจ๋ ํ์ผ ๋ฐ ๋๋ ํ ๋ฆฌ ํฌํจ
- handler.py # ๋ฃจํธ ๋๋ ํ ๋ฆฌ์ handler.py ํ์ผ ํฌํจ
- config/** # config ํด๋์ ๊ทธ ํ์ ๋ชจ๋ ํ์ผ ๋ฐ ๋๋ ํ ๋ฆฌ ํฌํจ
VSCode ํฐ๋ฏธ๋ cmd ์ฐฝ์์ ์คํํ๊ธฐ
sls deploy
๊ทธ ์ ์ API๋ฅผ ๋ง๋ค์๋ recipe_server์์
(1) config.py, mysql_connection.py, utils.py๋ฅผ aws-recipe-server ๋ก ์ฎ๊ธด๋ค
(2) resources ํด๋ ์์ฒด๋ฅผ aws-recipe-server ๋ก ์ฎ๊ธด๋ค
(3) ( aws-recipe-server์ ์๋ app.py๋ฅผ ์ญ์ ํ๊ณ ) app.py๋ฅผ aws-recipe-server ๋ก ์ฎ๊ธด๋ค
=> ์ฎ๊ธด๋ค
requirements.txt์ ์ฝ์ ํ๋ค
serverless.yml์ ์์ , ์ฝ์ ํ๋ค
์ ์ฅํ๊ณ , VSCode cmd๋ก ๊ฐ์ ์ ๋ ฅํ๋ค
sls deploy
endpoints๋ฅผ copyํ๊ธฐ
Postman
๊ธฐ์กด์ ์๋ API์ ์ฃผ์๋ฅผ ๋ฃ์ด์ฃผ๋ฉด ๋์ด๋ค
'RestFul API' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
HTTP ์์ฒญ์ ์ํ ๋ณต์กํ ์์ ์ ๋จ์ํํ๋ requests ๋ผ์ด๋ธ๋ฌ๋ฆฌ (0) | 2024.05.30 |
---|---|
๊ด๋ จ ํค์๋๊ฐ ํฌํจ๋ ๋ด์ค ๊ฒ์ API ๋ง๋ค๊ธฐ (0) | 2024.05.29 |
JWT ์ธ์ฆ ํ ํฐ์ ๋ก๊ทธ์ธ ๋ง๋ฃ ์๊ฐ ์ค์ ํ๊ธฐ (0) | 2024.05.22 |
JWT(JSON WEP TOKEN) ์ํธํ ๋ก๊ทธ์์ API ๋ง๋ค๊ธฐ (0) | 2024.05.22 |
JWT(์๋ฐฉํฅ) ์ํธํ ๋ก๊ทธ์ธ API ๋ง๋ค๊ธฐ (0) | 2024.05.22 |