Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

190731 chalice

114 views

Published on

すごい広島 with Python
AWS Chalice と Janome
西本卓也
株式会社シュアルタ

Published in: Technology
  • Be the first to comment

  • Be the first to like this

190731 chalice

  1. 1. AWS Chalice と Janome 西本 卓也 @nishimotz / @24motz 株式会社シュアルタ 1
  2. 2. 自己紹介:西本 • 広島 → 早稲田大学 → 京都工芸繊維大学 → 東京大学 • 機械学習、認知科学、障害者支援 → 博士(工学) • スクリーンリーダー NVDA 日本語版 • 広島(2011年から) • リモートワーク/ソフトウェア受託開発 • 株式会社シュアルタ(2018年から) • 信号処理/自然言語/Web/組み込み/モバイル/クラウド • 活動 • WAIC / Python / こどもプログラミング 2
  3. 3. Ruby on Jets • AWS 対応サーバーレスフレームワーク • Rails のように使える • 似たものが Python にないかと思ったらあった 3
  4. 4. AWS Chalice $ python -m pip install chalice awscli httpie $ chalice --help Usage: chalice [OPTIONS] COMMAND [ARGS]... Commands: 一部略 deploy new-project url 4
  5. 5. AWS Chalice $ chalice new-project sugoiapi $ cd sugoiapi $ cat app.py from chalice import Chalice app = Chalice(app_name='sugoiapi') @app.route('/') def index(): return {'hello': 'world'} $ chalice deploy 5
  6. 6. AWS Chalice $ chalice deploy Creating deployment package. Creating IAM role: sugoiapi-dev Creating lambda function: sugoiapi-dev Creating Rest API Resources deployed: - Lambda ARN: arn:aws:lambda:**:**:function:sugoiapi-dev - Rest API URL: https://**.execute-api.**.amazonaws.com/api/ 6
  7. 7. AWS Chalice $ http `chalice url` HTTP/1.1 200 OK Content-Type: application/json { "hello": "world" } 7
  8. 8. 8
  9. 9. Janome on AWS Chalice $ cat requirements.txt janome $ cat .chalice/config.json { "version": "2.0", "app_name": "sugoiapi", "stages": { "dev": { "api_gateway_stage": "api", "lambda_memory_size": 3008 } } } 9
  10. 10. Janome on AWS Chalice def token_to_dict(t): return dict( surface=t.surface, part_of_speech=t.part_of_speech, infl_type=t.infl_type, infl_form=t.infl_form, base_form=t.base_form, reading=t.reading, phonetic=t.phonetic ) 10 @app.route('/') def index(): d = app.current_request.to_dict() qp = d.get('query_params') if not qp: return [] text = unquote(qp.get('text', '')) return [ token_to_dict(token) for token in tokenizer.tokenize(text) ] from urllib.parse import unquote from chalice import Chalice from janome.tokenizer import Tokenizer app = Chalice(app_name='sugoiapi') tokenizer = Tokenizer()
  11. 11. Janome on AWS Chalice $ python -m pip install -r requirements.txt (ローカルに janome をインストールする必要) $ chalice deploy $ http `chalice url` [] (最初は20秒くらいかかる) 11
  12. 12. Janome on AWS Chalice $ http `chalice url`?text=こんにちは世界 | jq -c [{"surface":"こんにちは","part_of_speech":"感動 詞,*,*,*","infl_type":"*","infl_form":"*","base_form":"こんにちは ","reading":"コンニチハ","phonetic":"コンニチワ"},{"surface":"世界 ","part_of_speech":"名詞,一 般,*,*","infl_type":"*","infl_form":"*","base_form":"世界","reading":" セカイ","phonetic":"セカイ"}] 12
  13. 13. 資料 • Ruby On Jets • https://rubyonjets.com/ • Janome • https://mocobeta.github.io/janome/ • Chalice • https://github.com/aws/chalice • https://www.slideshare.net/AmazonWebServicesJapan/20190619-aws- black-belt-online-seminar-dive-deep-into-aws-chalice 13

×