Share
Embed
Transcript
20 slides
-
目次 今年の目標 ・状況を説明する能力を上げる ・プログラミング能力を向上 ・ITリテラシーを向上 注目している技術 ・Fast API + Serverlessで便利に
・Type Hintsで型安全性を向上したい 3 -
目次 今年の目標 ・状況を説明する能力を上げる ・プログラミング能力を向上 ・ITリテラシーを向上 注目している技術 ・Fast API + Serverlessで便利に
・Type Hintsで型安全性を向上したい 4 -
目次 今年の目標 ・状況を説明する能力を上げる ・プログラミング能力を向上 ・ITリテラシーを向上 注目している技術 ・Fast API + Serverlessで便利に
・Type Hintsで型安全性を向上したい 8 -
目次 今年の目標 ・状況を説明する能力を上げる ・プログラミング能力を向上 ・ITリテラシーを向上 注目している技術 ・Fast API + Serverlessで便利に
・Type Hintsで型安全性を向上したい 9 -
FastAPI [1] とは 2018年後半に登場したPythonフレームワーク Django, Flask, NestJS(Angular) から構想を得ている[2] OpenAPIを標準搭載 Flaskのようにシンプルに書ける
軽量なASGIフレームワーク「Starlette」 ・WebSocket ・GraphQL ・実行中のバックグラウンドタスク FastAPIのWebのコアとなっている 11 -
Serverless Pythonといえば「Zappa」も Zappa とは Amazon API Gateway AWS Lambda でWebアプリを簡単に構築、デプロイできる
Pythonのサーバーレスフレームワーク Zappaは、ASGI(非同期サーバゲートウェイ インターフェース)が実装されていないため FastAPI+Zappaは現在、使えない[3] そのため、API Gateway・Lambdaと ASGIアプリをつなぐ「Mangum[4] 」を使う -
チュートリアル [4] を体験してみる $ git clone https://github.com/iwpnd/fastapi-aws-lambda-example $ cd fastapi-aws-lambda-example
$ pip install -e . $ pip install uvicorn # or anything else that can handle ASGI $ pytest . -v $ uvicorn example_app.main:app --host 0.0.0.0 --port 8080 --reload http:/localhost:8080/docs でSwaggerUIからAPIをテストできる 参照ページ: [5]https://iwpnd.pw/articles/2020-01/deploy-fastapi-to-aws-lambda 13 -
チュートリアルを体験してみる template.ymlが有効かどうか $ sam validate デプロイするパッケージをビルドする $ sam build --use-container
--debug アプリケーションをパッケージ化してS3にアップロード(事前にバケット作成済み) $ sam package --s3-bucket my-travis-deployment-bucket --output-template-file out.yml --region eu-west-1 デプロイ $ sam deploy --template-file out.yml --stack-name example-stack-name --region eu-west-1 --no-fail-on-empty-changeset --capabilities CAPABILITY_IAM 14 -
チュートリアルを体験してみる curl -X GET "https://xxxxxxxx.execute-api.eu-west-1.amazonaws.com/prod/api /v1/example" -H "accept: application/json" https://xxxxxxxx.execute-api.eu-west-1.amazonaws.com/prod
にAPIがデプロイ されている FastAPI + Serverlessで 素早くAPIサーバをデプロイ出来る 15 -
目次 今年の目標 ・状況を説明する能力を上げる ・プログラミング能力を向上 ・ITリテラシーを向上 注目している技術 ・Fast API + Serverlessで便利に
・Type Hintsで型安全性を向上したい 16 -
参考文献 FastAPIドキュメント [1] https://fastapi.tiangolo.com/ 代替ツールから受けたインスピレーションと比較 [2] https://fastapi.tiangolo.com/ja/alternatives/ Zappa + FastApi?
[3] https://github.com/tiangolo/fastapi/issues/1020 Mangum [4] https://mangum.io/ How to continuously deploy a fastAPI to AWS Lambda with AWS SAM [5] https://iwpnd.pw/articles/2020-01/deploy-fastapi-to-aws-lambda 実践!!Python型入門(Type Hints) [6] https://qiita.com/papi_tokei/items/2a309d313bc6fc5661c3 20