Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Serverless Frameworkで気軽にAPIを公開してみる?(Python3.6・ヴ...
Search
Yutaka Fujisaki
July 13, 2017
Technology
0
360
Serverless Frameworkで気軽にAPIを公開してみる?(Python3.6・ヴィジュアル系編)
ヴィジュアル系で学ぶ、Serverless Framework(Python3.6編)
Yutaka Fujisaki
July 13, 2017
Tweet
Share
More Decks by Yutaka Fujisaki
See All by Yutaka Fujisaki
2019.03.06 JBUG福岡@ヌーラボ Backlogでわかる炎上の見分け方、消し方 リビルド
yfujisaki
2
840
messaging apiとLine Payで広がるLINE Botの世界
yfujisaki
1
640
孤独に耐えるための自宅スマートホーム化のすゝめ(JAWS-UG 鹿児島 Vol.8 LT)
yfujisaki
0
580
AWS(クラウド)活用思考と機能概要
yfujisaki
0
200
起業から3年間を支えてくれたintoneとChatOps〜面倒くさいを減らして運用を楽にしよう〜
yfujisaki
0
770
マイソースファクトリーでのStripeの導入を検討してみた
yfujisaki
1
420
コミュニティで会社ができた話とクラウドでのビジネスの話
yfujisaki
0
170
Other Decks in Technology
See All in Technology
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
290
Engineering at LY Corporation
lycorp_recruit_jp
0
590
Redmine 6.0 新機能評価ガイド
vividtone
0
310
TinyGoを使ったVSCode拡張機能実装
askua
2
210
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
6
1.7k
マイベストのデータ基盤の現在と未来 / mybest-data-infra-asis-tobe
mybestinc
2
2k
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.1k
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
340
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
320
OCI Data Integration技術情報 / ocidi_technical_jp
oracle4engineer
PRO
1
2.6k
QAEチームが辿った3年 ボクらが改善業務にスクラムを選んだワケ / 20241108_cloudsign_ques23
bengo4com
0
1.3k
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
350
Featured
See All Featured
Navigating Team Friction
lara
183
14k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Building an army of robots
kneath
302
42k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Optimizing for Happiness
mojombo
376
70k
How to Ace a Technical Interview
jacobian
276
23k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Ruby is Unlike a Banana
tanoku
96
11k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Transcript
Serverless FrameworkͰ ؾܰʹAPIΛެ։ͯ͠ΈΔʁ (Python3.6ɾϰΟδϡΞϧܥฤ) 201707݄13 JAWS-UGԬ@ूஂࢁݟͤͱAWS Summit TokyoৼΓฦΒNight#5
ࣗݾհ • ౻࡚ɹ༏ • גࣜձࣾΦϧλʔϒʔε ۀࣥߦһ COO • JAWS-UGԬίΞϝϯόʔ •
͘͞ΒΫϥϒIoTԬίΞϝϯόʔ • ϰΟδϡΞϧܥେ͖28 • AWS Summitߦͬͯͳ͍ɾɾɾ
࠷ۙPythonͰϚωʔδϟʔઢͷπʔϧ࡞Γ࢝Ί·ͨ͠ https://github.com/y-fujisaki/BacklogCountToolServerless
ͯ͞ຊͷ͓
ͨͱ͑͜Μͳͪΐͬͱͨ͠ൃ͕͋ͬͨΒʁ
ొਓ() • όϯΪϟϧஉ͞Μ • ϰΟδϡΞϧܥόϯυΛ͔͚ͬͯ28ɻɻCDϑϥή खʹೖΕͳ͍ͱؾ͕͢·ͳ͍ɺےۚೖΓɻதೋප͕࣏ ͠ͳ͍ • ͱ͋ΔCOOͳΤϯδχΞ͞Μ •
AWSͱAzureνϣτͰ͖Δɻ࠷ۙPythonͰπʔϧॻ͘ͷ͕ ͓ؾʹ͍Γ
͋Δͷձ • όϯΪϟϧஉʣϰΟδϡΞϧܥόϯυͷൃചΧϨϯμʔɺ ࣗ༝ʹѻ͑ΔΑ͏ͳσʔλཉ͍͠ͳ͊ • ΤϯδχΞʣϒϥϯυΤοΫεͷαΠτʹൃചΧϨϯμʔ ͕͔͋ͬͨΒεΫϨΠϐϯάͨ͠Β͍͚Δ͔ • όϯΪϟϧஉʣͦΕͩʂʂ
ɿϒϥϯυΤοΫε ାʹ͋ΔϰΟδϡΞϧܥCDઐళɻϝδϟʔόϯυͰຬͰ ͖ͳ͘ͳͬͨਓ͕࣍ʹߦͬͯΈΔ͓ళ http://www.brand-x.jp/
εΫϨΠϐϯάͯ͠Έͨ ݩϖʔδ http://www.brand-x.jp/page/38
εΫϨΠϐϯάͯ͠Έͨ https://github.com/y-fujisaki/vkei • Python • Beautiful Soup(http://kondou.com/BS4/)ͰHTML͔Βରͷ ΧϨϯμʔ෦Λऔಘ • σʔλΛগ͠ܗ
• JSONͰฦ͢Α͏ʹͯ͠Έͨ
JSON [ [ "date", "2017-8-3" ], [ "artist", "C4" ],
[ "title", " ULTIMATE BEST ALBUM [-S A G A-] " ], [ "media", "CD" ], [ "price", "¥3,800" ] ],
͋Δͷձͦͷ̎ • όϯΪϟϧஉʣ͍͍ͪͪεΫϦϓτୟ͘ͷΊΜͲ͍ɺͳΜͱ ͔ͯ͠ • ΤϯδχΞʣ͠Ό͋ͳ͍ɾɾɾLambdaͰ͓͏͔ɾɾɾ ͤʂྲྀߦΓͷServerless FrameworkͰͬͨΖʂ
Serverless Framework • ֤छΫϥυͷSeverlessΞʔΩςΫνϟͰbuild & deploy auto-scaling, event-driven functions.ͳͲΛૢ࡞͢ΔCLIπʔ ϧ
• https://github.com/serverless/serverless • ڥߏஙࢀߟࢿྉ:҆৺҆ఆͷΫϥεϝιου༷ϒϩά ࠓ͔Β࢝ΊΔServerless FrameworkͰ؆୯Lambda։ൃڥͷߏங http://dev.classmethod.jp/cloud/aws/easy-deploy-of-lambda-with-serverless- framework/
͍ํ(ςϯϓϨʔτσϑΥϧτ࣮ߦ࣌) # ʲςϯϓϨʔτ࡞ʳ sls create -t aws-python3 -p vkeicalendar cd
vkeicalendar/ # ʲσϓϩΠʳ sls deploy # ʲςετ:AWS্Ϧιʔε࣮ߦʳ sls invoke -f hello # ʲআʳ sls remove
ςϯϓϨʔτ͕༻ҙ͞Ε͍ͯΔϥϯλΠϜ • aws-python • aws-nodejs • aws-python • aws-java-maven •
aws-java-gradle • aws-scala-sbt • aws-csharp
Serverless FrameworkͰ ࡞ͬͨPythonεΫϦϓτΛ ಈ͔ͯ͠ΈΔ
࡞ۀͷྲྀΕ
ϓϩδΣΫτ࡞ sls create -t aws-python3 -p vkeicalendar cd vkeicalendar/
serverless-python-requirementsΠϯετʔϧ • PGͰඞཁͳPythonύοέʔδϦετ(requirements.txt)Λσ ϓϩΠ࣌ͷύοέʔδʹؚΊΔϓϥάΠϯ npm install --save serverless-python-requirements
PluginͰಡΈࠐΉύοέʔδϦετΛ࡞ (requirements.txt) beautifulsoup4 datetime python-dateutil retry urlopen
serverless.ymlΛ࿔Δ service: slsVkei # ςϯϓϨʔτΛ࡞ͨ͠ͱ͖ʹࢦఆͨ͠ͷ provider: name: aws runtime: python3.6
# aws-python3ͱࢦఆ͢Δͱ3.6ʹɺͳ͍ͱ2.7ʹͳΔ region: ap-northeast-1 # ౦ژϦʔδϣϯʹมߋ plugins: - serverless-python-requirements #ϓϥάΠϯࢦఆ functions: calendar: # Serverless FrameworkͰѻ͏໊ؔʢςετ࣌ʹ༻ʣ handler: vkei.calendar # ϑΝΠϧ໊(vkei.py)ɿLambdaϑΝϯΫγϣϯ໊(def calendar) events: - http: path: vcalendar # api gatewayϦιʔε໊ method: get # ࠓճgetͷΈ cors: true # ઃఆ͠ͳ͍ͱଞ͔Βར༻Ͱ͖ͳ͍
εΫϦϓτΛҠ২͢Δ import json from dateutil.relativedelta import relativedelta from retry import
retry from urllib.request import urlopen from bs4 import BeautifulSoup from datetime import datetime, date, timedelta def calendar(event, context): body = getVcalendar() response = { "statusCode": 200, # SPAͰѻ͏ͨΊɺϨεϙϯεϔομʔʹԼهՃ͑Δ "headers" : {"Access-Control-Allow-Origin" : "*"}, "body": body } return response ## Ճʂ ## ϰΟδϡΞϧܥΧϨϯμʔΛಡΈࠐΜͰJSONԽ def getVcalendar(): ɾɾɾ ɾɾɾ
ग़དྷͨͷ͕ͪ͜Βʢ̏ΫοΩϯάܗࣜʣ • https://github.com/y-fujisaki/vkeiJAWSFUKUOKA20170713
σϓϩΠ͢Δ y-fujisaki-MBP:slsVkei y-fujisaki$ sls deploy Serverless: Installing required Python packages
for runtime python3.6... Serverless: Linking required Python packages... Serverless: Packaging service... Serverless: Unlinking required Python packages... Serverless: Creating Stack... Serverless: Checking Stack create progress... ..... Serverless: Stack create finished... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Uploading service .zip file to S3 (4 MB)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... .................................. Serverless: Stack update finished... Service Information service: slsVkei stage: dev region: ap-northeast-1 api keys: None endpoints: GET - https://xxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/dev/vcalendar functions: hello: slsVkei-dev-hello
Ͱ͖ͨʂʂʂʢͣʣ
͋Δͷձͦͷ3 • ΤϯδχΞʣ͜ΕͰऔΕΔΑ͏ʹͳͬͨͰʂʂ • όϯΪϟϧஉʣόϯυ໊ൃചͰߜΓ͜ΊΔΑ͏ʹͯ͠ʂ • ΤϯδχΞʣɾɾɾ
ଓ͘
serverless frameworkͷϝϦοτ • ίϚϯυ̍ൃͰσϓϩΠɾআʂ • ϩʔΧϧσόοάͰ͖Δʢͣɾɾɾࣗͷڥ͍·ίέΔ ͆ʣ • serverlessෳͷαʔϏεͷ߹ͤͱͳΓɺίʔυ Build+Deployͷཧ͕όϥόϥʹͳΓ͕ͪͳͷΛճආͰ͖Δ
• ServerlessΞʔΩςΫνϟͷΊΜͲ͍͘͞ॾʑͷσϝϦοτ ໘ΛݶΓͳܰ͘ݮͰ͖Δ
Serverless FrameworkͰؾܰʹ LambdaΛ͓͏ʂ