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
[JAWS-SG#02] 個人開発やハッカソンで役立つ、便利APIのつくりかた
Search
Keisuke Mori
May 16, 2020
Programming
0
140
[JAWS-SG#02] 個人開発やハッカソンで役立つ、便利APIのつくりかた
Keisuke Mori
May 16, 2020
Tweet
Share
More Decks by Keisuke Mori
See All by Keisuke Mori
AWSを使う上で意識しておきたい、クラウドセキュリティ超入門(駆け足版)
kkmory
1
400
rubyonjets_with_aws_for_research
kkmory
0
580
AWSで動画変換&配信基盤を作った話
kkmory
0
250
Slackであそぼ!!
kkmory
0
130
Git-study-Hackz-treasure
kkmory
1
270
飯塚ブロックチェーン勉強会 #1
kkmory
0
140
Swarm: The distributed storage platform
kkmory
1
800
Kindai_Blockchain_study01
kkmory
0
260
Other Decks in Programming
See All in Programming
#QiitaBash TDDで(自分の)開発がどう変わったか
ryosukedtomita
1
370
Comparing decimals in Swift Testing
417_72ki
0
170
Honoアップデート 2025年夏
yusukebe
0
240
State of CSS 2025
benjaminkott
1
110
レガシープロジェクトで最大限AIの恩恵を受けられるようClaude Codeを利用する
tk1351
2
140
A Gopher's Guide to Vibe Coding
danicat
0
150
令和最新版手のひらコンピュータ
koba789
13
7.8k
可変性を制する設計: 構造と振る舞いから考える概念モデリングとその実装
a_suenami
10
1.8k
フロントエンドのmonorepo化と責務分離のリアーキテクト
kajitack
2
110
Go製CLIツールをnpmで配布するには
syumai
2
1.2k
GitHub Copilotの全体像と活用のヒント AI駆動開発の最初の一歩
74th
7
2.9k
AIレビュアーをスケールさせるには / Scaling AI Reviewers
technuma
2
200
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
96
6.2k
It's Worth the Effort
3n
186
28k
Designing for Performance
lara
610
69k
Measuring & Analyzing Core Web Vitals
bluesmoon
8
560
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
Visualization
eitanlees
146
16k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
30
9.6k
Code Review Best Practice
trishagee
69
19k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Mobile First: as difficult as doing things right
swwweet
223
9.9k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
1.1k
Transcript
個人開発やハッカソンで役立つ、 便利 API のつくりかた Kindai University / Hack’z Inc. Keisuke
Mori
Keisuke Mori 近畿大学産業理工学部(福岡キャンパス) - 情報学科 4回生 - 暗号技術, ブロックチェーン, プライバシー技術
- ソフトウェア開発の演習では Cloud9 使ってました @moririn772 サーバーサイド/インフラ系 - Go, Ruby, AWS がお気に入り - JAWS-SG 運営メンバー(今日は配信担当)
ݸਓ։ൃϋοΧιϯͰཱͭɺศར API ͷͭ͘Γ͔ͨ Today’s TALK
ΰʔϧσϯΟʔΫɺԿͯ͠·͔ͨ͠ʁ Q.
A. ΦϯϥΠϯϋοΧιϯʹग़ͯ·ͨ͠ https://connpass.com/event/174573/ɹ
ͳʹ࡞ͬͨΜͰ͔͢ ☺☺ Q.
A. ͜ΜͳͷΛ࡞Γ·ͨ͠
作った背景テンプレートをタグ付けしてみんなに共有 (タグを付けて検索しやすく) A. ࡞ͬͨςϯϓϨʔτڞ༗Ͱ͖·͢
Ͳ͏ͬͯ࡞ͬͨΜͰ͔͢ Q.
A. ͜Μͳײ͡Ͱ࡞Γ·ͨ͠ Application Server Image Hosting Service Client Tag Suggestion
Service API Gateway Lambda Translate Recognition Cloud SQL ( MySQL ) Cloudfront S3 React (Next) CI/CD etc… GAE ( Go ) Ұ෦ϋοΧιϯظؒʹऴΘΓ·ͤΜͰͨ͠…
ࠓ͜͜ͷΛ͠·͢ʂ Application Server Image Hosting Service Client Tag Suggestion Service
API Gateway Lambda Translate Recognition Cloud SQL ( MySQL ) Cloudfront S3 React (Next) CI/CD etc… GAE ( Go )
ͬͨ AWS ͷαʔϏε Amazon API Gateway Amazon Rekognition AWS Lambda
Amazon Translate ؆୯ʹ API ͷ࡞, ެ։, อक, ϞχλϦϯά, อޢΛߦ͏͜ͱ͕ Ͱ͖Δ αʔόʔϨε࣮ߦڥ ͍ΖΜͳݴޠͰॻ͚Δ Ruby, Go, Python, Java … ػցֶशͷઐࣝΛඞཁͱͤͣ ը૾ಈըͷମ, إ, γʔϯ Λ ಛఆͰ͖ΔɻΧελϜϥϕϧΛɹ ͏ͱɺ෦ͷྨͳͲՄೳ χϡʔϥϧػց༁αʔϏε 54 ݴޠʹରԠ
Tag Suggestion Service … 作った背景テンプレートをタグ付けして共有 → つけられそうなタグを背景画像から推測して提示する機能
Tag Suggestion Service … Tag Suggestion Service API Gateway Lambda
Translate Recognition Client
Tag Suggestion Service … Tag Suggestion Service API Gateway Lambda
Translate Recognition Client 背景に使われている素材(既にS3にPUT済)のURLを、 エンドポイントに投げる https://~~~/default/detect-image-label?image-uri=*************
Tag Suggestion Service … Tag Suggestion Service API Gateway Lambda
Translate Rekognition Client API Gateway から Lambda に処理を流す。 Lambda関数(handrer.request_handler)を発火させ、 AWS-SDK から Rekognition のAPI を叩く。
Tag Suggestion Service … Tag Suggestion Service API Gateway Lambda
Translate Rekognition Client Rekognition の “DetectLabels” オペレーションを使用。 画像をもとにラベルが検出され、結果が返る。
Tag Suggestion Service … Tag Suggestion Service API Gateway Lambda
Translate Rekognition Client タグが英語で返ってきてしまい、UX的によくないので Amazon Translate の "Translate Text" オペレーションを 使用し、タグを 英語→日本語 に翻訳する。
Tag Suggestion Service … Tag Suggestion Service API Gateway Lambda
Translate Rekognition Client これまでが処理の全貌 あとはクライアント側にレスポンスを返すだけ。 “body” : [ “飛行機”, “輸送”, “航空機”, “旅客機”, “車両” ]
Tag Suggestion Service … Tag Suggestion Service API Gateway Lambda
Translate Rekognition Client 推測されたタグが表示される。 ユーザーはタグを選択し、テンプレートを公開する。
ͲΕ͘Β͍Ͱ࡞ͬͨΜͰ͔͢ ⏰ ⏰ Q.
A. 1࣌ؒ͘Β͍Ͱͭ͘Ε·ͨ͠ * ˎ ಈ࡞༏ઌͰ࡞ͬͨͷͰςετॻ͍ͯͳ͍͠ɺσϓϩΠZIPͰݻΊΔΓํͩ͠ɺ ɹࡶΜͬͯποίϛ͕ೖΓͦ͏Ͱ͕͢ಈ͘ͷͰϤγʂʂ ɹ ϋοΧιϯݸਓ։ൃʮಈ͘͜ͱʯ͕େͳͷͰʂʂʢݴ͍༁ʣ ɹ ͋ͱͰSAMͰ࡞Γ͠·͠ΐ͏…
ݸਓ։ൃϋοΧιϯͰཱͭɺศར API ͷͭ͘Γ͔ͨ ʙ Amazon Rekognition Λ༻ͨ͠ը૾ͷλά͚APIฤ ʙ
ιʔείʔυ༧Ί༻ҙ͓͖ͯ͠·ͨ͠ $ git clone \ https://github.com/moririn772/tag-suggestion-api.git $ #ͱ͍͏ͷෆͳͷͰɺGitHubϦϙδτϦެ։ͯ͠·͢
Bundle install $ cd $ bundle install —path=vendor/bundle
Ͱ͖·ͨ͠ʂ $ ll > 5 13 10:47 Gemfile > 5
13 10:17 Gemfile.lock > 5 13 11:18 Readme.md > 5 13 10:49 handler.rb > 5 13 10:17 vendor
ZIPͰݻΊ·͢ $ zip -r handler.zip handler.rb vendor
ΆͪΆͪ…ʢLambdaʣ
ΆͪΆͪ…ʢAPI Gatewayʣ
ΆͪΆͪ…ʢIAMʣ
Ͱ͖…Δͷ͔…ʂʂ
None
؆୯ʹ͜ͷϨϕϧͷػೳ͕࣮Ͱ͖Δͷ͘͢͝Ͷʁ
εϐʔυ࣮
ɹϚωʔδυαʔϏεΛͲΜͲΜ͍ͬͯͬͯɺ ͍͍ײ͡ͷΞτϓοτΛ͍ͯ͜͠͏
खΛಈ͔ͨ͠ΒɺࠓͦΕΛ ొஃϒϩάͰΈΜͳʹγΣΞ͍ͯ͜͠͏
ݸਓ։ൃϋοΧιϯͰཱͭɺศར API ͷͭ͘Γ͔ͨ ʙ Amazon Rekognition Λ༻ͨ͠ը૾ͷλά͚APIฤ ʙ Thank you
!!
͓·͚ɿίʔυղઆ
Gemfile Λฤूͯ͠ɺbundle install ͠·͢ # frozen_string_literal: true source 'https://rubygems.org' git_source(:github)
{ |repo_name| "https://github.com/#{repo_name}" } gem 'aws-sdk-rekognition' gem 'aws-sdk-translate' Gemfile $ bundle install —path=vendor/bundle
ґଘ gem Λ require ͠·͢ # frozen_string_literal: true require 'net/http'
require 'json' require 'aws-sdk-rekognition' require 'aws-sdk-translate' require 'base64' require 'open-uri' def request_handler(event:, context:) image_uri = event['queryStringParameters']['image-uri'] resp = detect_label(URI.open(image_uri).read) { statusCode: 200, headers: { 'Content-Type': 'application/json' }, body: JSON.generate(resp) } end handler.rb
ґଘ gem Λ require ͠·͢ # frozen_string_literal: true require 'net/http'
require 'json' require 'aws-sdk-rekognition' require 'aws-sdk-translate' require 'base64' require 'open-uri' handler.rb
Rekognition ʹϥϕϧΛ͚ͭͯΒ͏ؔ def detect_label(data) client = Aws::Rekognition::Client.new attrs = {
image: { bytes: data }, max_labels: 10 } response = client.detect_labels(attrs) # Filter labels = response.labels.select { |c| c.confidence >= 66 } # Translate tag, Generate response array labels.map { |l| translate(l[:name].downcase) } end handler.rb
ϥϕϧΛຊޠʹͯ͘͠ΕΔؔ def translate(target) client = Aws::Translate::Client.new resp = client.translate_text( text:
target, source_language_code: 'en', target_language_code: 'ja' ) resp.translated_text end handler.rb
ϦΫΤετͷϋϯυϥʔؔΛ࣮͠·͢ def request_handler(event:, context:) # ΫΤϦύϥϝʔλ͜͏ͬͯऔΔ image_uri = event['queryStringParameters']['image-uri'] resp
= detect_label(URI.open(image_uri).read) { statusCode: 200, headers: { 'Content-Type': 'application/json' }, body: JSON.generate(resp) } end handler.rb
DONE !!! def request_handler(event:, context:) # ΫΤϦύϥϝʔλ͜͏ͬͯऔΔ image_uri = event['queryStringParameters']['image-uri']
resp = detect_label(URI.open(image_uri).read) { statusCode: 200, headers: { 'Content-Type': 'application/json' }, body: JSON.generate(resp) } end handler.rb