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
Lambdaを使ってJawsDaysをHackしてみよう!
Search
toshihirock
March 12, 2016
2
1.8k
Lambdaを使ってJawsDaysをHackしてみよう!
Lambdaを使ってJawsDaysをHackしてみよう!
2016 3/12 13:00-13:50(50min)
toshihirock
March 12, 2016
Tweet
Share
More Decks by toshihirock
See All by toshihirock
保守、運用で使ってみようLambda!
toshihirock
4
1.8k
CodeDeployを使ったアプリケーションデプロイを考える
toshihirock
0
640
Jenkinsおじさんと楽しい連携ツールたち
toshihirock
1
2.3k
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
How to train your dragon (web standard)
notwaldorf
88
5.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Docker and Python
trallard
41
3.1k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Mobile First: as difficult as doing things right
swwweet
222
9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Transcript
LambdaΛͬͯJawsDays ΛHackͯ͠ΈΑ͏! +"84%":4 5PTIJIJSP'VSVOP
ɾWiFi SSID->jawsdays_workshop ɾWiFi ύεϫʔυ->workshop02 ɾࢿྉ-> https://github.com/toshihirock/ jaws2016-lambda-hands-on
લఏ ɾॳ৺ऀ͚ͷߨशͳͷͰқߴ͋͘Γ ·ͤΜɻ͕࣌ؒ༨ͬͨํվ͢ΔͳͲࣗ༝ ʹ༡ΜͰΈ͍ͯͩ͘͞ɻ ɾLambdaͷίʔυ࣮αϯϓϧNode.jsͰ ߦ͓ͬͯΓ·͢ɻJava,PythonͰͷαϯϓϧ ͳ͍ྃ͝ঝ͍ͩ͘͞ɻ
Δ͜ͱɺΒͳ͍͜ͱ Δ͜ͱ ɾϋϯζΦϯܗࣜͰLambdaͰԿ͔Λ࡞ͬͯ ༡ΜͰΈΔ(༡ͼͳͷͰۀ͚Ͱͳ͍) Βͳ͍͜ͱ ɾLambdaͷৄࡉͳઆ໌ ɾTwitterAPIͷৄࡉ
ࣗݾհ ɾݹढ़(@toshihirock) ɾNTTιϑτΣΞגࣜձࣾ ɾAWSۀ1͙Β͍ ɾ͖ - Lambda - Podcast -
ϫʔϧυτϦΨʔ
ຊͷϋϯζΦϯ
-BNCEBΛͬ ͯKBXTEBZTʹπ Πʔτ͠Α͏
LambdaΛͬͯJawsDaysΛHackͬͧ͢ ɾπΠʔτ͍ͤͨ͞༰ͷςΩετΛS3ʹஔ ɾIAMϩʔϧΛ༩ͨ͠LambdaͰS3͔ΒςΩ ετϑΝΠϧΛऔಘ͠ɺϥϯμϜʹϐοΫΞοϓ ɾ༧Ί࡞ͯ͋͠ΔAPIGatewayʹ͚ͯPOST ϦΫΤετΛ࣮ࢪ ɾAPIGatewayܦ༝Ͱ@jaws2016_lambda͔Β ϋογϡλά #jawsdays Λ͚ͯπΠʔτ͞Ε
Δ(࡞ࡁΈ)
֓ཁਤ
ࣝฤ
S3? ɾΦϯϥΠϯετϨʔδ ɾߴ͍ݎ࿚ੑ(99.999999999%) ɾ҆Ձ ɾ༰ྔແ੍ݶ(1ϑΝΠϧ5TB·Ͱ) ࠓճπΠʔτจݴΛஔ͘ॴͱͯ͠ར༻
Lambda? ɾΠϕϯτυϦϒϯ cronͷΑ͏ʹఆظλΠϛϯάͰϢʔβʔ͕ॻ ͍ͨίʔυΛ࣮ߦͰ͖Δ ɾίʔυNode.js,Java,Python ɾ࠷ۙVPCରԠ ɾৄࡉެࣜࢀর
IAMϩʔϧ? ɾϢʔβʔLambdaɺEC2ͳͲͷϦιʔεʹର ׂͯ͠(Role)ΛࢦఆͰ͖Δɻྫ͑ʮS3ͷRead ݖݶʯͳͲ ɾϩʔϧLambda࡞࣌ʹ༩͢Δ͜ͱͰઃఆ ͞ΕͨAPIͷkick͕Ͱ͖Δ ࠓճͷྫͰLambda͔ΒS3ͷόέοτͷใΛ औಘ͍ͨ͠ͷͰLambda͚ͷ্هʹ֘͢Δ IAMϩʔϧΛ࡞͢Δ
࡞ۀͷྲྀΕ ɾS3όέοτʹπΠʔτจݴͷஔ ɾLambda༻IAMϩʔϧͷ࡞ ɾLambda Functionͷ࡞ ɾLambda Functionͷఆظ࣮ߦͷઃఆ
४උฤ(S3)
αʔϏεҰཡ͔ΒS3ͷબ
όέοτͷ࡞ ʮ$SFBUF#VDLFUʯ Λબ όέο τ໊Λ࡞ɻόέοτ ໊SFHJPOͰϢχʔΫͳ ඞཁ͋Γ Ϧʔδϣϯ 5PLZP
ʮ$SFBUFʯ Λબ
S3ஔ͢ΔςΩετϑΝΠϧͷ࡞ ɾ֤ࣗͷPCͷ͖ͳΤσΟλͰπΠʔτͤ͞ ͍ͨจݴूΛ࡞͍ͯͩ͘͠͞ɻจࣈίʔυ UTF-8Ͱอଘ ɾҙͷσϦϛλ۠ΓͰ࡞͍ͯͩ͘͠͞ɻ ҎԼྫσϦϛλվߦ(\r\n) ɾ࡞ޙɺʮtweetList.txtʯͰϩʔΧϧʹอ ଘ
֬ೝ # จࣈίʔυ֬ೝ $nkf -g tweetList.txt # վߦίʔυ֬ೝ.LF = $.CR
= ^MͰදࣔ $cat -e tweetList.txt
S3ςΩετϑΝΠϧͷΞοϓϩʔυ ʮ6QMPBEʯΛ બ ςΩετΛ υϥοάΞϯυυϩο ϓͰΞοϓϩʔυ ʮ4UBSU 6QMPBEʯΛબ ઌ΄Ͳ࡞ͨ͠όέοτΛબޙɺҎԼͷૢ ࡞ͰΞοϓϩʔυ
֬ೝ
४උฤ(IAMϩʔϧ)
αʔϏεҰཡ͔ΒIAMͷબ
ϩʔϧͷ৽ن࡞ ʮ3PMFTʯΛબ ʮ$SFBUF /FX3PMFʯΛબ
ϩʔϧ໊ͷܾఆ ҙͷ 3PMF/BNFΛೖྗ ʮ/FYU 4UFQʯΛબ
ϩʔϧλΠϓͷબ ʮ"84 -BNCEBʯΛબ LambdaʹΞλον͍ͨ͠ϩʔϧΛ࡞͢ΔͷͰLambdaΛ બ͠·͢
ϙϦγʔͷબ ʮTʯͱೖྗ ʮ"NB[PO43F BE0OMZ"DDFTTʯ Λબ ʮ/FYU 4UFQʯΛબ طʹAWSଆͰ༻ҙ͍ͯ͠ΔS3ͷReadOnly ͷϙϦγʔΛ༩
ϨϏϡʔ ֬ೝޙɺ ʮ$SFBUF3PMFʯ Λબ
LambdaΛ࡞Ζ͏!
(ޙͰར༻)ίʔυͷ४උ ɾҎԼͷ༰Λίϐϖͯ͠ҙͷςΩετΤ σΟλʹష͓ͬͯ͘ ɾhttps://github.com/toshihirock/jaws2016- lambda-hands-on/blob/master/index.js
(ޙͰར༻)ίʔυͷ४උ 4ͷઃఆ దٓࣗͷઃఆʹ มߋ "1*(BUFXBZͷ ೝূΩʔΛࢦఆ
αʔϏεҰཡ͔ΒLambdaͷબ
Functionͷ࡞ ※ॳΊͯͷํͷը໘ ʮ$SFBUFB -BNCEBGVODUJPOʯ Λબ ʮ(FU4UBSUFE /PXʯΛબ ※طʹFunction͕͋Δਓͷը໘
Blueprint ར༻͠ͳ͍ ͷͰʮ4LJQʯΛબ
Functionͷઃఆ(1/2) /PEFKT /BNFٴͼ %FTDSJQUJPOԿ Ͱ0, &EJUDPEF JOMJOF ઌ ΄Ͳͷ༰Λ ίϐϖ
Functionͷઃఆ(2/2) ઌ ΄Ͳ࡞ͨ͠4 ΞΫηεͰ͖Δ3PMF ໊ *OEFYIBO EMFS /P71$ ࠷ޙʹ ʮ/FYUʯ
ϨϏϡʔ ઃఆ͕ͳ ͚Εʮ$SFUF GVODUJPOʯ
࡞ ຊޠ͕จࣈԽ͚͠· ͢ɻɻؾʹͳΔਓຊϖʔδ Ͱ࠶ίϐϖͯ͠ߋ৽͢Δͱ Γ·͢ɻ
ςετͯ͠ΈΔ ʮ5FTUʯΛબ
ςετͯ͠ΈΔ ʮ4BWFBOE UFTUʯΛબ ςϯϓϨʔτԿͰ 0, πΠʔτใ4͔ Βऔಘ͢ΔͷͰ
ςετͯ͠ΈΔ ޭ͢Εը໘Լ෦ ʹπΠʔτͨ͠จࣈྻ͕දࣔ ͞ΕΔ ࣦഊ͢Δͱ͍Τϥʔදࣔ ʹͳΔ
ςετͯ͠ΈΔ 5XJUUFSͰ֬ೝ
Τϥʔ͕ൃੜ͍ͯ͠Δ߹ ɾը໘Լ෦(Log output)ʹϩάใ͕දࣔ͞ ΕΔͷͰ֬ೝ ɾඞཁʹԠͯ͡console.logͳͲΛࠐΜͰσ όοάͯ͠ΈΔ
botΒ͘͠ ఆظ࣮ߦͤͯ͞ΈΔ
ఆظ࣮ߦͷઃఆ ʮ&WFOUTPVSDFTʯλ ϒΛબ ʮ"EEFWFOU TPVSDFʯΛબ
ఆظ࣮ߦͷઃఆ ҙͷ࣌ؒؒ ִΛઃఆ ࠷খ ʮ$MPVE8BUDI&WFOUT 4DIFEVMFʯΛબ ໊শΛదٓมߋ 4VCNJUܾͯ͠ఆ
֬ೝ 5XJUUFS্Ͱ֬ೝ ͬͯ֬͠͠ೝ
͕࣌ؒ༨ͬͨਓ
͕࣌ؒ༨ͬͨਓ ɾ͖ʹ৭ʑͬͯΈ͍ͯͩ͘͞ʂʢఆظ࣮ߦ ִؒΛม͑ΔɺจݴͷύλʔϯΛ૿͢ͳͲʣ ɾLambda͔ΒTwitterͷAPIΛୟ͘ͳͲΛ ͯ͠Έ͍ͨ߹Ҏલॻ͍ͨͪ͜ΒΛࢀߟʹͬ ͯΈ͍ͯͩ͘͞ http://qiita.com/toshihirock/items/ d28505442526e0ae7793
Thanks!