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
960
messaging apiとLine Payで広がるLINE Botの世界
yfujisaki
1
690
孤独に耐えるための自宅スマートホーム化のすゝめ(JAWS-UG 鹿児島 Vol.8 LT)
yfujisaki
0
670
AWS(クラウド)活用思考と機能概要
yfujisaki
0
250
起業から3年間を支えてくれたintoneとChatOps〜面倒くさいを減らして運用を楽にしよう〜
yfujisaki
0
830
マイソースファクトリーでのStripeの導入を検討してみた
yfujisaki
1
460
コミュニティで会社ができた話とクラウドでのビジネスの話
yfujisaki
0
200
Other Decks in Technology
See All in Technology
EKS Pod Identity における推移的な session tags
z63d
1
200
サービスロボット最前線:ugoが挑むPhysical AI活用
kmatsuiugo
0
190
Yahoo!広告ビジネス基盤におけるバックエンド開発
lycorptech_jp
PRO
1
260
あなたの知らない OneDrive
murachiakira
0
230
キャリアを支え組織力を高める「多層型ふりかえり」 / 20250821 Kazuki Mori
shift_evolve
PRO
2
290
コミュニティと計画的偶発性理論 - 出会いが人生を変える / Life-Changing Encounters
soudai
PRO
7
1.3k
Goss: Faiss向けの新しい本番環境対応 Goバインディング #coefl_go_jp
bengo4com
0
1.4k
[CVPR2025論文読み会] Linguistics-aware Masked Image Modelingfor Self-supervised Scene Text Recognition
s_aiueo32
0
210
VPC Latticeのサービスエンドポイント機能を使用した複数VPCアクセス
duelist2020jp
0
170
OpenAPIから画面生成に挑戦した話
koinunopochi
0
150
プロジェクトマネジメントは不確実性との対話だ
hisashiwatanabe
0
200
LLMエージェント時代に適応した開発フロー
hiragram
1
390
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
780
What's in a price? How to price your products and services
michaelherold
246
12k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Side Projects
sachag
455
43k
Docker and Python
trallard
45
3.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
The Language of Interfaces
destraynor
160
25k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
How STYLIGHT went responsive
nonsquared
100
5.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
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Λ͓͏ʂ