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
400
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
950
messaging apiとLine Payで広がるLINE Botの世界
yfujisaki
1
680
孤独に耐えるための自宅スマートホーム化のすゝめ(JAWS-UG 鹿児島 Vol.8 LT)
yfujisaki
0
650
AWS(クラウド)活用思考と機能概要
yfujisaki
0
240
起業から3年間を支えてくれたintoneとChatOps〜面倒くさいを減らして運用を楽にしよう〜
yfujisaki
0
820
マイソースファクトリーでのStripeの導入を検討してみた
yfujisaki
1
460
コミュニティで会社ができた話とクラウドでのビジネスの話
yfujisaki
0
190
Other Decks in Technology
See All in Technology
PHPでWebブラウザのレンダリングエンジンを実装する
dip_tech
PRO
0
200
Yamla: Rustでつくるリアルタイム性を追求した機械学習基盤 / Yamla: A Rust-Based Machine Learning Platform Pursuing Real-Time Capabilities
lycorptech_jp
PRO
2
110
地図も、未来も、オープンに。 〜OSGeo.JPとFOSS4Gのご紹介〜
wata909
0
110
LinkX_GitHubを基点にした_AI時代のプロジェクトマネジメント.pdf
iotcomjpadmin
0
170
あなたの声を届けよう! 女性エンジニア登壇の意義とアウトプット実践ガイド #wttjp / Call for Your Voice
kondoyuko
4
420
Uniadex__公開版_20250617-AIxIoTビジネス共創ラボ_ツナガルチカラ_.pdf
iotcomjpadmin
0
160
変化する開発、進化する体系時代に適応するソフトウェアエンジニアの知識と考え方(JaSST'25 Kansai)
mizunori
1
210
VISITS_AIIoTビジネス共創ラボ登壇資料.pdf
iotcomjpadmin
0
160
Node-RED × MCP 勉強会 vol.1
1ftseabass
PRO
0
140
実践! AIエージェント導入記
1mono2prod
0
160
Postman AI エージェントビルダー最新情報
nagix
0
110
BrainPadプログラミングコンテスト記念LT会2025_社内イベント&問題解説
brainpadpr
1
160
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
How GitHub (no longer) Works
holman
314
140k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Embracing the Ebb and Flow
colly
86
4.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Docker and Python
trallard
44
3.4k
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Λ͓͏ʂ