Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今年の目標と注目技術

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Tonoyama Tonoyama
January 15, 2021

 今年の目標と注目技術

はんなりPython、2021はこれをやる!! LT会

Avatar for Tonoyama

Tonoyama

January 15, 2021
Tweet

More Decks by Tonoyama

Other Decks in Technology

Transcript

  1. FastAPI [1] とは 2018年後半に登場したPythonフレームワーク Django, Flask, NestJS(Angular) から構想を得ている[2] OpenAPIを標準搭載 Flaskのようにシンプルに書ける

    軽量なASGIフレームワーク「Starlette」 ・WebSocket ・GraphQL ・実行中のバックグラウンドタスク FastAPIのWebのコアとなっている 11
  2. Serverless Pythonといえば「Zappa」も Zappa とは Amazon API Gateway AWS Lambda でWebアプリを簡単に構築、デプロイできる

    Pythonのサーバーレスフレームワーク Zappaは、ASGI(非同期サーバゲートウェイ インターフェース)が実装されていないため FastAPI+Zappaは現在、使えない[3] そのため、API Gateway・Lambdaと ASGIアプリをつなぐ「Mangum[4] 」を使う
  3. チュートリアル [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
  4. チュートリアルを体験してみる 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
  5. 参考文献 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